// .eslintrc.json { "env": { "browser": true, "node": true, "commonjs": true }, "plugins": [ "react" ], //"parser": "babel-eslint", // 必須指定解析器,不然錯誤難消 // 0 或 'off':關閉規則。 // 1 或 'warn':打開規則,而且做爲一個警告(並不會致使檢查不經過)。 // 2 或 'error':打開規則,而且做爲一個錯誤 (退出碼爲1,檢查不經過)。 "rules": { // 定義對象的set存取器屬性時,強制定義get "accessor-pairs": 2, // 禁止或強制在括號內使用空格 // 指定數組的元素之間要以空格隔開(,後面), never參數:[ 以前和 ] 以後不能帶空格,always參數:[ 以前和 ] 以後必須帶空格 "array-bracket-spacing": [2, "never"], // 在塊級做用域外訪問塊內定義的變量是否報錯提示 "block-scoped-var": 0, // if while function 後面的{必須與if在同一行,java風格。 "brace-style": [2, "1tbs", { "allowSingleLine": true }], // 雙峯駝命名格式 "camelcase": 2, // 數組和對象鍵值對最後一個逗號, never參數:不能帶末尾的逗號, always參數:必須帶末尾的逗號, // always-multiline:多行模式必須帶逗號,單行模式不能帶逗號 "comma-dangle": [2, "never"], // 控制逗號先後的空格 "comma-spacing": [2, { "before": false, "after": true }], // 控制逗號在行尾出現仍是在行首出現 // http://eslint.org/docs/rules/comma-style "comma-style": [2, "last"], // 圈複雜度 "complexity": [2,12], // 以方括號取對象屬性時,[ 後面和 ] 前面是否須要空格, 可選參數 never, always "computed-property-spacing": [2,"never"], // 強制方法必須返回值,TypeScript強類型,不配置 "consistent-return": 0, // 用於指統一在回調函數中指向this的變量名,箭頭函數中的this已經能夠指向外層調用者,應該沒卵用了 // e.g [0,"that"] 指定只能 var that = this. that不能指向其餘任何值,this也不能賦值給that之外的其餘值 "consistent-this": 0, // 強制在子類構造函數中用super()調用父類構造函數,TypeScrip的編譯器也會提示 "constructor-super": 0, // if else while for do後面的代碼塊是否須要{ }包圍,參數: // multi 只有塊中有多行語句時才須要{ }包圍 // multi-line 只有塊中有多行語句時才須要{ }包圍, 可是塊中的執行語句只有一行時, // 塊中的語句只能跟和if語句在同一行。if (foo) foo++; else doSomething(); // multi-or-nest 只有塊中有多行語句時才須要{ }包圍, 若是塊中的執行語句只有一行,執行語句能夠零另起一行也能夠跟在if語句後面 // [2, "multi", "consistent"] 保持先後語句的{ }一致 // default: [2, "all"] 全都須要{ }包圍 "curly": [2, "all"], // switch語句強制default分支,也可添加 // no default 註釋取消這次警告 "default-case": 2, // 強制object.key 中 . 的位置,參數: // property,'.'號應與屬性在同一行 // object, '.' 號應與對象名在同一行 "dot-location": [2, "property"], // 強制使用.號取屬性 // 參數: allowKeywords:true 使用保留字作屬性名時,只能使用.方式取屬性 // false 使用保留字作屬性名時, 只能使用[]方式取屬性 e.g [2, {"allowKeywords": false}] // allowPattern: 當屬性名匹配提供的正則表達式時,容許使用[]方式取值,不然只能用.號取值 e.g [2, {"allowPattern": "^[a-z]+(_[a-z]+)+$"}] "dot-notation": [2, {"allowKeywords": true}], // 文件末尾強制換行 "eol-last": 2, // 使用 === 替代 == "eqeqeq": [2, "allow-null"], // 方法表達式是否須要命名 "func-names": 0, // 方法定義風格,參數: // declaration: 強制使用方法聲明的方式,function f(){} e.g [2, "declaration"] // expression:強制使用方法表達式的方式,var f = function() {} e.g [2, "expression"] // allowArrowFunctions: declaration風格中容許箭頭函數。 e.g [2, "declaration", { "allowArrowFunctions": true }] "func-style": 0, "generator-star-spacing": [2, { "before": true, "after": true }], "guard-for-in": 0, // 強制回調錯誤處理 "handle-callback-err": [2, "^(err|error)$" ], // 強制使用一致的縮進 "indent": [2, 4, { "SwitchCase": 1 }], // 強制在對象字面量的鍵和值之間使用一致的空格 "key-spacing": [2, { "beforeColon": true, "afterColon": true }], // keyword-spacing 強制關鍵字周圍空格的一致性 // "before": true (默認) 要求在關鍵字以前至少有一個空格 // "before": false 禁止在關鍵字以前有空格 // "after": true (默認) 要求在關鍵字以後至少有一個空格 // "after": false 禁止在關鍵字以後有空格 // "overrides" 容許覆蓋指定的關鍵字的空格風格 "keyword-spacing":[2,{"before": true, "after": true }], "linebreak-style": 0, "lines-around-comment": 0, "max-nested-callbacks": 0, // 要求構造函數首字母大寫 "new-cap": [2, { "newIsCap": true, "capIsNew": true }], // 要求調用無參構造函數時帶括號 "new-parens": 2, "newline-after-var": 0, // 禁用 alert alert、prompt 和 confirm 時,該規則將發出警告。 "no-alert": 2, // 禁止使用 Array 構造函數 "no-array-constructor": 2, // 禁用 caller 或 callee "no-caller": 2, // 不容許在 catch 語句中遮蓋變量 "no-catch-shadow": 2, // 禁止在條件語句中出現賦值操做符 "no-cond-assign": 2, // 禁用 console "no-console": 2, // 禁止在條件中使用常量表達式 "no-constant-condition": 2, // 禁用 continue "no-continue": 2, // 禁止在正則表達式中使用控制字符 "no-control-regex": 2, // 禁用 debugger "no-debugger": 2, // 禁止刪除變量 // delete 的目的是刪除對象的屬性。使用 delete 操做刪除一個變量可能會致使意外狀況發生 "no-delete-var": 2, // 禁止使用看起來像除法的正則表達式 // function bar() { return /=foo/; } 錯誤 // function bar() { return /\=foo/; }正確 "no-div-regex": 2, // 禁止在 function 定義中出現重複的參數 "no-dupe-args": 2, // 禁止在對象字面量中出現重複的鍵 "no-dupe-keys": 2, // 禁止重複 case 標籤 "no-duplicate-case": 2, // 禁止在 else 前有 return "no-else-return": 2, // 禁止空塊語句 "no-empty": 0, // 禁止在正則表達式中出現空字符集 "no-empty-character-class": 2, // 禁止與 null 進行比較 "no-eq-null": 2, // 禁用 eval() "no-eval": 2, // 禁止對 catch 子句中的異常從新賦值 "no-ex-assign": 2, // 禁止擴展原生對象 "no-extend-native": 2, // 禁止沒必要要的函數綁定 "no-extra-bind": 2, // 禁止沒必要要的布爾類型轉換 "no-extra-boolean-cast": 2, // 禁止冗餘的括號 "no-extra-parens": 2, // 禁用沒必要要的分號 "no-extra-semi": 2, // 禁止 case 語句落空 "no-fallthrough": 2, // 禁止浮點小數 "no-floating-decimal": 2, // 禁止對 function 聲明從新賦值 "no-func-assign": 2, // 禁用隱式的eval() "no-implied-eval": 2, // 禁止使用內聯註釋 "no-inline-comments": 2, // 禁止在嵌套的語句塊中出現變量或 function 聲明 "no-inner-declarations": [2, "functions"], // 禁止在 RegExp 構造函數中出現無效的正則表達式 "no-invalid-regexp": 2, // 禁止不規則的空白 "no-irregular-whitespace": 2, // 禁用迭代器 "no-iterator": 2, // 禁用與變量同名的標籤 "no-label-var": 2, // no-labels 規則旨在消除 JavaScript 中標籤的使用。當遇到標籤語句時,該規則將發出警告。 /** * 示例: 標籤語句 outer: while (true) { while (true) { break outer; } } */ "no-labels": 2, // 禁用沒必要要的嵌套塊 "no-lone-blocks": 2, // 禁止 if 語句做爲惟一語句出如今 else 語句塊中 "no-lonely-if": 2, // 禁止循環中存在函數 "no-loop-func": 2, // 禁止 require 調用與普通變量聲明混合使用 "no-mixed-requires": 2, // 禁止使用 空格 和 tab 混合縮進 "no-mixed-spaces-and-tabs": 2, // 禁止出現多個空格 "no-multi-spaces": 2, // 禁止多行字符串 "no-multi-str": 2, // 不容許多個空行 "no-multiple-empty-lines": [2, { "max": 1 }], // 現版本已經做廢 "no-native-reassign": 2, // 替代 no-unsafe-negation "no-negated-in-lhs": 2, "no-nested-ternary": 0, "no-new": 2, "no-new-func": 0, "no-new-object": 2, "no-new-require": 2, "no-new-wrappers": 2, "no-obj-calls": 2, "no-octal": 2, "no-octal-escape": 2, "no-param-reassign": 0, "no-path-concat": 0, "no-process-env": 0, "no-process-exit": 0, "no-proto": 0, "no-redeclare": 2, "no-regex-spaces": 2, "no-restricted-modules": 0, "no-return-assign": 2, "no-script-url": 0, "no-self-compare": 2, "no-sequences": 2, "no-shadow": 0, "no-shadow-restricted-names": 2, "no-spaced-func": 2, "no-sparse-arrays": 2, "no-sync": 0, "no-ternary": 0, "no-this-before-super": 2, "no-throw-literal": 2, // 禁用行尾空白 "no-trailing-spaces": 2, // 禁用未聲明的變量 "no-undef": 2, "no-undef-init": 2, "no-undefined": 0, "no-underscore-dangle": 0, "no-unexpected-multiline": 2, "no-unneeded-ternary": 2, "no-unreachable": 2, "no-unused-expressions": 0, // 禁止未使用過的變量 "no-unused-vars": [1, { "vars": "all", "args": "none" }], // 禁止定義前使用 "no-use-before-define": 2, "no-var": 0, "no-void": 0, "no-warning-comments": 0, "no-with": 2, "object-curly-spacing": 0, "object-shorthand": 0, // 強制函數中的變量在一塊兒聲明或分開聲明 "one-var": [2, { "initialized": "never" }], "operator-assignment": 0, "operator-linebreak": [2, "after", { "overrides": { "?": "before", ":": "before" } }], "padded-blocks": 0, "prefer-const": 0, "quote-props": 0, // 字符串使用單引號 single、double、 // "double" (默認) 要求儘量地使用雙引號 // "single" 要求儘量地使用單引號 // "backtick" 要求儘量地使用反勾號 // "avoidEscape": true 容許字符串使用單引號或雙引號,只要字符串中包含了一個其它引號,不然須要轉義 "quotes": [2, "double", "avoid-escape"], // 要求必須有基數 var num = parseInt("071", 10); // 71 "radix": 2, // "always" (默認) 要求在語句末尾使用分號 // "never" 禁止在語句末尾使用分號 (除了消除以 [、(、/、+ 或 - 開始的語句的歧義) // "omitLastInOneLineBlock":ture 忽略花括號在同一行(內容也就在同一行了)的語句塊中的最後一個分號 "semi": [2, "always", {"omitLastInOneLineBlock": true}], // 這個是默認選項,它強制分號以後有空格,禁止分號以前有空格。 "semi-spacing": [2, {"before": false, "after": true}], "sort-vars": 0, // 要求或禁止語句塊以前的空格 "space-before-blocks": [2, "always"], // 要求或禁止函數圓括號以前有一個空格 // always (默認) 要求在參數的 ( 前面有一個空格。 // never 禁止在參數的 ( 前面有空格。 "space-before-function-paren": [2, "never"], "space-in-parens": [2, "never"], // 要求中綴操做符周圍有空格 "space-infix-ops": 1, "space-unary-ops": [2, { "words": true, "nonwords": false }], //要求或禁止在註釋前有空白 "spaced-comment": [2, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!"] }], // "safe" (默認) 對應下面的選項: // "global" 若是 ESLint 認爲一個文件是 CommonJS 模塊 // "function" 若是 ESLint 認爲一個文件不是 CommonJS 模塊 // "global" 要求在全局做用域下有一個嚴格模式指令(不容許任何其它嚴格模式指令) // "function" 要求在函數聲明或表達式開始位置有一個嚴格模式指令(不容許任何其它嚴格模式指令) // "never" 禁用嚴格模式指令 "strict": [2, "safe"], "use-isnan": 2, "valid-jsdoc": 0, "valid-typeof": 2, "vars-on-top": 0, "wrap-iife": [2, "any"], "wrap-regex": 0, "yoda": [2, "never"] } } // package.json { "name": "xiaomickts", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "node-sass scss -w -o css" }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "babel-eslint": "^8.2.2", "eslint": "^4.19.1", "eslint-plugin-react": "^7.7.0", "node-sass": "^4.8.3" } }