diff --git a/.eslintrc b/.eslintrc index a7552e7..d811f40 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,199 +1,3 @@ { - "parserOptions": { - "ecmaVersion": 6, - "ecmaFeatures": { - "jsx": true - } - }, - "parser": "espree", - "env": { - "amd": false, - "jasmine": false, - "node": true, - "mocha": true, - "browser": true, - "builtin": true, - "es6": true - }, - "rules": { - "no-alert": 2, - "no-array-constructor": 2, - "no-bitwise": 2, - "no-caller": 2, - "no-catch-shadow": 2, - "no-cond-assign": [2, "except-parens"], - "no-constant-condition": 2, - "no-continue": 0, - "no-control-regex": 2, - "no-debugger": 2, - "no-delete-var": 2, - "no-div-regex": 0, - "no-dupe-keys": 2, - "no-dupe-args": 2, - "no-duplicate-case": 2, - "no-else-return": 0, - "no-empty": 2, - "no-empty-character-class": 2, - "no-eq-null": 0, - "no-eval": 2, - "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, - "no-fallthrough": 2, - "no-floating-decimal": 0, - "no-func-assign": 2, - "no-implied-eval": 2, - "no-inline-comments": 0, - "no-inner-declarations": [2, "functions"], - "no-invalid-regexp": 2, - "no-irregular-whitespace": 2, - "no-iterator": 0, - "no-label-var": 2, - "no-labels": 2, - "no-lone-blocks": 2, - "no-lonely-if": 0, - "no-loop-func": 2, - "no-mixed-requires": [0, false], - "no-mixed-spaces-and-tabs": [2, false], - "linebreak-style": [0, "unix"], - "no-multi-spaces": 2, - "no-multi-str": 2, - "no-multiple-empty-lines": [0, { - "max": 2 - }], - "no-native-reassign": 2, - "no-negated-in-lhs": 2, - "no-nested-ternary": 0, - "no-new": 0, - "no-new-func": 2, - "no-new-object": 2, - "no-new-require": 0, - "no-new-wrappers": 2, - "no-obj-calls": 2, - "no-octal": 2, - "no-octal-escape": 2, - "no-param-reassign": 0, - "no-path-concat": 0, - "no-plusplus": 0, - "no-process-env": 0, - "no-process-exit": 0, - "no-proto": 2, - "no-redeclare": 2, - "no-regex-spaces": 2, - "no-restricted-modules": 0, - "no-return-assign": 0, - "no-script-url": 2, - "no-self-compare": 0, - "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-trailing-spaces": 2, - "no-this-before-super": 0, - "no-throw-literal": 0, - "no-undef": 2, - "no-undef-init": 2, - "no-undefined": 0, - "no-unexpected-multiline": 0, - "no-underscore-dangle": 0, - "no-unneeded-ternary": 0, - "no-unreachable": 2, - "no-unused-expressions": 0, - "no-unused-vars": 2, - "no-use-before-define": [2, "nofunc"], - "no-void": 0, - "no-var": 2, - "no-const-assign": 2, - "prefer-const": 0, - "no-warning-comments": [0, { - "terms": ["todo", "fixme", "xxx"], - "location": "start" - }], - "no-with": 2, - "array-bracket-spacing": [0, "never"], - "accessor-pairs": 0, - "block-scoped-var": 0, - "brace-style": [0, "1tbs"], - "camelcase": 0, - "comma-dangle": [2, "always-multiline"], - "comma-spacing": 2, - "comma-style": 0, - "complexity": [0, 11], - "computed-property-spacing": [0, "never"], - "consistent-return": 0, - "consistent-this": [0, "that"], - "constructor-super": 0, - "curly": [2, "multi-line"], - "default-case": 0, - "dot-location": 0, - "dot-notation": 0, - "eol-last": 2, - "eqeqeq": [2, "allow-null"], - "func-names": 0, - "func-style": [0, "declaration"], - "generator-star-spacing": 0, - "guard-for-in": 0, - "handle-callback-err": 0, - "indent": [2, 2, {"SwitchCase": 1}], - "key-spacing": [2, { - "beforeColon": false, - "afterColon": true - }], - "keyword-spacing": [2, { - "before": true, - "after": true - }], - "lines-around-comment": 0, - "max-depth": [0, 4], - "max-len": [0, 80, 4], - "max-nested-callbacks": [0, 2], - "max-params": [0, 3], - "max-statements": [0, 10], - "new-cap": 0, - "new-parens": 2, - "newline-after-var": 0, - "object-curly-spacing": [0, "never"], - "object-shorthand": 0, - "one-var": 0, - "operator-assignment": [0, "always"], - "operator-linebreak": 0, - "padded-blocks": 0, - "quote-props": 0, - "quotes": [2, "single"], - "radix": 0, - "semi": 2, - "semi-spacing": [2, { - "before": false, - "after": true - }], - "sort-vars": 0, - "space-before-blocks": [2, "always"], - "space-before-function-paren": [2, "never"], - "space-in-parens": [2, "never"], - "space-infix-ops": 2, - "space-unary-ops": [2, { - "words": true, - "nonwords": false - }], - "spaced-comment": [2, "always", { "markers": ["*!"] }], - "strict": [2, "global"], - "use-isnan": 2, - "valid-jsdoc": [2, { - "prefer": { - "returns": "return" - }, - "requireReturn": false - }], - "valid-typeof": 0, - "vars-on-top": 0, - "wrap-iife": 0, - "wrap-regex": 0, - "yoda": [2, "never"] - } + "extends": "./index.js" } diff --git a/index.js b/index.js index f327710..304530b 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,16 @@ 'use strict'; -const fs = require('fs'); -const path = require('path'); - -module.exports = JSON.parse(fs.readFileSync(path.join(__dirname, '.eslintrc'))); +module.exports = { + parser: 'espree', + parserOptions: { + ecmaVersion: 6, + sourceType: 'modules', + ecmaFeatures: { + jsx: true, + }, + }, + 'extends': [ + './rules/es6', + './legacy', + ].map(require.resolve), +}; diff --git a/legacy.js b/legacy.js new file mode 100644 index 0000000..ace40a8 --- /dev/null +++ b/legacy.js @@ -0,0 +1,20 @@ +'use strict'; + +module.exports = { + env: { + amd: false, + jasmine: false, + node: true, + mocha: true, + browser: true, + builtin: true, + }, + 'extends': [ + './rules/best-practices', + './rules/strict', + './rules/variables', + './rules/style', + './rules/node', + './rules/errors', + ].map(require.resolve), +}; diff --git a/package.json b/package.json index dc24c0c..dd2960d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "homepage": "https://github.com/egg-express/eslint-config-egg", "author": "popomore ", "scripts": { - "lint": "eslint test index.js", + "lint": "eslint test index.js legacy.js rules/*.js", "test": "mocha", "ci": "npm run lint && npm run test", "autod": "autod -e test/fixtures -f ~ -w" diff --git a/rules/best-practices.js b/rules/best-practices.js new file mode 100644 index 0000000..0a6ad30 --- /dev/null +++ b/rules/best-practices.js @@ -0,0 +1,673 @@ +'use strict'; + +module.exports = { + rules: { + /** + * 不强制要求 getter/setter 成对出现 + * @see http://eslint.org/docs/rules/accessor-pairs + */ + 'accessor-pairs': 0, + + /** + * 校验下列方法的回调中是否有 `return` + * + * ```js + * Array.from + * Array.prototype.every + * Array.prototype.filter + * Array.prototype.find + * Array.prototype.findIndex + * Array.prototype.map + * Array.prototype.reduce + * Array.prototype.reduceRight + * Array.prototype.some + * Array.prototype.sort + * ``` + * @see http://eslint.org/docs/rules/array-callback-return + */ + 'array-callback-return': 2, + + /** + * 不允许在 block scope 内使用 var 声明变量 + * @see http://eslint.org/docs/rules/block-scoped-var + * @since 3.0.0 + */ + 'block-scoped-var': 2, + + /** + * 条件判断最多允许 11 条路径 + * @see http://eslint.org/docs/rules/complexity + */ + complexity: 0, + + /** + * 如果方法中的某条逻辑路径最终有 `return` 语句,其它逻辑路径不强制有 `return` 语句 + * @see http://eslint.org/docs/rules/consistent-return + * @example + * + * ```js + * // 正确 + * function doSomething(condition) { + * if (condition) { + * return true; + * } + * } + * ``` + */ + 'consistent-return': 0, + + /** + * 花括号使用习惯 + * + * 1. 只有一行的 `if`, `else if`, `else`, `for`, `while`, `do` 声明可以不用花括号 + * + * @see http://eslint.org/docs/rules/curly + * @example + * + * ```js + * // 错误 + * if (foo) + * doSomething(); + * else + * doSomethingElse(); + * + * // 正确 + * if (foo) doSomething(); + * + * if (foo) doSomething(); + * else doSomethingElse(); + * + * do something(); + * while (foo); + * ``` + */ + curly: [ 2, 'multi-line' ], + + /** + * `switch` 声明必须有 `default` 处理,可以使用 `no default` 跳过验证 + * @see http://eslint.org/docs/rules/default-case + * @since 3.0.0 + * @example + * + * ```js + * // 正确 + * switch (foo) { + * case 1: + * doSomething(); + * break; + * + * case 2: + * doSomething(); + * break; + * + * // no default + * } + * ``` + */ + 'default-case': [ 2, { commentPattern: '^no default$' }], + + /** + * 能够随意使用 `foo.bar` 或 `foo['bar']` 的时候必须使用 `foo.bar` + * @see http://eslint.org/docs/rules/dot-notation + * @since 3.0.0 + * @example + * + * ```js + * // 错误 + * const x = foo['bar']; + * + * // 正确 + * const obj = foo.bar; + * const y = foo[arg]; + * + * // 特别地,保留词做 key 时,下面的写法是正确的 + * const foo = bar['class']; + * ``` + */ + 'dot-notation': [ 2, { allowKeywords: false }], + + /** + * 允许在成员表示的 `.` 前后增加新行 + * @see http://eslint.org/docs/rules/dot-location + * @example + * + * ```js + * // 正确 + * const a = foo. + * bar; + * + * const b = foo + * .bar; + * ``` + */ + 'dot-location': 0, + + /** + * 强制使用 `===` 和 `!==` + * @see http://eslint.org/docs/rules/eqeqeq + * @example + * + * ```js + * // 正确 + * a === b + * foo === true + * bananas !== 1 + * value === undefined + * typeof foo === 'undefined' + * 'hello' !== 'world' + * 0 === 0 + * true === true + * foo === null + * foo == null + * + * // 错误 + * a == b + * foo == true + * bananas != 1 + * value == undefined + * typeof foo == 'undefined' + * 'hello' != 'world' + * 0 == 0 + * true == true + * foo == null + * ``` + */ + eqeqeq: [ 2, 'allow-null' ], + + /** + * `for in` 循环内,可以不排除继承的属性 + * @see http://eslint.org/docs/rules/guard-for-in + */ + 'guard-for-in': 0, + + /** + * 不允许 `alert` + * @see http://eslint.org/docs/rules/no-alert + */ + 'no-alert': 2, + + /** + * 不允许使用 `arguments.caller` 或 `arguments.callee` + * @see http://eslint.org/docs/rules/no-caller + */ + 'no-caller': 2, + + /** + * 为了避免 `case` 声明的变量处在整个 `switch` 句块内,需要将 `case` 的处理函数用花括 + * 号包裹形成独立的句块 + * @see http://eslint.org/docs/rules/no-case-declarations + * @example + * + * ```js + * // 错误 + * switch (foo) { + * case 1: + * let x = 1; + * break; + * case 2: + * const y = 2; + * break; + * // no default + * + * // 正确 + * switch (foo) { + * case 1: { + * let x = 1; + * break; + * } + * case 2: { + * const y = 2; + * break; + * } + * // no default + * ``` + */ + 'no-case-declarations': 2, + + /** + * 看起来像除法的正则式是可以被允许的 + * @see http://eslint.org/docs/rules/no-div-regex + */ + 'no-div-regex': 0, + + /** + * `if` 中不允许在 `return` 后出现 `else` + * @see http://eslint.org/docs/rules/no-else-return + * @since 3.0.0 + */ + 'no-else-return': 2, + + /** + * 不允许空方法 + * @see http://eslint.org/docs/rules/no-empty-function + * @example + * + * 特别地,允许下列几种: + * + * #### 箭头方法 `arrowFunctions` + * + * ```js + * const foo = () => {}; + * ``` + * + * #### 普通方法 `functions` + * + * ```js + * function foo() {} + * + * const foo = function() {}; + * + * const obj = { + * foo: function() {} + * }; + * ``` + * + * #### 类方法和字面对象的简化写法 `methods` + * + * ```js + * const obj = { + * foo() {} + * }; + * + * class A { + * foo() {} + * static foo() {} + * } + * ``` + * + * 以下的写法是不允许的 + * + * ```js + * // generatorFunctions + * function* foo() {} + * const foo = function*() {}; + * + * // generatorMethods + * const obj = { + * foo: function*() {}, + * *foo() {}, + * }; + * + * // getters or setters + * const obj = { + * get foo() {}, + * set foo(value) {}, + * }; + * + * // constructors + * class A { + * constructor() {} + * } + * + * // mixed + * const obj = { + * bar: 123, + * foo: () => this.bar, + * *foo() {}, + * } + * ``` + */ + 'no-empty-function': [ 2, { + allow: [ + 'arrowFunctions', + 'functions', + 'methods', + ], + }], + + /** + * 不允许空的解构赋值语法 + * @see http://eslint.org/docs/rules/no-empty-pattern + * @example + * + * ```js + * // 错误 + * const {} = foo; + * const [] = foo; + * const {a: {}} = foo; + * const {a: []} = foo; + * function foo({}) {} + * function foo([]) {} + * function foo({a: {}}) {} + * function foo({a: []}) {} + * ``` + */ + 'no-empty-pattern': 2, + + /** + * 允许 `foo == null` + * @see http://eslint.org/docs/rules/no-eq-null + */ + 'no-eq-null': 0, + + /** + * 不允许 `eval` + * @see http://eslint.org/docs/rules/no-eval + */ + 'no-eval': 2, + + /** + * 不允许对 JS 原生方法进行拓展 + * @see http://eslint.org/docs/rules/no-extend-native + * @example + * + * ```js + * // 错误 + * Object.prototype.a = "a"; + * Object.defineProperty(Array.prototype, "times", { value: 999 }); + * ``` + */ + 'no-extend-native': 2, + + /** + * 不允许多余的 `bind` 操作 + * @see http://eslint.org/docs/rules/no-extra-bind + */ + 'no-extra-bind': 2, + + /** + * 循环中不允许出现多余的 label + * @see http://eslint.org/docs/rules/no-extra-label + */ + 'no-extra-label': 2, + + /** + * 不允许在 `switch` 内出现多个 `case` 贯通 + * @see http://eslint.org/docs/rules/no-fallthrough + */ + 'no-fallthrough': 2, + + /** + * 不允许 `.7`, `-.7`, `2.` 的写法 + * @see http://eslint.org/docs/rules/no-floating-decimal + * @since 3.0.0 + */ + 'no-floating-decimal': 2, + + /** + * 允许使用简写法做类型转换 + * @see http://eslint.org/docs/rules/no-implicit-coercion + * @example + * + * ```js + * // 正确 + * const b = !!foo; + * const b = ~foo.indexOf("."); + * const n = +foo; + * const n = 1 * foo; + * const s = "" + foo; + * foo += ""; + * ``` + */ + 'no-implicit-coercion': 0, + + /** + * 允许在全局作用域内使用 `const` 和实名方法表示全局变量 + * @see http://eslint.org/docs/rules/no-implicit-globals + */ + 'no-implicit-globals': 0, + + /** + * 不允许类似 `eval` 作用的语法 + * @see http://eslint.org/docs/rules/no-implied-eval + */ + 'no-implied-eval': 2, + + /** + * 允许在 class 或类似 class 对象外使用 `this` + * @see http://eslint.org/docs/rules/no-invalid-this + */ + 'no-invalid-this': 0, + + /** + * 允许使用 `__iterator__` + * @see http://eslint.org/docs/rules/no-iterator + */ + 'no-iterator': 0, + + /** + * 不允许使用 label + * @see http://eslint.org/docs/rules/no-labels + */ + 'no-labels': [ 2, { allowLoop: false, allowSwitch: false }], + + /** + * 不允许多余的代码 `block` + * @see http://eslint.org/docs/rules/no-lone-blocks + */ + 'no-lone-blocks': 2, + + /** + * 循环内不能有 `function` + * @see http://eslint.org/docs/rules/no-loop-func + */ + 'no-loop-func': 2, + + /** + * 不允许不明所以的数字 + * + * 特别地,允许下列情况: + * + * 1. 数组索引 + * 2. 使用 `const` 声明的数字 + * 3. 对象中的属性值是数字 + * + * @see http://eslint.org/docs/rules/no-magic-numbers + * @example + * + * ```js + * // 错误 + * const foo = bar + 60 * 60 * 1000 + * + * // 正确 + * const hourInMs = 60 * 60 * 1000; + * const foo = bar + hourInMs; + * ``` + */ + 'no-magic-numbers': [ 0, { + ignore: [], + ignoreArrayIndexes: true, + enforceConst: true, + detectObjects: false, + }], + + /** + * 不允许连续空格 + * @see http://eslint.org/docs/rules/no-multi-spaces + */ + 'no-multi-spaces': 2, + + /** + * 不允许使用 `\` 标识转行 + * @see http://eslint.org/docs/rules/no-multi-str + */ + 'no-multi-str': 2, + + /** + * 不允许给原生对象重新赋值 + * @see http://eslint.org/docs/rules/no-native-reassign + */ + 'no-native-reassign': 2, + + /** + * 允许在赋值和比较语句之外使用 `new` + * @see http://eslint.org/docs/rules/no-new + * @example + * + * ```js + * // 正确 + * new Thing(); + * + * const thing = new Thing(); + * + * Thing(); + * ``` + */ + 'no-new': 0, + + /** + * 不允许使用 `new Function()` + * @see http://eslint.org/docs/rules/no-new-func + */ + 'no-new-func': 2, + + /** + * 不允许使用 `new String()`, `new Number()`, `new Boolean()` 创建实例 + * @see http://eslint.org/docs/rules/no-new-wrappers + */ + 'no-new-wrappers': 2, + + /** + * 不允许用0开头表示八进制 + * @see http://eslint.org/docs/rules/no-octal + */ + 'no-octal': 2, + + /** + * 不允许在字符串内使用八进制 escape + * @see http://eslint.org/docs/rules/no-octal-escape + */ + 'no-octal-escape': 2, + + /** + * 允许对参数赋值 + * @see http://eslint.org/docs/rules/no-param-reassign + */ + 'no-param-reassign': 0, + + /** + * 不允许使用 `__proto__` + * @see http://eslint.org/docs/rules/no-proto + */ + 'no-proto': 2, + + /** + * 不允许重复声明变量 + * @see http://eslint.org/docs/rules/no-redeclare + */ + 'no-redeclare': 2, + + /** + * 不允许在 `return` 语句里赋值 + * @see http://eslint.org/docs/rules/no-return-assign + * @since 3.0.0 + */ + 'no-return-assign': 2, + + /** + * 不允许给 `url` 赋值 `javascript:` + * @see http://eslint.org/docs/rules/no-script-url + */ + 'no-script-url': 2, + + /** + * 不允许 `foo = foo` + * @see http://eslint.org/docs/rules/no-self-assign + */ + 'no-self-assign': 2, + + /** + * 不允许 `foo === foo` + * @see http://eslint.org/docs/rules/no-self-compare + * @since 3.0.0 + */ + 'no-self-compare': 2, + + /** + * 不允许使用 `,` 操作符 + * @see http://eslint.org/docs/rules/no-sequences + */ + 'no-sequences': 2, + + /** + * 不限制 `throw` 的对象 + * @see http://eslint.org/docs/rules/no-throw-literal + */ + 'no-throw-literal': 0, + + /** + * disallow unmodified conditions of loops + * @see http://eslint.org/docs/rules/no-unmodified-loop-condition + */ + 'no-unmodified-loop-condition': 0, + + /** + * 不检查未使用到的语句 + * @see http://eslint.org/docs/rules/no-unused-expressions + * @since 3.0.0 + */ + 'no-unused-expressions': [ 2, { + allowShortCircuit: true, + allowTernary: true, + }], + + /** + * disallow unused labels + * @see http://eslint.org/docs/rules/no-unused-labels + */ + 'no-unused-labels': 2, + + /** + * 允许不必要的 `.call()`, `.apply()` + * @see http://eslint.org/docs/rules/no-useless-call + */ + 'no-useless-call': 0, + + /** + * disallow useless string concatenation + * @see http://eslint.org/docs/rules/no-useless-concat + */ + 'no-useless-concat': 2, + + /** + * disallow unnecessary string escaping + * @see http://eslint.org/docs/rules/no-useless-escape + */ + 'no-useless-escape': 2, + + /** + * 允许使用 `void` + * @see http://eslint.org/docs/rules/no-void + */ + 'no-void': 0, + + /** + * 允许警示性的注释 + * @see http://eslint.org/docs/rules/no-warning-comments + */ + 'no-warning-comments': [ 0, { + terms: [ 'todo', 'fixme', 'xxx' ], + location: 'start', + }], + + /** + * disallow use of the `with` statement + * @see http://eslint.org/docs/rules/no-with + */ + 'no-with': 2, + + /** + * 使用 `parseInt()` 时可以没有第二个参数 + * @see http://eslint.org/docs/rules/radix + */ + radix: 0, + + /** + * 不限制变量声明的位置 + * @see http://eslint.org/docs/rules/consts-on-top + */ + 'vars-on-top': 0, + + /** + * 不需要包裹 immediately-invoked function expression(即时运行函数) + * @see http://eslint.org/docs/rules/wrap-iife + */ + 'wrap-iife': 0, + + /** + * 变量在先,条件在后 + * @see http://eslint.org/docs/rules/yoda + */ + yoda: 2, + }, +}; diff --git a/rules/errors.js b/rules/errors.js new file mode 100644 index 0000000..da9ef63 --- /dev/null +++ b/rules/errors.js @@ -0,0 +1,200 @@ +'use strict'; + +module.exports = { + rules: { + /** + * require trailing commas in multiline object literals + * @see http://eslint.org/docs/rules/comma-dangle + */ + 'comma-dangle': [ 2, 'always-multiline' ], + + /** + * @see http://eslint.org/docs/rules/no-cond-assign + * @example + * + * ```js + * // 错误 + * function setHeight(someNode) { + * do { + * someNode.height = "100px"; + * } while (someNode = someNode.parentNode); + * } + * + * // 正确 + * function setHeight(someNode) { + * do { + * someNode.height = "100px"; + * } while ((someNode = someNode.parentNode)); + * } + * ``` + */ + 'no-cond-assign': [ 2, 'except-parens' ], + + /** + * 使用 `console` 时警告 + * @see http://eslint.org/docs/rules/no-console + */ + 'no-console': 1, + + /** + * disallow use of constant expressions in conditions + * @see http://eslint.org/docs/rules/no-constant-condition + */ + 'no-constant-condition': 2, + + /** + * disallow control characters in regular expressions + * @see http://eslint.org/docs/rules/no-control-regex + */ + 'no-control-regex': 2, + + /** + * disallow use of debugger + * @see http://eslint.org/docs/rules/no-debugger + */ + 'no-debugger': 2, + + /** + * disallow duplicate arguments in functions + * @see http://eslint.org/docs/rules/no-dupe-args + */ + 'no-dupe-args': 2, + + /** + * disallow duplicate keys when creating object literals + * @see http://eslint.org/docs/rules/no-dupe-keys + */ + 'no-dupe-keys': 2, + + /** + * disallow a duplicate case label. + * @see http://eslint.org/docs/rules/no-duplicate-case + */ + 'no-duplicate-case': 2, + + /** + * disallow empty statements + * @see http://eslint.org/docs/rules/no-empty + */ + 'no-empty': 2, + + /** + * disallow the use of empty character classes in regular expressions + * @see http://eslint.org/docs/rules/no-empty-character-class + */ + 'no-empty-character-class': 2, + + /** + * disallow assigning to the exception in a catch block + * @see http://eslint.org/docs/rules/no-ex-assign + */ + 'no-ex-assign': 2, + + /** + * disallow double-negation boolean casts in a boolean context + * @see http://eslint.org/docs/rules/no-extra-boolean-cast + */ + 'no-extra-boolean-cast': 2, + + /** + * disallow unnecessary parentheses + * @see http://eslint.org/docs/rules/no-extra-parens + */ + 'no-extra-parens': 2, + + /** + * disallow unnecessary semicolons + * @see http://eslint.org/docs/rules/no-extra-semi + */ + 'no-extra-semi': 2, + + /** + * disallow overwriting functions written as function declarations + * @see http://eslint.org/docs/rules/no-func-assign + */ + 'no-func-assign': 2, + + /** + * disallow function declarations in nested blocks + * @see http://eslint.org/docs/rules/no-inner-declarations + */ + 'no-inner-declarations': [ 2, 'functions' ], + + /** + * disallow invalid regular expression strings in the RegExp constructor + * @see http://eslint.org/docs/rules/no-invalid-regexp + */ + 'no-invalid-regexp': 2, + + /** + * disallow irregular whitespace outside of strings and comments + * @see http://eslint.org/docs/rules/no-irregular-whitespace + */ + 'no-irregular-whitespace': 2, + + /** + * disallow negation of the left operand of an in expression + * @see http://eslint.org/docs/rules/no-negated-in-lhs + */ + 'no-negated-in-lhs': 2, + + /** + * disallow the use of object properties of the global object (Math and JSON) as functions + * @see http://eslint.org/docs/rules/no-obj-calls + */ + 'no-obj-calls': 2, + + /** + * disallow multiple spaces in a regular expression literal + * @see http://eslint.org/docs/rules/no-regex-spaces + */ + 'no-regex-spaces': 2, + + /** + * disallow sparse arrays + * @see http://eslint.org/docs/rules/no-sparse-arrays + */ + 'no-sparse-arrays': 2, + + /** + * Avoid code that looks like two expressions but is actually one + * @see http://eslint.org/docs/rules/no-unexpected-multiline + */ + 'no-unexpected-multiline': 0, + + /** + * disallow unreachable statements after a return, throw, continue, or break statement + * @see http://eslint.org/docs/rules/no-unreachable + */ + 'no-unreachable': 2, + + /** + * disallow return/throw/break/continue inside finally blocks + * @see http://eslint.org/docs/rules/no-unsafe-finally + */ + 'no-unsafe-finally': 2, + + /** + * disallow comparisons with the value NaN + * @see http://eslint.org/docs/rules/use-isnan + */ + 'use-isnan': 2, + + /** + * ensure JSDoc comments are valid + * @see http://eslint.org/docs/rules/valid-jsdoc + */ + 'valid-jsdoc': [ 2, { + prefer: { + returns: 'return', + }, + requireReturn: false, + }], + + /** + * 允许使用不正确的字符串作为 `typeof` 的结果,例如 `typeof foo === "strnig"` + * @see http://eslint.org/docs/rules/valid-typeof + */ + 'valid-typeof': 0, + }, +}; diff --git a/rules/es6.js b/rules/es6.js new file mode 100644 index 0000000..cb755c1 --- /dev/null +++ b/rules/es6.js @@ -0,0 +1,267 @@ +/** + * ES6 语法规范 + */ + +'use strict'; + +module.exports = { + env: { + es6: true, + }, + parserOptions: { + ecmaVersion: 6, + sourceType: 'module', + }, + rules: { + /** + * 当箭头函数的花括号能够被省略的时候,不强制省略 + * @see http://eslint.org/docs/rules/arrow-body-style + * @since 3.0.0 + * @example + * + * ```js + * // 正确 + * let foo = () => { + * return 0; + * }; + * + * let foo = () => { + * return { + * bar: { + * foo: 1, + * bar: 2, + * } + * }; + * }; + * + * let foo = () => 0; + * + * let foo = () => ({ + * bar: { + * foo: 1, + * bar: 2, + * } + * }); + ** ``` + */ + 'arrow-body-style': 0, + + /** + * 当箭头函数的参数括号能够被省略的时候,强制省略 + * @see http://eslint.org/docs/rules/arrow-parens + */ + 'arrow-parens': [ 2, 'as-needed' ], + + /** + * 箭头函数的「箭头」前后都必须有空格 + * @see http://eslint.org/docs/rules/arrow-spacing + */ + 'arrow-spacing': [ 2, { before: true, after: true }], + + /** + * 不强制检查继承 `constructor` 函数内的 `super` + * @see http://eslint.org/docs/rules/constructor-super + */ + 'constructor-super': 0, + + /** + * `generator` 的 `*` 符号强制前无空格,后有空格 + * @see http://eslint.org/docs/rules/generator-star-spacing + * @since 3.0.0 + * @example + * + * ```js + * function* generator() { + * yield '44'; + * yield '55'; + * } + * ``` + */ + 'generator-star-spacing': [ 2, { before: false, after: true }], + + /** + * 禁止对类声明的变量进行覆写 + * @see http://eslint.org/docs/rules/no-class-assign + */ + 'no-class-assign': 2, + + /** + * 当箭头函数容易被混淆时,禁止使用箭头函数。允许用括号包裹区分 + * @see http://eslint.org/docs/rules/no-confusing-arrow + * @example + * + * ```js + * var x = a => 1 ? 2 : 3; // 错误 + * var x = a => (1 ? 2 : 3); // 正确 + * ```` + */ + 'no-confusing-arrow': [ 2, { + allowParens: true, + }], + + /** + * 禁止对 `const` 声明的变量进行覆写 + * @see http://eslint.org/docs/rules/no-const-assign + */ + 'no-const-assign': 2, + + /** + * 禁止 `class` 中出现同名的 `member` + * @see http://eslint.org/docs/rules/no-dupe-class-members + */ + 'no-dupe-class-members': 2, + + /** + * 允许使用 `new Symbol('foo')` 语法 + * @see http://eslint.org/docs/rules/no-new-symbol + */ + 'no-new-symbol': 0, + + /** + * `constructor` 方法内,禁止在 `super()` 之前使用 `this/super` + * @see http://eslint.org/docs/rules/no-this-before-super + * @since 3.0.0 + */ + 'no-this-before-super': 2, + + /** + * 禁止无用的计算属性名 + * @see http://eslint.org/docs/rules/no-useless-computed-key + * @example + * + * ```js + * foo = { ['a' + 'b']: 'foo' }; // 正确 + * foo = { ['a']: 'bar' }; // 错误 + * ``` + */ + 'no-useless-computed-key': 2, + + /** + * 不允许多余的 `constructor` + * @see http://eslint.org/docs/rules/no-useless-constructor + */ + 'no-useless-constructor': 2, + + /** + * 强制使用 `let` 或 `const` + * @see http://eslint.org/docs/rules/no-var + */ + 'no-var': 2, + + /** + * 对象字面声明时, 方法和属性要使用速写法 + * @see http://eslint.org/docs/rules/object-shorthand + * @since 3.0.0 + * @example + * + * ```js + * // properties + * const foo = { x, y, z }; + * + * // methods + * const foo = { + * a() {}, + * b() {} + * }; + * + * // 错误 + * const foo = { + * 'a-b'() {} + * }; + * + * // 正确 + * const bar = { + * ConstructorFunction: function() {} + * }; + * ``` + */ + 'object-shorthand': [ 2, 'always', { + avoidQuotes: true, + ignoreConstructors: false, + }], + + /** + * 对于申明后就不再修改的变量, 使用 `const` + * @see http://eslint.org/docs/rules/prefer-const + * @since 3.0.0 + * @example + * + * 1. 特别地, 当结构赋值中所有的变量都不再修改才使用 const + * + * ```js + * // 下面的写法是错误的 + * let { a, b } = obj; + * console.log(a, b); + * + * // 下面的写法是正确的 + * let { a, b } = obj; + * a = a + 1; + * console.log(a, b); + * ``` + */ + 'prefer-const': [ 2, { + destructuring: 'all', + ignoreReadBeforeAssign: true, + }], + + /** + * 在能使用的时候不强制使用 Reflect 方法 + * @see http://eslint.org/docs/rules/prefer-reflect + */ + 'prefer-reflect': 0, + + /** + * 不强制使用 rest 获取参数 + * @see http://eslint.org/docs/rules/prefer-rest-params + * @since 3.0.0 + */ + 'prefer-rest-params': 0, + + /** + * 在使用 `.apply()` 调用函数的地方不强制要求使用拓展运算符 `...args` + * @see http://eslint.org/docs/rules/prefer-spread + */ + 'prefer-spread': 0, + + /** + * 使用模板语法而不是字符串拼接 + * @see http://eslint.org/docs/rules/prefer-template + */ + 'prefer-template': 2, + + /** + * generator 内不强制检查 `yield` + * @see http://eslint.org/docs/rules/require-yield + */ + 'require-yield': 0, + + /** + * template 内不允许有空格 + * @see http://eslint.org/docs/rules/template-curly-spacing + * @example + * + * ```js + * // 错误 + * `${ bar }`; + * `hello, ${ people.name}!`; + * `hello, ${people.name }!`; + * + * // 正确 + * `${bar}`; + * `hello, ${people.name}!`; + * + * // 特别地,下面这种用法是允许的 + * `${ + * bar + * }`; + * ``` + */ + 'template-curly-spacing': 2, + + /** + * ` ` + * @see http://eslint.org/docs/rules/yield-star-spacing + */ + 'yield-star-spacing': [ 2, { before: false, after: true }], + }, +}; diff --git a/rules/node.js b/rules/node.js new file mode 100644 index 0000000..7887ff4 --- /dev/null +++ b/rules/node.js @@ -0,0 +1,69 @@ +'use strict'; + +module.exports = { + env: { + node: true, + }, + + rules: { + /** + * not enforce return after a callback + * @see http://eslint.org/docs/rules/callback-return + */ + 'callback-return': 0, + + /** + * not require all requires be top-level + * @see http://eslint.org/docs/rules/global-require + */ + 'global-require': 0, + + /** + * not enforces error handling in callbacks (node environment) + * @see http://eslint.org/docs/rules/handle-callback-err + */ + 'handle-callback-err': 0, + + /** + * allow mixing regular variable and require declarations + * @see http://eslint.org/docs/rules/no-mixed-requires + */ + 'no-mixed-requires': 0, + + /** + * allow use of new operator with the require function + * @see http://eslint.org/docs/rules/no-new-require + */ + 'no-new-require': 0, + + /** + * allow string concatenation with __dirname and __filename + * @see http://eslint.org/docs/rules/no-path-concat + */ + 'no-path-concat': 0, + + /** + * allow use of process.env + * @see http://eslint.org/docs/rules/no-process-env + */ + 'no-process-env': 0, + + /** + * allow process.exit() + * @see http://eslint.org/docs/rules/no-process-exit + */ + 'no-process-exit': 0, + + /** + * not restrict usage of specified node modules + * @see http://eslint.org/docs/rules/no-restricted-modules + */ + 'no-restricted-modules': 0, + + /** + * allow use of synchronous methods + * @see http://eslint.org/docs/rules/no-sync + */ + 'no-sync': 0, + }, +}; diff --git a/rules/strict.js b/rules/strict.js new file mode 100644 index 0000000..c46dfb1 --- /dev/null +++ b/rules/strict.js @@ -0,0 +1,10 @@ +'use strict'; + +module.exports = { + rules: { + /** + * @see http://eslint.org/docs/rules/strict + */ + strict: [ 2, 'global' ], + }, +}; diff --git a/rules/style.js b/rules/style.js new file mode 100644 index 0000000..a5dcb39 --- /dev/null +++ b/rules/style.js @@ -0,0 +1,503 @@ +'use strict'; + +module.exports = { + rules: { + /** + * 规定了中括号中空格位置 + * @see http://eslint.org/docs/rules/array-bracket-spacing + * @since 3.0.0 + */ + 'array-bracket-spacing': [ 2, 'always', { + objectsInArrays: false, + arraysInArrays: false, + }], + + /** + * enforce spaces inside of single line blocks + * @see http://eslint.org/docs/rules/block-spacing + */ + 'block-spacing': [ 2, 'always' ], + + /** + * @see http://eslint.org/docs/rules/brace-style + * @since 3.0.0 + * @example + * + * ```js + * // 正确 + * if (foo) { + * bar(); + * } + * + * // 不正确 + * if (foo) bar(); + * + * if (foo) { + * bar(); + * } + * else { + * baz(); + * } + * ``` + */ + 'brace-style': [ 2, '1tbs' ], + + /** + * not require camel case names + * @see http://eslint.org/docs/rules/camelcase + */ + camelcase: 0, + + /** + * enforce spacing before and after comma + * @see http://eslint.org/docs/rules/comma-spacing + */ + 'comma-spacing': [ 2, { before: false, after: true }], + + /** + * enforce one true comma style + * @see http://eslint.org/docs/rules/comma-style + * @since 3.0.0 + * @example + * + * ```js + * // 错误 + * var foo = 1 + * , + * bar = 2; + * + * var foo = 1 + * , bar = 2; + * + * var foo = ["apples" + * , "oranges"]; + * + * function bar() { + * return { + * "a": 1 + * ,"b:": 2 + * }; + * } + * ``` + */ + 'comma-style': [ 2, 'last' ], + + /** + * allow padding inside computed properties + * @see http://eslint.org/docs/rules/computed-property-spacing + */ + 'computed-property-spacing': 0, + + /** + * not enforces consistent naming when capturing the current execution context + * @see http://eslint.org/docs/rules/consistent-this + */ + 'consistent-this': 0, + + /** + * enforce newline at the end of file, with no multiple empty lines + * @see http://eslint.org/docs/rules/eol-last + */ + 'eol-last': 2, + + /** + * not require function expressions to have a name + * @see http://eslint.org/docs/rules/func-names + */ + 'func-names': 0, + + /** + * not enforces use of function declarations or expressions + * @see http://eslint.org/docs/rules/func-style + */ + 'func-style': 0, + + /** + * Blacklist certain identifiers to prevent them being used + * @see http://eslint.org/docs/rules/id-blacklist + */ + 'id-blacklist': 0, + + /** + * not enforces minimum and maximum identifier lengths + * (variable names, property names etc.) + * @see http://eslint.org/docs/rules/id-length + */ + 'id-length': 0, + + /** + * not require identifiers to match the provided regular expression + * @see http://eslint.org/docs/rules/id-match + */ + 'id-match': 0, + + /** + * this option sets a specific tab width for your code + * @see http://eslint.org/docs/rules/indent + */ + indent: [ 2, 2, { SwitchCase: 1, VariableDeclarator: 1 }], + + /** + * enforces spacing between keys and values in object literal properties + * @see http://eslint.org/docs/rules/key-spacing + */ + 'key-spacing': [ 2, { beforeColon: false, afterColon: true }], + + /** + * require a space before & after certain keywords + * @see http://eslint.org/docs/rules/keyword-spacing + */ + 'keyword-spacing': [ 2, { + before: true, + after: true, + overrides: { + 'return': { after: true }, + 'throw': { after: true }, + 'case': { after: true }, + }, + }], + + /** + * enforces the usage of Unix line endings: \n for LF + * @see http://eslint.org/docs/rules/linebreak-style + */ + 'linebreak-style': [ 2, 'unix' ], + + /** + * not enforces empty lines around comments + * @see http://eslint.org/docs/rules/lines-around-comment + */ + 'lines-around-comment': 0, + + /** + * specify the maximum depth that blocks can be nested + * @see http://eslint.org/docs/rules/max-depth + */ + 'max-depth': 0, + + /** + * not specify the maximum length of a line in your program + * @see http://eslint.org/docs/rules/max-len + * @since 3.0.0 + */ + 'max-len': [ 2, 100, 2, { + ignoreUrls: true, + ignoreComments: false, + }], + + /** + * not specify the maximum depth callbacks can be nested + * @see http://eslint.org/docs/rules/max-nested-callbacks + */ + 'max-nested-callbacks': 0, + + /** + * limits the number of parameters that can be used in the function declaration. + * @see http://eslint.org/docs/rules/max-params + */ + 'max-params': 0, + + /** + * specify the maximum number of statement allowed in a function + * @see http://eslint.org/docs/rules/max-statements + */ + 'max-statements': 0, + + /** + * restrict the number of statements per line + * @see http://eslint.org/docs/rules/max-statements-per-line + * @since 3.0.0 + */ + 'max-statements-per-line': 0, + + /** + * not require a capital letter for constructors + * @see http://eslint.org/docs/rules/new-cap + */ + 'new-cap': 0, + + /** + * disallow the omission of parentheses when invoking a constructor with no arguments + * @see http://eslint.org/docs/rules/new-parens + */ + 'new-parens': 2, + + /** + * allow an empty newline after var statement + * @see http://eslint.org/docs/rules/newline-after-var + */ + 'newline-after-var': 0, + + /** + * @see http://eslint.org/docs/rules/newline-before-return + */ + 'newline-before-return': 0, + + /** + * enforces new line after each method call in the chain to make it + * more readable and easy to maintain + */ + 'newline-per-chained-call': [ 2, { ignoreChainWithDepth: 3 }], + + /** + * disallow use of the Array constructor + * @see http://eslint.org/docs/rules/no-array-constructor + */ + 'no-array-constructor': 2, + + /** + * disallow use of bitwise operators + * @see http://eslint.org/docs/rules/no-bitwise + */ + 'no-bitwise': 2, + + /** + * allow use of the continue statement + * @see http://eslint.org/docs/rules/no-continue + */ + 'no-continue': 0, + + /** + * allow comments inline after code + * @see http://eslint.org/docs/rules/no-inline-comments + */ + 'no-inline-comments': 0, + + /** + * allow if as the only statement in an else block + * @see http://eslint.org/docs/rules/no-lonely-if + */ + 'no-lonely-if': 0, + + /** + * disallow mixed spaces and tabs for indentation + * @see http://eslint.org/docs/rules/no-mixed-spaces-and-tabs + */ + 'no-mixed-spaces-and-tabs': [ 2, false ], + + /** + * disallow multiple empty lines and only one newline at the end + * @see http://eslint.org/docs/rules/no-multiple-empty-lines + * @since 3.0.0 + */ + 'no-multiple-empty-lines': [ 2, { max: 2, maxEOF: 1 }], + + /** + * allow negated conditions + * @see http://eslint.org/docs/rules/no-negated-condition + */ + 'no-negated-condition': 0, + + /** + * disallow negating the left operand in `in` expressions + * @see http://eslint.org/docs/rules/no-negated-in-lhs + */ + 'no-negated-in-lhs': 2, + + /** + * allow nested ternary expressions + * @see http://eslint.org/docs/rules/no-nested-ternary + */ + 'no-nested-ternary': 0, + + /** + * disallow use of the Object constructor + * @see http://eslint.org/docs/rules/no-new-object + */ + 'no-new-object': 2, + + /** + * allow use of unary operators, ++ and -- + * @see http://eslint.org/docs/rules/no-plusplus + */ + 'no-plusplus': 0, + + /** + * disallow certain syntax forms + * @see http://eslint.org/docs/rules/no-restricted-syntax + */ + 'no-restricted-syntax': [ + 2, + 'WithStatement', + ], + + /** + * disallow space between function identifier and application + * @see http://eslint.org/docs/rules/no-spaced-func + */ + 'no-spaced-func': 2, + + /** + * allow the use of ternary operators + * @see http://eslint.org/docs/rules/no-ternary + */ + 'no-ternary': 0, + + /** + * disallow trailing whitespace at the end of lines + * @see http://eslint.org/docs/rules/no-trailing-spaces + */ + 'no-trailing-spaces': 2, + + /** + * allow dangling underscores in identifiers + * @see http://eslint.org/docs/rules/no-underscore-dangle + */ + 'no-underscore-dangle': 0, + + /** + * allow the use of Boolean literals in conditional expressions + * also, prefer `a || b` over `a ? a : b` + * @see http://eslint.org/docs/rules/no-unneeded-ternary + */ + 'no-unneeded-ternary': 2, + + /** + * disallow whitespace before properties + * @see http://eslint.org/docs/rules/no-whitespace-before-property + */ + 'no-whitespace-before-property': 2, + + /** + * require padding inside curly braces + * @see http://eslint.org/docs/rules/object-curly-spacing + * @since 3.0.0 + * @example + * + * ```js + * // 错误 + * var obj = {'foo': 'bar'}; + * var obj = {'foo': 'bar' }; + * var obj = { baz: {'foo': 'qux'}, bar}; + * var obj = {baz: { 'foo': 'qux' }, bar}; + * var obj = {'foo': 'bar' + * }; + * ``` + */ + 'object-curly-spacing': [ 2, 'always' ], + + /** + * not enforce "same line" or "multiple line" on object properties. + * @see http://eslint.org/docs/rules/object-property-newline + */ + 'object-property-newline': 0, + + /** + * allow just one var statement per function + * @see http://eslint.org/docs/rules/one-var + */ + 'one-var': 0, + + /** + * require a newline around variable declaration + * @see http://eslint.org/docs/rules/one-var-declaration-per-line + * @since 3.0.0 + */ + 'one-var-declaration-per-line': [ 2, 'always' ], + + /** + * not require assignment operator shorthand where possible or prohibit it entirely + * @see http://eslint.org/docs/rules/operator-assignment + */ + 'operator-assignment': 0, + + /** + * not enforce operators to be placed before or after line breaks + * @see http://eslint.org/docs/rules/operator-linebreak + */ + 'operator-linebreak': 0, + + /** + * allow padding within blocks + * @see http://eslint.org/docs/rules/padded-blocks + */ + 'padded-blocks': 0, + + /** + * not require quotes around object literal property names + * @see http://eslint.org/docs/rules/quote-props + */ + 'quote-props': [ 'error', 'as-needed', { keywords: true }], + + /** + * specify whether double or single quotes should be used + * @see http://eslint.org/docs/rules/quotes + */ + quotes: [ 2, 'single', { avoidEscape: true }], + + /** + * do not require jsdoc + * @see http://eslint.org/docs/rules/require-jsdoc + */ + 'require-jsdoc': 0, + + /** + * disallow use of semicolons instead of ASI + * @see http://eslint.org/docs/rules/semi + */ + semi: [ 2, 'always' ], + + /** + * enforce spacing before and after semicolons + * @see http://eslint.org/docs/rules/semi-spacing + */ + 'semi-spacing': [ 2, { before: false, after: true }], + + /** + * not sort variables within the same declaration block + * @see http://eslint.org/docs/rules/sort-vars + */ + 'sort-vars': 0, + + /** + * disallow space before blocks + * @see http://eslint.org/docs/rules/space-before-blocks + */ + 'space-before-blocks': 2, + + /** + * require or disallow space before function opening parenthesis + * @see http://eslint.org/docs/rules/space-before-function-paren + */ + 'space-before-function-paren': [ 2, { + anonymous: 'never', + named: 'never', + }], + + /** + * require or disallow spaces inside parentheses + * @see http://eslint.org/docs/rules/space-in-parens + */ + 'space-in-parens': [ 2, 'never' ], + + /** + * require spaces around operators + * @see http://eslint.org/docs/rules/space-infix-ops + */ + 'space-infix-ops': 2, + + /** + * Require spaces before/after unary operators + * @see http://eslint.org/docs/rules/space-unary-ops + */ + 'space-unary-ops': [ 2, { + words: true, + nonwords: false, + }], + + /** + * require or disallow a space immediately following the // or /* in a comment + * @see http://eslint.org/docs/rules/spaced-comment + */ + 'spaced-comment': [ 2, 'always', { + exceptions: [ '-', '+' ], + markers: [ '*!' ], + }], + + /** + * not require regex literals to be wrapped in parentheses + * @see http://eslint.org/docs/rules/wrap-regex + */ + 'wrap-regex': 0, + }, +}; diff --git a/rules/variables.js b/rules/variables.js new file mode 100644 index 0000000..03a4637 --- /dev/null +++ b/rules/variables.js @@ -0,0 +1,80 @@ +'use strict'; + +module.exports = { + rules: { + /** + * 不对变量赋值的时机进行要求 + * @see http://eslint.org/docs/rules/init-declarations + */ + 'init-declarations': 0, + + /** + * allow the catch clause parameter name being the same as a variable in the outer scope + * @see http://eslint.org/docs/rules/no-catch-shadow + * @since 3.0.0 + */ + 'no-catch-shadow': 0, + + /** + * disallow deletion of variables + * @see http://eslint.org/docs/rules/no-delete-var + */ + 'no-delete-var': 2, + + /** + * disallow labels that share a name with a variable + * @see http://eslint.org/docs/rules/no-label-var + */ + 'no-label-var': 2, + + /** + * disallow specific globals + * @see http://eslint.org/docs/rules/no-restricted-globals + * @since 3.0.0 + */ + 'no-restricted-globals': 0, + + /** + * allow declaration of variables already declared in the outer scope + * @see http://eslint.org/docs/rules/no-shadow + */ + 'no-shadow': 0, + + /** + * disallow shadowing of names such as arguments + * @see http://eslint.org/docs/rules/no-shadow-restricted-names + */ + 'no-shadow-restricted-names': 2, + + /** + * disallow use of undeclared variables unless mentioned in a `global` block + * @see http://eslint.org/docs/rules/no-undef + */ + 'no-undef': 2, + + /** + * disallow use of undefined when initializing variables + * @see http://eslint.org/docs/rules/no-undef-init + */ + 'no-undef-init': 2, + + /** + * disallow use of undefined variable + * @see http://eslint.org/docs/rules/no-undefined + */ + 'no-undefined': 0, + + /** + * disallow declaration of variables that are not used in the code + * @see http://eslint.org/docs/rules/no-unused-vars + * @since 3.0.0 + */ + 'no-unused-vars': [ 2, { vars: 'local', args: 'after-used' }], + + /** + * disallow use of variables before they are defined + * @see http://eslint.org/docs/rules/no-use-before-define + */ + 'no-use-before-define': [ 2, 'nofunc' ], + }, +};