我有以下测试代码
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
}
是否有一个神奇的设置,我错过了这个传递?
答案 0 :(得分:2)
您使用的是Object Rest/Spread Properties,它不在ES6中,甚至不是标准版。目前处于第3阶段。
JSHint does not support Object Rest/Spread Properties,但是。您可以将JSHint替换为具有experimental support using experimentalObjectRestSpread
。
或者,当然,你可以忽略这些线,正如sabareesh所暗示的那样。但就个人而言,我会建议反对。它会污染代码库并禁用后续linting。我建议使用ESLint,因为它通常更好地支持更新的功能,而且似乎更受欢迎。
答案 1 :(得分:0)
var state = {
// jshint ignore:start
...sth,
// jshint ignore:end
}
尝试这些。