[英]Eslint with Prettier. Unable to prevent eslint-config-prettier line-length errors
See Edits at bottom请参阅底部的编辑
I have a JavaScript file that I am linting with Eslint.我有一个 JavaScript 文件,我正在使用 Eslint 进行 linting。 I am using Prettier to format the code.
我正在使用 Prettier 来格式化代码。
My personal choice on this file is to increase the line-length beyond the 80 chars that Prettier has as a default to 2000 chars.我个人对这个文件的选择是将行长增加到 Prettier 默认的 80 个字符以外的 2000 个字符。
So I have a prettierrc.config.js:所以我有一个 prettierrc.config.js:
module.exports = {
printWidth: 2000
};
Which works when I format the code, and I have a .eslintrc.js当我格式化代码时它会起作用,并且我有一个 .eslintrc.js
module.exports = {
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"es6": true,
"browser": true
},
"extends": [
"eslint-config-airbnb-base",
"eslint-config-prettier"
],
"plugins": [
"eslint-plugin-import",
"eslint-plugin-prettier"
],
"rules": {
"prettier/prettier": ["error", {}],
"max-len": ["error", {"code": 2000, "ignoreUrls": true}],
"linebreak-style": 0,
"no-use-before-define": ["error", { "functions": false, "classes": false }],
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-underscore-dangle": 0,
"import/no-amd": 0,
"import/no-dynamic-require": 0,
},
"globals": {
"define": true
}
};
Everytime I lint the file, it complains about the length of certain lines.每次我 lint 文件时,它都会抱怨某些行的长度。
Edit for clarity:为清楚起见进行编辑:
I am using eslint v4.19.1 and prettier 1.10.2 .我正在使用eslint v4.19.1和更漂亮的 1.10.2 。 Config files are being read and used correctly.
配置文件被正确读取和使用。
Edit for additional information 2018/05/30编辑以获取更多信息 2018/05/30
I have discovered the distinction in the lint errors.我发现了 lint 错误的区别。 Max-len is working correctly, and the value I have provided as an override in rules is being respected.
Max-len 工作正常,并且我在规则中提供的替代值得到尊重。
What the prettier config has a problem with is the length of some of my conditional expressions.更漂亮的配置有一个问题是我的一些条件表达式的长度。 I can see it is wanting to put them on new lines with additional white space.
我可以看到它希望将它们放在带有额外空白的新行上。 This is now the config I am looking to override.
现在这是我要覆盖的配置。 it seems to be a different rule to max-len.
这似乎是与 max-len 不同的规则。 The example below is a conditional expression with a length of 60 characters and it is triggering a lint error.
下面的示例是一个长度为 60 个字符的条件表达式,它触发了 lint 错误。 The whole line is only 84 characters long (* to represent spaces).
整行只有 84 个字符长(* 表示空格)。
**********} else if (firstSessionDate > this.sessionsData[i].SessionStartDateTime) {
Based on ESLint's docs , anything you include in rules
take precedence over the rules inherited from extends
, meaning you can change the rule's behavior partially or completely.根据ESLint 的文档,您在
rules
中包含的任何内容都优先于从继承自extends
的规则,这意味着您可以部分或完全更改规则的行为。
That means the max-len
rule you specified is picked up over the max-len
rule from eslint-config-prettier
.这意味着您指定的
max-len
max-len
规则是从eslint-config-prettier
中选择的 max-len 规则。 You have to delete this rule from your config file and ESLint will stop complaining.你必须从你的配置文件中删除这条规则,ESLint 就会停止抱怨。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.