与漂亮的Eslint。无法阻止eslint-config-prettier行长错误

时间:2018-04-09 13:49:19

标签: javascript eslint prettier

请参阅底部的修改

我有一个JavaScript文件,我正在使用Eslint。我正在使用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
  }
};

每当我抓住文件时,都会抱怨某些行的长度。

为清晰起见,

修改

我正在使用 eslint v4.19.1 更漂亮的1.10.2 。正在读取和正确使用配置文件。

修改以获取更多信息2018/05/30

我发现了lint错误的区别。 Max-len工作正常,我在规则中作为覆盖提供的值正在得到尊重。

更漂亮的配置有问题的是我的一些条件表达式的长度。我可以看到它想要将它们放在具有额外空白区域的新线上。这是我想要覆盖的配置。 max-len似乎是一个不同的规则。下面的示例是一个长度为60个字符的条件表达式,它触发了一个lint错误。整行只有84个字符(*表示空格)。

**********} else if (firstSessionDate > this.sessionsData[i].SessionStartDateTime) {

1 个答案:

答案 0 :(得分:0)

根据ESLint's docs,您在Uncaught TypeError: Cannot read property 'map' of undefined 中包含的任何内容都优先于从rules继承的规则,这意味着您可以部分或完全更改规则的行为。

这意味着您指定的extends规则会从max-len的{​​{1}}规则中获取。您必须从配置文件中删除此规则,ESLint将停止抱怨。

相关问题