eslint


Posted by tzutzu858 on 2020-07-07

eslint 是 es lint
es 是 ECMAScript

ECMAScript 是一種由 Ecma 國際(前身為歐洲電腦製造商協會)在標準 ECMA-262 中定義的手稿語言規範。這種語言在全球資訊網上應用廣泛,它往往被稱為 JavaScript 或J Script ,但實際上後兩者是 ECMA-262 標準的實現和擴充。維基百科

  • 到專案去 npm install

看到裡面有 hooks
hooks : 你要的東西掛在上面,在 commit 之前執行你掛的東西

  • 修正錯誤

    第一個是行號,第二個是哪個字

  • 取消規則
    /* eslint-disable <放規則> */

  • package.json可以看出檢查範圍是什麼

    "scripts": {
      "lint": "eslint ./homeworks/**/*.js",
      "test": "echo \"Error: no test specified\" && exit 1"
    }
    

    例如:檢查 homeworks 底下所有的檔案,所有.js檔案



錯誤資訊翻譯筆記區

一個趁機好好進修英文的時刻

  • Assignment can be replaced with operator assignment
    可以用操作員分配代替分配

The following patterns are considered problems and should be replaced by their shorthand equivalents:

/*eslint operator-assignment: [2, "always"]*/

x = x + y;        /*error Assignment can be replaced with operator assignment.*/
x = y * x;        /*error Assignment can be replaced with operator assignment.*/
x[0] = x[0] / y;  /*error Assignment can be replaced with operator assignment.*/
x.y = x.y << z;   /*error Assignment can be replaced with operator assignment.*/
  • Assignment to function parameter 'num' no-param-reassign
    分配給功能參數“ num”

  • Expected linebreaks to be 'LF' but found 'CRLF'
    預期換行符為“ LF”,但發現為“ CRLF”
    改善 : VSCode 單擊窗口右下角的選項,並將其從 CRLF 設置為 LF

  • 'Math.pow' is restricted from being used. Use the exponentiation operator (**) instead
    Disallow the use of Math.pow in favor of the ** operator
    Math.pow換成**

  • Newline required at end of file but not found
    文件末尾需要換行符,但找不到。
    改善 : 就是多加一行

  • Trailing spaces not allowed
    不允許尾隨空格。 os:打的時候就手滑按幾個空白鍵也不行

  • Missing semicolon
    缺少分號

  • Missing space before opening brace space-before-blocks
    打開括號之前的空間不足
    改善 : { 前要加個空格

  • Unary operator '++' used
    一元運算符'++'使用

  • 'i' is not defined
    改善 : 迴圈裡面宣告 for (let i=1 ; i<=n ; i=i+1)
    終於知道為何有時裡面要宣告有時不用。
    i 變量也是函數範圍的,而不僅限於for循環。

  • Unexpected whitespace before semicolon
    分號前出現意外空格 os:分號後要加空格,分號前不給加空格="=

  • Unary operator '++' used
    一元運算符'++'使用
    改善 : i += 1
    eslint no-plusplus的規則

  • Unexpected var, use let or const instead
    意外的var,請改用 let 或 const

  • Missing trailing comma
    缺少尾隨逗號

  • 'lines' is already declared in the upper scope
    “行”已在上限範圍內聲明
    改善 : 改變數名稱

  • Block must not be padded by blank lines
    Block 不能用空行填充


#javascript







Related Posts

怎麼檢查 object 是不是空的?

怎麼檢查 object 是不是空的?

JS30 Day 25 筆記

JS30 Day 25 筆記

Why and How I start learning programming language?

Why and How I start learning programming language?


Comments