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,
};
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,
};
Share
Improve this question
edited Aug 24, 2020 at 16:58
David Bradshaw
13.1k3 gold badges44 silver badges75 bronze badges
asked Aug 14, 2020 at 20:53
Kirk RossKirk Ross
7,15315 gold badges67 silver badges123 bronze badges
4
- What do you mean "not require"? It's not like it makes you write all lines to exactly 160 characters. – jonrsharpe Commented Aug 14, 2020 at 20:56
- @jonrsharpe - I have my IDE set to autofix on save and if an elements with five or six attributes CAN fit within my max len, it auto corrects it and "forces" it. I don't want to turn off autofix-on-save, and even if I do, I get little underlines wherever there's an "unnecessary" line break (which I in fact want). – Kirk Ross Commented Aug 14, 2020 at 21:16
- 1 Then you likely don't want prettier's printWidth: prettier.io/docs/en/options.html#print-width. Or maybe prettier, if you have a layout you "want". – jonrsharpe Commented Aug 14, 2020 at 21:18
- Prettier kind of sucks in this way. It does indeed "make you write lines to [not exactly but near] 160 characters". Ideally, it would apply printWidth to only lines that were too long, but not make lines longer that are too short. – Matthew Dean Commented May 25, 2022 at 16:23
1 Answer
Reset to default 12Set 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.