【发布时间】:2018-09-18 22:46:47
【问题描述】:
查看底部的修改
我有一个 JavaScript 文件,我正在使用 Eslint 进行 linting。我正在使用 Prettier 来格式化代码。
我个人对此文件的选择是将行长增加到 Prettier 默认的 80 个字符之外,增加到 2000 个字符。
所以我有一个 prettierrc.config.js:
module.exports = {
printWidth: 2000
};
当我格式化代码并且我有一个 .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
}
};
每次我对文件进行 lint,它都会抱怨某些行的长度。
编辑为清楚起见:
我正在使用 eslint v4.19.1 和 prettier 1.10.2。正在正确读取和使用配置文件。
编辑获取更多信息 2018/05/30
我发现了 lint 错误的区别。 Max-len 工作正常,并且我在规则中作为替代提供的值得到尊重。
更漂亮的配置有一个问题是我的一些条件表达式的长度。我可以看到它希望将它们放在带有额外空白的新行上。现在这是我要覆盖的配置。这似乎是与 max-len 不同的规则。下面的示例是一个长度为 60 个字符的条件表达式,它触发了 lint 错误。整行只有 84 个字符长(* 表示空格)。
**********} else if (firstSessionDate > this.sessionsData[i].SessionStartDateTime) {
【问题讨论】:
标签: javascript eslint prettier