webpack4_Eslint Unary operator '++' used no-plusplus


錯誤詳情

Unary operator '++' used no-plusplus

  • 當使用++的時候Eslint報錯

報錯原因

Eslint禁止使用++與--,因為一元運算符會自動插入分號,如果一元運算符前有空格,可能會引發歧義。(但經測試同樣情況下沒有造成歧義)
(詳見disallow the unary operators ++ and -- (no-plusplus))。

兩種解決方法

以復合賦值運算符代替一元運算符

使用+=-=代替++ --,例如foo++;應該寫成foo+=1;

配置allowForLoopAfterthoughts

在目錄中創建文件.eslintrc,進行如下配置

{
    "parser": "babel-eslint",
    "rules": {
        "no-plusplus": ["off", {
            "allowForLoopAfterthoughts": true
        }]
    }
}

注意需要提前安裝babel-eslint依賴

參考

disallow the unary operators ++ and -- (no-plusplus)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM