Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prettier conflicts with no-unexpected-multiline #32

Closed
sudo-suhas opened this issue Oct 29, 2017 · 12 comments
Closed

prettier conflicts with no-unexpected-multiline #32

sudo-suhas opened this issue Oct 29, 2017 · 12 comments

Comments

@sudo-suhas
Copy link
Contributor

This scenario is relevant when a shareable config like airbnb-base is combined with prettier. If the rule no-unexpected-multiline is enabled, it ends up resulting in a error which can only be resolved by switching off the rule.

.eslintrc.yml

extends: prettier
plugins:
  - prettier
parserOptions:
  ecmaVersion: 8
  sourceType: script
rules:
  no-undef: off
  no-unused-vars: off
  no-unexpected-multiline: error
  prettier/prettier:
    - error
    -
      trailingComma: none
      singleQuote: true
      printWidth: 80
      tabWidth: 4

code snippet

const value =
    Array.isArray(param) && spread
        ? getInstance()
              [methodName](...param)
              .toJSON()
        : getInstance()
              [methodName](param)
              .toJSON();

Eslint output:

  4:15  error  Unexpected newline between object and [ of property access  no-unexpected-multiline
  7:15  error  Unexpected newline between object and [ of property access  no-unexpected-multiline

If I fix the errors:

  3:24  error  Insert `⏎··············`  prettier/prettier
  5:24  error  Insert `⏎··············`  prettier/prettier
@lydell
Copy link
Member

lydell commented Oct 30, 2017

Thanks for the clear issue!

See previous discussion here: #8 (and #25)

One way is to simply turn the rule off always. But is there any case we lose where this rule would have caught an error?

@sudo-suhas
Copy link
Contributor Author

I did see the previous discussion. W.r.t this particular rule, the plan was to revisit it in the future if the need were to arise. Indeed, turning off the rule works but I am proposing that eslint-config-prettier should do it and I'd be happy to make a PR for it if required. And no, the rule doesn't catch a syntax error at least in this case.

@lydell
Copy link
Member

lydell commented Oct 30, 2017

Sorry, I meant "one way is to include this rule in this config to be always turned off". I'm just worried that turning this rule off means people will miss out on ESLint helping them find semicolon mistakes. Perhaps this should be one of the "special rules". I use this rule myself, and have never encountered conflicts with Prettier so far, but it does depend on how you write your code.

My point is that this issue needs a little experimentation and thinking about.

@lydell
Copy link
Member

lydell commented Oct 31, 2017

I've now come to the conclusion that we should add the rule as a special rule.

@sudo-suhas
Copy link
Contributor Author

sudo-suhas commented Nov 1, 2017

Ok @lydell, I'd like to work on this. But I might need some help with updating the readme though.

@lydell
Copy link
Member

lydell commented Nov 1, 2017

You can make a PR if you want and I can help getting it across the finish line.

@lydell
Copy link
Member

lydell commented Nov 1, 2017

Released in 2.7.0.

@andreyvolokitin
Copy link

I am not sure if I run ESLint before Prettier with this config (Prettier as ESLint plugin) and thus can turn "no-unexpected-multiline": "error" on?:

{
  "extends": [
    "airbnb-base",
    "prettier"
  ],
  "rules": {
    "prettier/prettier": "error",
    "no-unexpected-multiline": "error"
  },
  "plugins": [
    "prettier"
  ]
}

@lydell
Copy link
Member

lydell commented Dec 1, 2017

@andreyvolokitin With that config Prettier essentially runs at the same time as ESLint, unless you use the --fix flag which basically causes Prettier to run first.

@yaminyaylo
Copy link

yaminyaylo commented Jan 21, 2019

As a solution you can use "prettier.printWidth": 100)(or more setting to extend line

@mbrookes
Copy link

I have this error, however after disabling no-unexpected-multiline, the next prettier run reformats the code such that the error comes back:

         };
       };
     })
-    // eslint-disable-next-line no-unexpected-multiline
-    ["catch"](function(error) {
+    [
+      // eslint-disable-next-line no-unexpected-multiline
+      "catch"
+    ](function(error) {
       console.error("Error during service worker registration:", error);
     });
 }

@lydell
Copy link
Member

lydell commented Sep 17, 2019

@mbrookes Ah, that’s unfortunate that Prettier moves the comment in that scenario. There are a couple of ways to go:

  • Use /* eslint-disable no-unexpected-multiline */ and /* eslint-enable no-unexpected-multiline */ around the whole thing.

  • Use .catch instead of ["catch"].

  • Use .then(null, fn) instead of .catch(fn).

  • Use a temporary variable and put the ["catch"] on that.

benelan added a commit to Esri/calcite-design-system that referenced this issue Jan 13, 2025
## Summary

- Create a new package in `packages/eslint-config-calcite` that contains
shared ESLint configurations for importing in other packages.
- Setup the components and design-tokens packages to use the new shared
ESLint configs.
- Add typescript-eslint coverage to our github scripts 
- Check css files in lint-staged (previously it was only scss)
- Disable
[`no-unexpected-newline`](https://archive.eslint.org/docs/6.0.0/rules/no-unexpected-multiline),
which [conflicts with
prettier](prettier/eslint-config-prettier#32)
- Various other cleanup, such as formatting json files in `.vscode/` and
removing cspell ignore comments in favor of dictionary additions..
- Run `npm run lint` so unrelated changes don't appear in subsequent PRs
benelan added a commit to Esri/calcite-design-system that referenced this issue Feb 8, 2025
## Summary

- Create a new package in `packages/eslint-config-calcite` that contains
shared ESLint configurations for importing in other packages.
- Setup the components and design-tokens packages to use the new shared
ESLint configs.
- Add typescript-eslint coverage to our github scripts 
- Check css files in lint-staged (previously it was only scss)
- Disable
[`no-unexpected-newline`](https://archive.eslint.org/docs/6.0.0/rules/no-unexpected-multiline),
which [conflicts with
prettier](prettier/eslint-config-prettier#32)
- Various other cleanup, such as formatting json files in `.vscode/` and
removing cspell ignore comments in favor of dictionary additions..
- Run `npm run lint` so unrelated changes don't appear in subsequent PRs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants