使用`rollup-plugin-eslint`获取错误的行号并报告不对更改作出反应

时间:2016-09-04 14:31:17

标签: eslint rollup

我一直在eslint输出上得到错误的行号:

$ ./node_modules/.bin/rollup -c

/Users/asko/Git/es6-trial/src/main.js
   31:7  error  Expected indentation of 4 space characters but found 6  indent
   60:7  error  Expected indentation of 4 space characters but found 6  indent
   61:7  error  Expected indentation of 4 space characters but found 6  indent
  134:7  error  Expected indentation of 4 space characters but found 6  indent
  142:9  error  Expected indentation of 6 space characters but found 8  indent

✖ 5 problems (5 errors, 0 warnings)

报告的数字比实际问题的数字大一些。

但如果我编辑文件,eslint输出不会改变!它正在进行某种类型的缓存吗?

不幸的是,这个来源的回购不是公开的。

.eslintrs.json是:

{
  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "impliedStrict": true
    }
  },
  "env": {
    "browser": true,
    "es6": true
  },
  "globals": {
    "assert": false
  },
  "extends": "eslint:recommended",
  "parserOptions": {
    "sourceType": "module"
  },
  "rules": {
    "indent": ["error", 2],
    "linebreak-style": ["error", "unix"],
    // "quotes": ["warn", "single"],
    "semi": ["error", "always"],
    "no-console": "off",
    "no-unused-vars": "warn"
  }
}

所有这一切都很奇怪。有没有人见过这个?

它与通过Rollup运行eslint有关。如果我直接使用./node_modules/.bin/eslint src/*.js运行,则无需报告。

1 个答案:

答案 0 :(得分:0)

确保在 babel 插件之前配置 eslint 插件,否则linting将在转换后的代码上运行,例如:

plugins: [ eslint({ exclude: 'node_modules/**' }), babel({ exclude: 'node_modules/**' }) ]

而不是

plugins: [ babel({ exclude: 'node_modules/**' }), eslint({ exclude: 'node_modules/**' }) ]

请参阅https://github.com/TrySound/rollup-plugin-eslint/issues/10