ESLint错误:行号超出范围

时间:2017-04-03 18:52:18

标签: javascript eslint

我正在使用标准配置的ESLint。

运行eslint --fix */**时出现此错误:

Line number out of range (line 318 requested, but only 317 lines present).
RangeError: Line number out of range (line 318 requested, but only 317 lines present).
    at SourceCode.getIndexFromLoc (/usr/local/lib/node_modules/eslint/lib/util/source-code.js:389:19)
    at Object.fix (/usr/local/lib/node_modules/eslint/lib/rules/no-multiple-empty-lines.js:116:52)
    at RuleContext.report (/usr/local/lib/node_modules/eslint/lib/rule-context.js:127:34)
    at Program:exit.allLines.reduce.concat.reduce (/usr/local/lib/node_modules/eslint/lib/rules/no-multiple-empty-lines.js:108:37)
    at Array.reduce (native)
    at EventEmitter.Program:exit (/usr/local/lib/node_modules/eslint/lib/rules/no-multiple-empty-lines.js:93:22)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:191:7)
    at NodeEventGenerator.applySelector (/usr/local/lib/node_modules/eslint/lib/util/node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (/usr/local/lib/node_modules/eslint/lib/util/node-event-generator.js:294:22)

任何想法如何解决这个问题?

我首先从标准CLI尝试standard --fix并得到了相同的错误,然后直接从ESLint尝试确认它是后者抛出的错误,而不是前者。

1 个答案:

答案 0 :(得分:3)

想出来:https://github.com/eslint/eslint/issues/8401

  

如果文件以带有空格字符的新行结束,则似乎始终抛出此错误。当我删除空格时,错误就会消失。