Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ESLint / Prettier -- enforce max-len / printWidth, but don't require it?

Is there a way to configure ESLint w/ Prettier to enforce the max-len / printWidth rule but not require it? That is to say, allow you to add line breaks as you see fit?

// eslintrc.js

"max-len": [0, 160, 2, { ignoreUrls: true }],

// prettier.config.js

module.exports = {
  trailingComma: "all",
  tabWidth: 2,
  semi: true,
  singleQuote: false,
  printWidth: 160,
};
like image 439
Kirk Ross Avatar asked Aug 14 '20 20:08

Kirk Ross


People also ask

Does ESLint support printwidth?

It just does not seem to recognize any sort of printWidth at all (i.e. max-len rule ). My ESLint config extends airbnb, so it should infer 100.

How to turn off ESLint Max-Len rule?

Set print-width to 999 in prettier to turn it off, then set the eslint max-len rule to be a warning at what ever your preferred value is.

Can I use ESLint and prettier in my project?

You are ready to use Prettier and ESLint in your project without worrying about any conflicts. ESLint knows about all your Prettier rules by integrating all the rules that are enforced by it and removing all the rules that could conflict with it. Now there shouldn't be anything in your way for an improved code style and structure.

Why doesn’t printwidth work with prettier’s printwidth option?

However, when humans write code, they don’t strive to reach the maximum number of columns on every line. Developers often use whitespace to break up long lines for readability. In practice, the average line length often ends up well below the maximum. Prettier’s printWidth option does not work the same way.


1 Answers

Set print-width to 999 in prettier to turn it off, then set the eslint max-len rule to be a warning at what ever your preferred value is.

like image 76
David Bradshaw Avatar answered Sep 30 '22 04:09

David Bradshaw