jslint --edition=latest 意外的 ES6 特性。常数

jslint --edition=latest Unexpected ES6 feature. const

我正在尝试使用 node-jslint https://github.com/reid/node-jslint 以保持我的代码整洁

我的 nodejs 脚本中有一个 const,但 jslint 说它不是有效的 ES6 代码

 Unexpected ES6 feature.
const pdPersonsFilterId = process.argv[2]; // Line 10, Pos 0

这是我在控制台中使用的命令

jslint --edition=latest index.js

根据 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const 可以使用全局常量。

为什么 jslint 不认为此代码有效?

2020 年编辑: 作为 , and as predicted in the answer, JSLint has dropped the es6 requirement -- it looks like on 9 Oct 2017

也就是说,es6 不再是 一个有效的 JSLint 选项。 今天的 OP 代码会像这里写的那样 lint :

/*jslint browser */
/*global process */
const pdPersonsFilterId = process.argv[2];

但是,如果您认为自己处在 OP 的情况下,确保您用来检查文件的任何进程都没有使用旧版本的 JSLint。一些工具附带了过时的版本,或者您的构建脚本可能维护了一个旧版本以免破坏遗留代码。如果您遇到这种情况,下面的修复应该有效。

但是,如果您知道自己的 JSLint 版本比 2017 年 10 月 9 日更新,并且出现了 es6 错误,请打开一个新的 Whosebug 问题!


对于最初的 question/older 版本的 JSLint...

JSLint 对 ES6 很满意;你只需要让它知道你正在使用 ES6。将 es6 指令添加到您的 JSLint 配置或文件顶部,然后获利。

/*jslint es6 */
const pdPersonsFilterId = process.argv[2];

现在您看到的警告消失了。

来自JSLint's help

It may take time for the sixth edition of ECMAScript [ES6] to reach ubiquity. Using the new features in enviroments that do not fully implement the new standard will result in failure. This is why JSLint gives warnings when ES6 features are used. Some of ES6's features are good, so JSLint will recognize the good parts of ES6 with the es6 option. As implementations of the new standard become more stable and better understood, the set of features recognized by JSLint may increase. After the transition to ES6 is complete, the es6 option will be dropped. [emph mine]

似乎很公平。所以你看到的只是警告你,你所得到的可能无法在不支持 ES6 的地方工作,因为现在有很多地方。一旦 ES6 更加广泛——或者如果你明确地让 Crockford 知道你打算使用 ES6——警告将 go/goes 消失。 (TJ 的观点可能是,至少对于 Node,现在是删除警告的时候了。;^D)

尝试 ESLint

它在 NPM 上有更好的统计数据,文档非常棒并且被广泛使用。