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

Custom Prettier rules are not working. #4

Closed
felipeS opened this issue Feb 27, 2019 · 12 comments
Closed

Custom Prettier rules are not working. #4

felipeS opened this issue Feb 27, 2019 · 12 comments

Comments

@felipeS
Copy link

felipeS commented Feb 27, 2019

Apparently, it's only taking into account the Prettier default rules. I have the following rule in my settings.json:
{
"prettier.printWidth": 132,
}

But it's always cutting my lines at 80.

@wesbos
Copy link
Owner

wesbos commented Feb 27, 2019

Hmm - let me take a look into this. You are sure you don't have a prettier config file in your folder?

@felipeS
Copy link
Author

felipeS commented Feb 27, 2019

I'm testing in a single file in a folder, there's no .eslintrc or .prettierrc file

@wesbos
Copy link
Owner

wesbos commented Feb 27, 2019

and was this with a global or local install?

@felipeS
Copy link
Author

felipeS commented Feb 27, 2019

Global install

@NickyMeuleman
Copy link
Contributor

NickyMeuleman commented Feb 27, 2019

Sorry to interject.

This might be what is causing the unwanted behaviour:
https://github.com/prettier/eslint-plugin-prettier#options

But it's always cutting my lines at 80.

This line could be taking precedence over the rule you set in settings.json https://github.com/wesbos/eslint-config-wesbos/blob/master/.eslintrc.js#L120

from that first link:

NB: This option will merge and override any config set with .prettierrc files

(I'm making the leap here that a setting in the settings.json file acts like a global .prettierrc file)

edit: the rule in settings.json is probably not active since prettier is being ran through an ESLint-plugin and not the VSCode extension. I wonder if it is aware of settings given to the editor extension 🤔

@wesbos
Copy link
Owner

wesbos commented Feb 27, 2019

hmm I don't recall this being an issue for me and I've always used it this way. Will investigate :)

@wesbos
Copy link
Owner

wesbos commented Feb 27, 2019

Oh - just reading this again and I see the issue.

I don't use the prettier vs code extension, and if you followed my steps, you will see that we turned it off.

So, if you want to overwrite any settings that I have, you need to do so in your .eslintrc, and not in your VS Code settings file.

It would then look like this:

{
  "extends": [
    "wesbos"
  ],
  
  "rules": {
    "prettier/prettier": [
      "error",
      {
        "printWidth": 135,
      }
    ]
  }
}

@wesbos
Copy link
Owner

wesbos commented Feb 27, 2019

Going to leave this open so I can document how to add custom eslint and prettier settings to overwrite any that my config sets

@felipeS
Copy link
Author

felipeS commented Feb 27, 2019

I followed the steps and disabled the vs code extension, but I wasn't aware that I have to add the prettier rules to the .eslintrc file, didn't even know it was possible 😅It's working now, though.
Thanks!

@wesbos
Copy link
Owner

wesbos commented Feb 27, 2019

well im glad you logged this issue because that is exactly what I wanted to find out - little sticking points like this is what cause people to abandon tools like this. Glad we could get it figured out!

@JohnMilazzo
Copy link

Same here. Through some trial and error I realized I could remove the settings from both VS Code and my project's .prettierrc file. Having everything in one place (.eslintrc) is prettier nice! ;)

@wesbos
Copy link
Owner

wesbos commented Mar 12, 2019

Okay ive documented this in the readme now. Opted against using a .prettierrc

@wesbos wesbos closed this as completed Mar 12, 2019
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

4 participants