[英]Force ESLint to use ES6
我的ESLint都設置和工作,但我希望它在我不使用像let
, const
或箭頭函數( =>
)這樣的ES6時拋出錯誤。
{
"env": {
"node": true,
"es6": true,
"mocha": true
},
"rules": {
"semi": 2
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "script",
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true
}
}
}
目前,這不會拋出錯誤:
var stars = [];
var speed = 20;
function setup() {
createCanvas(windowWidth, windowHeight);
// Create 1000 stars
for (var i = 0; i < 1000; i++) {
stars.push(new Star());
}
}
您可以使用prefer-arrow-callback
規則強制使用箭頭函數作為回調。
此外, prefer-const
規則強制盡可能使用const
(即,如果永遠不重新賦值變量)。
你不要在for循環中使用i
,所以這不是錯誤。
您可以使用no-var
規則但它會影響所有內容,而不僅僅是循環。
如果您在for循環中使用了i
,那么no-loop-func
規則就是您要尋找的。
如果您更喜歡箭頭函數作為回調,則可以使用prefer-arrow-callback
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.