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

Request: Override rules in file #1154

Closed
blainekasten opened this issue Apr 7, 2017 · 8 comments
Closed

Request: Override rules in file #1154

blainekasten opened this issue Apr 7, 2017 · 8 comments
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:needs discussion Issues needing discussion and a decision to be made before action can be taken

Comments

@blainekasten
Copy link
Contributor

There is a strong argument against this. And honestly I don't really want this. But there is a bit of an interop issue with certain rules in different environments.

Issue

Rule: trailingComma: 'all'

This rule works great when your code is fed through Babel, but fails when executed directly. example:

const add = (...args) => args.reduce((a, b) => a + b, 0);
add(
  1,
  2,
  3,
)

Environments

This specifically happens to me because I write es6 code for the client, which is transpiled through Babel.

And then I write es6-ish code for node, which is not transpiled.

So therefore, when my editor automatically prettifies the node code, it breaks.

Solutions?

Easiest solution seems to be to have an eslint style comment in a file over-riding rules. Example:

// prettier-rule trailingComma=es5

I'm curious your thoughts on this, or if you have a better idea of how I can use prettier in different environments like this.

@vjeux vjeux added the status:needs discussion Issues needing discussion and a decision to be made before action can be taken label Apr 7, 2017
@vjeux
Copy link
Contributor

vjeux commented Apr 7, 2017

We're having the same problem at fb.

@mbrookes
Copy link

mbrookes commented Apr 7, 2017

Dupe of #98? But glad this is getting some fresh exposure.

@mbrookes
Copy link

mbrookes commented Apr 7, 2017

Further discussion: #62

@lydell
Copy link
Member

lydell commented Apr 8, 2017

I recently bumped into this too. I solved it by running prettier through ESLint using eslint-plugin-prettier.

.eslintrc.js:

module.exports = {
  // ...
  rules: {
    // ...
    "prettier/prettier": ["error", { trailingComma: "es5" }],
  },
};

frontend/.eslintrc.js:

const parentConfig = require("../.eslintrc");
const parentPrettierOptions = parentConfig.rules["prettier/prettier"][1];

module.exports = {
  // ...
  rules: {
    // ...
    "prettier/prettier": [
      "error",
      Object.assign({}, parentPrettierOptions, { trailingComma: "all" })
    ],
  },
};

So in case you need something now the above is a potential solution :)

@vjeux
Copy link
Contributor

vjeux commented May 21, 2017

node 8 is going to be released in 1.5 week and supports trailing commas for function calls. I think that we should get people to upgrade when it's ready rather than add complexity inside of prettier.

@vjeux vjeux closed this as completed May 21, 2017
@mbrookes
Copy link

@vjeux Not sure why this was closed. @blainekasten posted a specific example of why overrides are needed. Just because that particular issue is fixed doesn't remove the need for overrides in some form (beyond the paltry set of command line options that currently exist).

@vjeux
Copy link
Contributor

vjeux commented May 22, 2017

If you have another use case for overrides, please create a different issue, and we can try to figure out a solution. I'm interested in solving the problems people have, not implementing whatever solution they think would solve their problem :)

@mbrookes
Copy link

NVM, looks like, there are multiple ops open (and closed) proposing something similar, making a strong case, and giving other use cases, so this one can stay closed.

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 7, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Projects
None yet
Development

No branches or pull requests

4 participants