我有以下测试代码
const sth = {
one: 'one',
two: 'two',
three: {
foo: 'foo',
bar: 'bar',
}
};
const state = {
...sth
};
当我运行 jshint 时,我得到以下输出
jshint --config .jshintrc test.js
test.js: line 12, col 3, Expected '}' to match '{' from line 11 and instead saw '...'.
test.js: line 12, col 6, Missing semicolon.
test.js: line 12, col 9, Missing semicolon.
test.js: line 12, col 6, Unrecoverable syntax error. (92% scanned).
4 errors
但这是完全有效的 es6 代码。
我的 .jshintrc 如下所示:
{
"curly": false,
"expr": true,
"maxlen": 200,
"esversion": 6
}
是否有我缺少的魔法设置才能通过?
最佳答案
您正在使用 Object Rest/Spread Properties这不在 ES6 中,甚至还不是标准。目前处于第 3 阶段。
JSHint does not support Object Rest/Spread Properties , 然而。您可以将 JSHint 替换为具有 experimental support using experimentalObjectRestSpread
的 ESLint .
或者,当然,您可以按照 sabareesh 的建议忽略这些行。但是,就我个人而言,我建议不要这样做。它会污染代码库,还会禁用后续的 linting。我建议改用 ESLint,因为它通常对新功能有更好的支持,而且似乎更受欢迎。
关于ecmascript-6 - JsHint 显示 es6 对象解构赋值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47177483/