├── .gitignore ├── .eslintignore ├── es6.js ├── index.js ├── lib ├── es3-rules.js ├── es5-rules.js ├── es2015-rules.js └── common-rules.js ├── examples ├── bad │ ├── extra-characters.js │ ├── debug.js │ ├── commonjs.js │ ├── es3.js │ ├── js-oddities.js │ ├── vars.js │ ├── es5.js │ ├── duplicates.js │ ├── danger.js │ ├── overwrite.js │ ├── regex.js │ ├── shadow-vars.js │ ├── outdated.js │ ├── es2015.js │ ├── not-optimal.js │ └── typos.js └── good │ └── jsdoc.js ├── .eslintrc.yml ├── .travis.yml ├── es3.js ├── es5.js ├── .editorconfig ├── es2015.js ├── package.json ├── LICENSE ├── README.md └── CHANGELOG.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | examples/** 2 | -------------------------------------------------------------------------------- /es6.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('./es2015'); 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = require('./es2015'); 4 | -------------------------------------------------------------------------------- /lib/es3-rules.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | 'comma-dangle': ['error', 'never'] 5 | }; 6 | -------------------------------------------------------------------------------- /examples/bad/extra-characters.js: -------------------------------------------------------------------------------- 1 | /*eslint no-extra-semi: "warn"*/ 2 | var x = 5;; // The second semicolon is unnecessary. 3 | -------------------------------------------------------------------------------- /lib/es5-rules.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | 'getter-return': ['error'], 5 | 'accessor-pairs': ['error'] 6 | }; 7 | -------------------------------------------------------------------------------- /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | parserOptions: 2 | ecmaVersion: 6 3 | 4 | env: 5 | node: true 6 | 7 | extends: ./index.js 8 | 9 | rules: 10 | strict: error 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | branches: 4 | only: 5 | - master 6 | 7 | language: node_js 8 | 9 | node_js: 10 | - 4 11 | - 6 12 | - 8 13 | - 10 14 | -------------------------------------------------------------------------------- /es3.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const commonRules = require('./lib/common-rules'); 4 | const es3Rules = require('./lib/es3-rules'); 5 | 6 | module.exports = { 7 | rules: Object.assign({}, commonRules, es3Rules) 8 | }; 9 | -------------------------------------------------------------------------------- /es5.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const commonRules = require('./lib/common-rules'); 4 | const es5Rules = require('./lib/es5-rules'); 5 | 6 | module.exports = { 7 | rules: Object.assign({}, commonRules, es5Rules) 8 | }; 9 | -------------------------------------------------------------------------------- /examples/bad/debug.js: -------------------------------------------------------------------------------- 1 | /*eslint no-debugger: "error"*/ 2 | debugger; // Production code should definitely not contain debugger, 3 | // as it will cause the browser to stop executing code and open an appropriate debugger. 4 | -------------------------------------------------------------------------------- /examples/bad/commonjs.js: -------------------------------------------------------------------------------- 1 | /*eslint no-new-require: "error"*/ 2 | var instance = new require('class'); // The `instance` variable will be equal to constructor function 3 | // instead of expected instance of class. 4 | -------------------------------------------------------------------------------- /examples/bad/es3.js: -------------------------------------------------------------------------------- 1 | /*eslint comma-dangle: ["error", "never"]*/ 2 | var obj = { 3 | bar: 'baz', 4 | qux: 'quux', // IE8 (when not in IE8 document mode) and below will throw an error when 5 | // it encounters trailing commas in JavaScript. 6 | }; 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | trim_trailing_whitespace = true 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | 10 | [*.{json,*rc,yml}] 11 | indent_size = 2 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /es2015.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const commonRules = require('./lib/common-rules'); 4 | const es5Rules = require('./lib/es5-rules'); 5 | const es2015Rules = require('./lib/es2015-rules'); 6 | 7 | module.exports = { 8 | rules: Object.assign({}, commonRules, es5Rules, es2015Rules) 9 | }; 10 | -------------------------------------------------------------------------------- /examples/bad/js-oddities.js: -------------------------------------------------------------------------------- 1 | /*eslint use-isnan: "error"*/ 2 | if (foo == NaN) { // NaN has the unique property of not being equal to anything, including itself. 3 | // ... 4 | } 5 | 6 | /*eslint no-obj-calls: "error"*/ 7 | var json = new JSON(); // JSON look as if it could be constructors due their capitalization, 8 | // but actually this is namespace. 9 | -------------------------------------------------------------------------------- /examples/good/jsdoc.js: -------------------------------------------------------------------------------- 1 | /*eslint valid-jsdoc: [2, { requireReturn: false, requireReturnDescription: false }]*/ 2 | 3 | /** 4 | * Evals file contents. 5 | * 6 | * @param {string} file The filename to eval. 7 | * @param {Object} options The eval options. 8 | * @param {Function} callback 9 | * @returns {Object} 10 | */ 11 | function fileEval(file, options, callback) { 12 | /* ... */ 13 | } 14 | -------------------------------------------------------------------------------- /examples/bad/vars.js: -------------------------------------------------------------------------------- 1 | /*eslint no-undef: 2*/ 2 | b = 10; // 'b' is not defined 3 | 4 | /*eslint no-unused-vars: "error"*/ 5 | var x = 10; // "x" is defined but never used 6 | 7 | (function(foo, bar, baz) { // "baz" is defined but never used 8 | return bar; 9 | })(); 10 | 11 | /*eslint no-use-before-define: "error"*/ 12 | console.log(a); 13 | var a = 10; 14 | 15 | new A(); 16 | class A { 17 | } 18 | -------------------------------------------------------------------------------- /examples/bad/es5.js: -------------------------------------------------------------------------------- 1 | /*eslint getter-return: "error"*/ 2 | Object.defineProperty(p, "age", { 3 | get: function (){ 4 | // no returns. 5 | } 6 | }); 7 | 8 | /*eslint accessor-pairs: "error"*/ 9 | Object.defineProperty(p, "age", { 10 | // Without a getter, you cannot read the property, so it ends up not being used. 11 | set: function (val) { 12 | this.val = val; 13 | } 14 | }); 15 | -------------------------------------------------------------------------------- /examples/bad/duplicates.js: -------------------------------------------------------------------------------- 1 | /*eslint no-dupe-args: "error"*/ 2 | function foo(a, b, a) { 3 | // Outside of strict mode duplicate arguments will mask the value of the first argument. 4 | console.log('which a is it?', a); 5 | } 6 | 7 | /*eslint no-dupe-keys: "error"*/ 8 | var foo = { 9 | bar: 'baz', 10 | bar: 'qux' // Duplicate key with other value. 11 | }; 12 | 13 | /*eslint no-duplicate-case: "error"*/ 14 | var one = 1; 15 | 16 | switch (one) { 17 | case 1: break; 18 | case 1: break; // Duplicate case label. 19 | default: break; 20 | } 21 | -------------------------------------------------------------------------------- /examples/bad/danger.js: -------------------------------------------------------------------------------- 1 | /*eslint no-extend-native: "error"*/ 2 | Object.prototype.extra = 55; 3 | 4 | /*eslint no-global-assign: "error"*/ 5 | window = {}; 6 | 7 | /*eslint no-octal: "error"*/ 8 | // The leading zero to identify an octal literal has been a source of confusion and error in JavaScript. 9 | var num = 071; // 57 10 | 11 | /*eslint no-with: "error"*/ 12 | with (foo) { 13 | // The with statement is potentially problematic because it adds members of an object to the current scope, 14 | // making it impossible to tell what a variable inside the block actually refers to. 15 | } 16 | -------------------------------------------------------------------------------- /examples/bad/overwrite.js: -------------------------------------------------------------------------------- 1 | /*eslint no-func-assign: "error"*/ 2 | function foo() {} 3 | foo = bar; 4 | 5 | /*eslint no-ex-assign: "error"*/ 6 | try { 7 | // code 8 | } catch (e) { 9 | e = 10; // Overwrite the reference to the error. 10 | } 11 | 12 | /*eslint no-unsafe-finally: "error"*/ 13 | (() => { 14 | try { 15 | return 1; // 1 is returned but suspended until finally block ends 16 | } catch(err) { 17 | return 2; 18 | } finally { 19 | return 3; // 3 is returned before 1, which we did not expect 20 | } 21 | })(); // We expect this function to return 1, but result is 3. 22 | -------------------------------------------------------------------------------- /lib/es2015-rules.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | /* ECMAScript 2015 ===================================================================== */ 5 | /* http://eslint.org/docs/rules/#ecmascript-6 6 | /* ===================================================================================== */ 7 | 'constructor-super': 'error', 8 | 'no-this-before-super': 'error', 9 | 'no-dupe-class-members': 'error', 10 | 'no-class-assign': 'error', 11 | 'no-const-assign': 'error', 12 | 'no-new-symbol': 'error', 13 | 'require-yield': 'error', 14 | 'class-methods-use-this': ['error', { 15 | "exceptMethods": ['toLocaleString', 'toSource', 'toString', 'valueOf'] 16 | }], 17 | 'no-useless-computed-key': 'error' 18 | }; 19 | -------------------------------------------------------------------------------- /examples/bad/regex.js: -------------------------------------------------------------------------------- 1 | /*eslint no-control-regex: "error"*/ 2 | var pattern1 = /\\x1f/; // These characters are rarely used in JavaScript strings so a regular expression 3 | // containing these characters is most likely a mistake. 4 | 5 | /*eslint no-regex-spaces: "error"*/ 6 | var pattern2 = /foo bar/; // In this regular expression, 7 | // it's very hard to tell how many spaces are intended to be matched. 8 | 9 | /*eslint no-empty-character-class: "error"*/ 10 | var pattern3 = /^abc[]/; // Empty character classes in regular expressions do not match anything 11 | // and can result in code that may not work as intended. 12 | 13 | /*eslint no-invalid-regexp: ["error", {"allowConstructorFlags": ["u", "y"]}]*/ 14 | var pattern4 = new RegExp('\\'); 15 | 16 | /*eslint no-useless-escape: "error"*/ 17 | "\'"; 18 | -------------------------------------------------------------------------------- /examples/bad/shadow-vars.js: -------------------------------------------------------------------------------- 1 | /*eslint no-shadow: "error"*/ 2 | var a = 3; 3 | function b() { 4 | var a = 10; 5 | } 6 | 7 | /*eslint no-catch-shadow: "error"*/ 8 | var err = 'x'; 9 | 10 | try { 11 | throw 'problem'; 12 | } catch (err) { 13 | 14 | } 15 | 16 | console.log(err) // err is 'problem', not 'x' 17 | 18 | /*eslint no-shadow-restricted-names: "error"*/ 19 | function NaN() {} 20 | 21 | /*eslint no-case-declarations: "error"*/ 22 | switch (foo) { 23 | case 1: 24 | let x = 1; 25 | break; 26 | default: 27 | break; 28 | } 29 | // The `x` variable is available here. 30 | 31 | /*eslint no-empty-pattern: "error"*/ 32 | var { a: {} } = foo; // doesn't create any variables 33 | 34 | /*eslint block-scoped-var: "error"*/ 35 | 36 | function doTryCatch() { 37 | try { 38 | var build = 1; 39 | } catch (e) { 40 | var f = build; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eslint-config-pedant", 3 | "version": "1.0.1", 4 | "description": "Pedant preset for eslint", 5 | "license": "MIT", 6 | "repository": "blond/eslint-config-pedant", 7 | "author": "Andrew Abramov (github.com/blond)", 8 | "keywords": [ 9 | "eslint", 10 | "config", 11 | "preset", 12 | "pedant", 13 | "errors", 14 | "typos", 15 | "variables", 16 | "commonjs", 17 | "best", 18 | "practices", 19 | "es2015", 20 | "es6", 21 | "es5", 22 | "es3", 23 | "js", 24 | "lint" 25 | ], 26 | "main": "index.js", 27 | "files": [ 28 | "lib/**", 29 | "index.js", 30 | "es3.js", 31 | "es5.js", 32 | "es6.js", 33 | "es2015.js" 34 | ], 35 | "engines": { 36 | "node": ">= 4" 37 | }, 38 | "peerDependencies": { 39 | "eslint": ">= 4.2.0 < 6.0.0" 40 | }, 41 | "dependencies": {}, 42 | "devDependencies": { 43 | "eslint": ">= 4.2.0 < 5.0.0" 44 | }, 45 | "scripts": { 46 | "test": "eslint ." 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/bad/outdated.js: -------------------------------------------------------------------------------- 1 | /*eslint no-caller: "error"*/ 2 | function foo(n) { 3 | if (n <= 0) { 4 | return; 5 | } 6 | 7 | // The use of `arguments.caller` and `arguments.callee` make several code optimizations impossible. 8 | // They have been deprecated in future versions of JavaScript 9 | // and their use is forbidden in ECMAScript 5 while in strict mode. 10 | arguments.callee(n - 1); 11 | } 12 | 13 | /*eslint no-iterator: "error"*/ 14 | Foo.prototype.__iterator__ = function() { // You should use ECMAScript 6 iterators and generators instead. 15 | return new FooIterator(this); 16 | }; 17 | 18 | /*eslint no-proto: 2*/ 19 | var a = obj.__proto__; // Use `getPrototypeOf` method instead. 20 | 21 | 22 | /*eslint no-octal-escape: "error"*/ 23 | var foo = "Copyright \251"; // It is recommended that Unicode escapes be used instead. 24 | 25 | /*eslint no-labels: "error"*/ 26 | label: 27 | while(true) { 28 | // labels tend to be used only rarely and are frowned upon by some as a remedial form of flow control 29 | // that is more error prone and harder to understand. 30 | break label; 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Andrew Abramov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/bad/es2015.js: -------------------------------------------------------------------------------- 1 | /*eslint constructor-super: "error"*/ 2 | class A extends B { 3 | constructor() { 4 | // Constructors of derived classes must call super(). 5 | } 6 | } 7 | 8 | /*eslint no-this-before-super: "error"*/ 9 | class A extends B { 10 | constructor() { 11 | this.a = 0; // In the constructor of derived classes, 12 | // if this are used before super() calls, it raises a reference error. 13 | super(); 14 | } 15 | } 16 | 17 | /*eslint no-dupe-class-members: "error"*/ 18 | class Foo { 19 | bar() { } 20 | bar() { } // Duplicate names in class members. 21 | } 22 | 23 | /*eslint no-class-assign: "error"*/ 24 | class C { } // Creates the `A` variable. 25 | C = 0; // Modify the `A` variable. But the modification is a mistake in most cases. 26 | 27 | /*eslint no-const-assign: "error"*/ 28 | const a = 0; 29 | a += 1; // We cannot modify variables that are declared using const keyword. 30 | // It will raise a runtime error. 31 | 32 | /*eslint no-new-symbol: "error"*/ 33 | var foo = new Symbol('foo'); // The Symbol constructor is not intended to be used with the new operator, 34 | // but to be called as a function. 35 | 36 | /*eslint require-yield: "error"*/ 37 | function* foo() { 38 | return 10; // This generator functions that do not have the `yield` keyword. 39 | } 40 | 41 | /*eslint class-methods-use-this: "error"*/ 42 | class A { 43 | constructor() { 44 | this.a = "hi"; 45 | } 46 | 47 | sayHi() { 48 | console.log("hi"); // The sayHi method doesn’t use this, so we can make it a static method. 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/bad/not-optimal.js: -------------------------------------------------------------------------------- 1 | /*eslint no-eval: "error"*/ 2 | var obj = { x: "foo" }, 3 | key = "x", 4 | value = eval("obj." + key); 5 | 6 | /*eslint no-implied-eval: "error"*/ 7 | setTimeout("alert('Hi!');", 100); 8 | 9 | /*eslint no-new-func: "error"*/ 10 | var x = new Function("a", "b", "return a + b"); 11 | 12 | /*eslint no-self-assign: "error"*/ 13 | foo = foo; 14 | 15 | /*eslint no-unused-expressions: ["error", {"allowShortCircuit": true, "allowTernary": true}]*/ 16 | n + 1; // This is a valid JavaScript expression, 17 | // but isn’t actually used. 18 | 19 | /*eslint no-inner-declarations: "error"*/ 20 | for (var i = 0; i < 10; ++i) { 21 | // This feature will be announced 10 times. 22 | function doSomethingElse () { 23 | // ... 24 | } 25 | } 26 | 27 | /*eslint no-loop-func: "error"*/ 28 | for (var i=10; i; i--) { 29 | var a = function() { return i; }; 30 | a(); 31 | } 32 | 33 | /*eslint no-constant-condition: "error"*/ 34 | if (false) { 35 | // This function is never executed. 36 | doSomething(); 37 | } 38 | 39 | /*eslint no-unreachable: "error"*/ 40 | function fn() { 41 | var x = 1; 42 | 43 | return x; 44 | x = 3; // This will never execute. 45 | } 46 | 47 | /*eslint no-empty: "error"*/ 48 | if (foo) {} // Empty block statements, while not technically errors, but they can cause confusion when reading code. 49 | 50 | /*eslint no-extra-boolean-cast: "error"*/ 51 | var truth = true; 52 | 53 | if (!!truth) { // This variable already coerced to a Boolean. 54 | // ... 55 | } 56 | 57 | /*eslint no-useless-computed-key: "error"*/ 58 | var a = { ['0']: 0 }; // It’s unnecessary to use computed properties with literals such as. 59 | -------------------------------------------------------------------------------- /examples/bad/typos.js: -------------------------------------------------------------------------------- 1 | /*eslint no-cond-assign: "error"*/ 2 | if (user.jobTitle = 'manager') { 3 | // user.jobTitle is now incorrect 4 | } 5 | 6 | /*eslint valid-typeof: "error"*/ 7 | typeof foo === 'fucntion' // The typo in the 'function' word. 8 | 9 | /*eslint no-self-compare: "error"*/ 10 | if (x === x) { 11 | x = 20; 12 | } 13 | 14 | /*eslint no-sparse-arrays: "error"*/ 15 | var colors = ['red',, 'blue']; // extra comma 16 | 17 | /*eslint array-callback-return: "error"*/ 18 | [1, 2, 3].map(function(value) { 19 | value + 1; // forget to write `return` 20 | }); // [undefined, undefined, undefined] 21 | 22 | /*eslint curly: "error"*/ 23 | if (foo) foo++; bar++; // forget to wrap `bar++` 24 | 25 | /*eslint no-redeclare: "error"*/ 26 | var a = 3; 27 | var a = 10; 28 | 29 | /*eslint no-new: "error"*/ 30 | new Person(); 31 | 32 | /*eslint no-return-assign: "error"*/ 33 | function doSomething() { 34 | return foo = bar + 2; // The true intent was to do a comparison (`==` or `===`). 35 | } 36 | 37 | /*eslint no-throw-literal: "error"*/ 38 | throw "error"; 39 | 40 | /*eslint no-unexpected-multiline: "error"*/ 41 | var bar = 'bar' 42 | var foo = bar // This entry is equivalent to `var foo = bar(1 || 2).toString()`. 43 | (1 || 2).toString(); 44 | 45 | /*eslint no-unsafe-negation: "error"*/ 46 | if (!key in object) { 47 | // Operator precedence makes it equivalent to (!key) in object 48 | // and type conversion makes it equivalent to (key ? "false" : "true") in object. 49 | } 50 | 51 | if (!obj instanceof Ctor) { 52 | // Operator precedence makes it equivalent to (!obj) instanceof Ctor 53 | // and it equivalent to always false since boolean values are not objects. 54 | } 55 | 56 | /*eslint no-extra-bind: "error"*/ 57 | var x = function () { 58 | return 'bla'; 59 | }.bind(bar); // useless bind, can be safely removed 60 | -------------------------------------------------------------------------------- /lib/common-rules.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | /* Possible Errors ===================================================================== */ 5 | /* https://github.com/eslint/eslint/tree/master/docs/rules#possible-errors */ 6 | /* ===================================================================================== */ 7 | 8 | // Duplicates 9 | 'no-dupe-args': 'error', 10 | 'no-dupe-keys': 'error', 11 | 'no-duplicate-case': 'error', 12 | 13 | // Typos 14 | 'valid-typeof': 'error', 15 | 'no-sparse-arrays': 'error', 16 | 'no-unexpected-multiline': 'error', 17 | 'no-cond-assign': ['error', 'except-parens'], 18 | 'no-unsafe-negation': 'error', 19 | 'no-extra-bind': 'error', 20 | 21 | // Overwrite 22 | 'no-ex-assign': 'error', 23 | 'no-func-assign': 'error', 24 | 'no-unsafe-finally': 'error', 25 | 26 | // JS Oddities 27 | 'use-isnan': 'error', 28 | 'no-obj-calls': 'error', 29 | 30 | // Debug 31 | 'no-debugger': 'error', 32 | 33 | // Regex 34 | 'no-control-regex': 'error', 35 | 'no-regex-spaces': 'error', 36 | 'no-empty-character-class': 'error', 37 | 'no-invalid-regexp': ['error', { allowConstructorFlags: ['u', 'y'] }], 38 | 'no-useless-escape': 'error', 39 | 40 | // Not optimal 41 | 'no-empty': 'error', 42 | 'no-inner-declarations': 'error', 43 | 'no-constant-condition': 'error', 44 | 'no-unreachable': 'error', 45 | 'no-extra-boolean-cast': 'error', 46 | 47 | // Extra Characters 48 | 'no-extra-semi': 'error', 49 | 50 | // JSDoc 51 | 'valid-jsdoc': ['error', { 52 | requireReturn: false, 53 | requireReturnDescription: false, 54 | requireParamDescription: false 55 | }], 56 | 57 | // Whitespaces 58 | 'no-irregular-whitespace': ['error', { skipComments: true }], 59 | 60 | /* Variables =========================================================================== */ 61 | /* http://eslint.org/docs/rules/#variables */ 62 | /* ===================================================================================== */ 63 | 64 | // Unused & undeclared variables 65 | 'no-unused-vars': ['error', { args: 'after-used' }], 66 | 'no-undef': 'error', 67 | 'no-use-before-define': ['error', { 68 | functions: false, 69 | classes: true 70 | }], 71 | 72 | // Shadow variables 73 | 'no-catch-shadow': 'error', 74 | 'no-shadow': 'error', 75 | 'no-shadow-restricted-names': 'error', 76 | 77 | /* Node.js and CommonJS ================================================================ */ 78 | /* http://eslint.org/docs/rules/#nodejs-and-commonjs 79 | /* ===================================================================================== */ 80 | 81 | 'no-new-require': 'error', 82 | 83 | /* Best Practices ====================================================================== */ 84 | /* http://eslint.org/docs/rules/#best-practices */ 85 | /* ===================================================================================== */ 86 | 87 | // Danger 88 | 'no-extend-native': 'error', 89 | 'no-global-assign': 'error', 90 | 'no-octal': 'error', 91 | 'no-with': 'error', 92 | 93 | // Outdated 94 | 'no-caller': 'error', 95 | 'no-iterator': 'error', 96 | 'no-proto': 'error', 97 | 'no-octal-escape': 'error', 98 | 'no-labels': 'error', 99 | 'no-unused-labels': 'error', 100 | 101 | // Shadow vars 102 | 'no-case-declarations': 'error', 103 | 'no-empty-pattern': 'error', 104 | 'block-scoped-var': 'error', 105 | 106 | // Typos 107 | 'no-self-compare': 'error', 108 | 'array-callback-return': 'error', 109 | 'curly': 'error', 110 | 'no-new': 'error', 111 | 'no-return-assign': 'error', 112 | 'no-throw-literal': 'error', 113 | 'no-redeclare': 'error', 114 | 115 | // Not Optimal 116 | 'no-eval': 'error', 117 | 'no-implied-eval': 'error', 118 | 'no-self-assign': 'error', 119 | 'no-unused-expressions': ['error', { allowShortCircuit: true, allowTernary: true }], 120 | 'no-loop-func': 'error', 121 | 'no-new-func': 'error' 122 | }; 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | eslint-config-pedant 2 | ==================== 3 | 4 | An ESLint [Shareable Config](http://eslint.org/docs/developer-guide/shareable-configs) to find errors, typos and potentially dangerous code. 5 | 6 | [![NPM Status][npm-img]][npm] 7 | [![Travis Status][test-img]][travis] 8 | 9 | [npm]: https://www.npmjs.org/package/eslint-config-pedant 10 | [npm-img]: https://img.shields.io/npm/v/eslint-config-pedant.svg 11 | 12 | [travis]: https://travis-ci.org/blond/eslint-config-pedant 13 | [test-img]: https://img.shields.io/travis/blond/eslint-config-pedant/master.svg?label=tests 14 | 15 | ![pedant](https://cloud.githubusercontent.com/assets/2225579/13544540/31939a3a-e288-11e5-8fd2-f6a86190e037.jpg) 16 | 17 | Table of Contents 18 | ----------------- 19 | 20 | * [Install](#install) 21 | * [Usage](#usage) 22 | * [Presets](#presets) 23 | * [FAQ](#faq) 24 | * [Semantic Versioning Policy](#semantic-versioning-policy) 25 | 26 | Install 27 | ------- 28 | 29 | You'll first need to install ESLint: 30 | 31 | ``` 32 | $ npm install eslint --save-dev 33 | ``` 34 | 35 | **Note**: You may install ESLint globally using the `-g` flag. 36 | 37 | Next, install `eslint-config-pedant`: 38 | 39 | ``` 40 | $ npm install eslint-config-pedant --save-dev 41 | ``` 42 | 43 | **Note**: If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-config-pedant` globally. 44 | 45 | A globally-installed instance of ESLint can only use globally-installed ESLint plugins. A locally-installed ESLint can make use of both locally- and globally- installed ESLint plugins. 46 | 47 | Usage 48 | ----- 49 | 50 | Shareable configs are designed to work with the `extends` feature of `.eslintrc` files. You can learn more about [Shareable Config](http://eslint.org/docs/developer-guide/shareable-configs) on the official ESLint website. 51 | 52 | Add this to your `.eslintrc.json` file: 53 | 54 | ```json 55 | { 56 | "extends": "pedant" 57 | } 58 | ``` 59 | 60 | **Note**: We omitted the `eslint-config-` prefix since it is automatically assumed by ESLint. 61 | 62 | You can override settings from the shareable config by adding them directly into your `.eslintrc.json` file. 63 | 64 | Presets 65 | ------- 66 | 67 | ### ECMAScript 68 | 69 | By default rules are suitable for `ECMAScript 2015` or higher. 70 | 71 | For `ECMAScript 2015` or higher, your config file should look like this: 72 | ```json 73 | { 74 | "extends": "pedant", 75 | "parserOptions": { 76 | "ecmaVersion": 6 77 | } 78 | } 79 | ``` 80 | 81 | If you are not using `ECMAScript 2015`, you can choose the config for `ECMAScript 5`: 82 | 83 | ```json 84 | { 85 | "extends": "pedant/es5" 86 | } 87 | ``` 88 | 89 | Or config for `ECMAScript 3`: 90 | 91 | ```json 92 | { 93 | "extends": "pedant/es3" 94 | } 95 | ``` 96 | 97 | FAQ 98 | --- 99 | 100 | * [Whether this config is suitable for me?](#whether-this-config-is-suitable-for-me) 101 | * [Why this config does not contain stylistic rules?](#why-this-config-does-not-contain-stylistic-rules) 102 | 103 | ### Whether this config is suitable for me? 104 | 105 | Most likely this config will suite you, because it contains only those rules which are necessary to find errors, typos and potentially dangerous code. 106 | 107 | To make sure that this config is right for you: 108 | 109 | * Look at the [examples](./examples/bad/) of **incorrect** code. 110 | * Look at the [rules](./index.js) from this config. The detailed information about each rule you can find on the [eslint](http://eslint.org/docs/rules/) website. 111 | * Try this config in your project. If you agree with those errors then this config is for you. 112 | 113 | ### Why this config does not contain stylistic rules? 114 | 115 | This config intentionally does not limit your choice of code style. 116 | 117 | If you want to check code style of your code you can add [stylistic rules](http://eslint.org/docs/rules/#stylistic-issues) to your config in your project. 118 | 119 | Also, you can create your own [Shareable Config](http://eslint.org/docs/developer-guide/shareable-configs) or use one of the existing. 120 | 121 | Semantic Versioning Policy 122 | -------------------------- 123 | 124 | The `eslint-config-pedant` follows [semantic versioning](semver) and [ESLint's Semantic Versioning Policy](eslint-semver). 125 | 126 | [semver]: http://semver.org 127 | [eslint-semver]: https://github.com/eslint/eslint#semantic-versioning-policy 128 | 129 | However, due to the nature of ESLint, it's not always clear when a minor or major version bump occurs. To help clarify this for everyone, ESLint defined the following semantic versioning policy: 130 | 131 | * Patch release (intended to not break your lint build) 132 | * A bug fix in a rule options that results in ESLint reporting fewer errors. 133 | * Improvements to documentation. 134 | * Non-user-facing changes such as refactoring code, modifying tests, and increasing examples coverage. 135 | * Re-releasing after a failed release (i.e., publishing a release that doesn't work for anyone). 136 | * An existing rule is replaced (if rule is deprecated) that results in ESLint reporting fewer errors. 137 | * Minor release (might break your lint build) 138 | * A bug fix in a rule options that results in ESLint reporting more errors. 139 | * An existing rule is replaced (if rule is deprecated) that results in ESLint reporting more errors. 140 | * A new rule is added that does not result in ESLint reporting more errors by default. 141 | * A new option to an existing rule is added that does not result in ESLint reporting more errors by default. 142 | * New capabilities to the public API are added (new presets, etc.). 143 | * Major release (likely to break your lint build) 144 | * A new rule is added that results in ESLint reporting more errors by default. 145 | * A new option to an existing rule is added that results in ESLint reporting more errors by default. 146 | * An existing rule is removed (if rule is not deprecated). 147 | * Part of the public API is removed or changed in an incompatible way (removed presets, etc.). 148 | 149 | According to our policy, any minor update may report more errors than the previous release (ex: from a bug fix). As such, we recommend using the tilde (`~`) in `package.json` e.g. `"eslint-config-pedant": "~1.0.0"` to guarantee the results of your builds. 150 | 151 | License 152 | ------- 153 | 154 | MIT © [Andrew Abramov](https://github.com/blond) 155 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | v1.0.0 (2017-11-02) 5 | ------------------- 6 | 7 | ### Dependencies 8 | 9 | * Requires an ESLint of at least `v4.2.0` (@blond [#67]). 10 | * Droped support for ESLint v3 (@blond [#67]). 11 | 12 | [#67]: https://github.com/blond/eslint-config-pedant/pull/67 13 | 14 | ### Common Rules 15 | 16 | * Added the [block-scoped-var] rule (@blond [#63]). 17 | 18 | [block-scoped-var]: http://eslint.org/docs/rules/block-scoped-var 19 | 20 | [#63]: https://github.com/blond/eslint-config-pedant/pull/63 21 | 22 | ### ES5 & ES2015 Rules 23 | 24 | * Added the [getter-return] rule to `es5` and `es2015` presets (@blond [#64]). 25 | * Added the [accessor-pairs] rule to `es5` and `es2015` presets (@blond [#66]). 26 | 27 | [getter-return]: http://eslint.org/docs/rules/getter-return 28 | [accessor-pairs]: http://eslint.org/docs/rules/accessor-pairs 29 | 30 | [#64]: https://github.com/blond/eslint-config-pedant/pull/64 31 | [#66]: https://github.com/blond/eslint-config-pedant/pull/66 32 | 33 | ### Bug Fixes 34 | 35 | * Fixed [class-methods-use-this] rule: should ignore base object methods (@blond [#62]). 36 | 37 | [class-methods-use-this]: http://eslint.org/docs/rules/class-methods-use-this 38 | 39 | [#62]: https://github.com/blond/eslint-config-pedant/pull/62 40 | 41 | ### Documentation 42 | 43 | * Updated preset section for `es2015` (@jt3k [#60]). 44 | 45 | [#60]: https://github.com/blond/eslint-config-pedant/pull/60 46 | 47 | v0.10.0 (2017-07-02) 48 | ------------------- 49 | 50 | * Supported ESLint 4 (@blond [#55]). 51 | 52 | v0.9.0 (2017-04-22) 53 | ------------------- 54 | 55 | ### Common Rules 56 | 57 | * Added the [no-extra-bind] rule (@blond [#46]). 58 | * Added the [no-useless-escape] rule (@blond [#49]). 59 | 60 | [no-extra-bind]: http://eslint.org/docs/rules/no-extra-bind 61 | [no-useless-escape]: http://eslint.org/docs/rules/no-useless-escape 62 | 63 | [#46]: https://github.com/blond/eslint-config-pedant/pull/46 64 | [#49]: https://github.com/blond/eslint-config-pedant/pull/49 65 | 66 | ### ES2015 Rules 67 | 68 | * Added the [class-methods-use-this] rule to `es2015` preset (@blond [#47]). 69 | * Added the [no-useless-computed-key] rule to `es2015` preset (@blond [#48]). 70 | 71 | [class-methods-use-this]: http://eslint.org/docs/rules/class-methods-use-this 72 | [no-useless-computed-key]: http://eslint.org/docs/rules/no-useless-computed-key 73 | 74 | [#47]: https://github.com/blond/eslint-config-pedant/pull/47 75 | [#48]: https://github.com/blond/eslint-config-pedant/pull/48 76 | 77 | ### Other 78 | 79 | * Renamed the `es6` preset to `es2015` (@blond [#50]). 80 | 81 | [#50]: https://github.com/blond/eslint-config-pedant/pull/50 82 | 83 | v0.8.1 (2017-04-09) 84 | ------------------- 85 | 86 | ### Rules 87 | 88 | * Removed deprecated rules: [no-native-reassign] and [no-negated-in-lhs] (@blond [#41]) 89 | * Turned off `requireParamDescription` option in [valid-jsdoc] rule (@blond [#42]) 90 | 91 | [no-native-reassign]: http://eslint.org/docs/rules/no-native-reassign 92 | [no-negated-in-lhs]: http://eslint.org/docs/rules/no-negated-in-lhs 93 | [valid-jsdoc]: http://eslint.org/docs/rules/valid-jsdoc 94 | 95 | [#41]: https://github.com/blond/eslint-config-pedant/pull/41 96 | [#42]: https://github.com/blond/eslint-config-pedant/pull/42 97 | 98 | ### Documentation 99 | 100 | * Added [Semantic Versioning Policy] (@blond [#44]) 101 | 102 | [#44]: https://github.com/blond/eslint-config-pedant/pull/44 103 | 104 | [Semantic Versioning Policy]: README.md#semantic-versioning-policy 105 | 106 | v0.8.0 (2016-09-03) 107 | ------------------- 108 | 109 | ### Rules 110 | 111 | * Added [no-unsafe-negation](http://eslint.org/docs/rules/no-unsafe-negation) rule (@blond [#31]). 112 | 113 | [#31]: https://github.com/blond/eslint-config-pedant/pull/31 114 | 115 | ### Dependencies 116 | 117 | * Requires an `eslint` of at least `v3.3.0`. 118 | 119 | v0.7.0 (2016-07-08) 120 | ------------------- 121 | 122 | ### Support Node.js 123 | 124 | * Drop support for Node.js < 4. (ESLint dropped support in `v3.0.0`). 125 | 126 | ### Commits 127 | 128 | - [[`a7917f2`](https://github.com/blond/eslint-config-pedant/commit/a7917f2)] - chore(travis): run tests in Node.js 6 (@blond) 129 | - [[`7ded85c`](https://github.com/blond/eslint-config-pedant/commit/7ded85c)] - chore(node): drop support for Node.js < 4 (@blond) 130 | 131 | v0.6.0 (2016-06-02) 132 | ------------------- 133 | 134 | ### Dependencies 135 | 136 | * `eslint` updated to `3.0.0` 137 | * `es6-object-assign` updated to `1.0.2` 138 | 139 | ### Commits 140 | 141 | - [[`306e379`](https://github.com/blond/eslint-config-pedant/commit/306e379)] - Update eslint to ^3.0.0 (@tadatuta) 142 | - [[`be5884c`](https://github.com/blond/eslint-config-pedant/commit/be5884c)] - chore(package): update es6-object-assign to version 1.0.2 (@greenkeeperio-bot) 143 | 144 | v0.5.0 (2016-05-15) 145 | ------------------- 146 | 147 | ### ECMAScript 3 & 5 148 | 149 | Added shareable configs for `ECMAScript 3` and `ECMAScript 5` ([#16], [#19]). 150 | 151 | Read more in [ECMAScript](./README.md#ecmascript) section. 152 | 153 | ### Rules 154 | 155 | Removed [comma-dangle](http://eslint.org/docs/rules/no-unsafe-finally) rule for `es6` and `es5` configs ([#14], [#19]). 156 | 157 | ### Dependencies 158 | 159 | Now `eslint-config-pedant` requires `eslint` version `2.9.0` or more ([#20]). 160 | 161 | [#14]: https://github.com/blond/eslint-config-pedant/issues/14 162 | [#16]: https://github.com/blond/eslint-config-pedant/issues/16 163 | [#19]: https://github.com/blond/eslint-config-pedant/pull/19 164 | [#20]: https://github.com/blond/eslint-config-pedant/pull/20 165 | 166 | ### Commits 167 | 168 | - [[`1ec3a8a`](https://github.com/blond/eslint-config-pedant/commit/1ec3a8a61885e5f9b0ea691cf3245793c2921ffd)] - chore(package): specify eslint as peer dependency (@blond) 169 | - [[`7fc57d2`](https://github.com/blond/eslint-config-pedant/commit/7fc57d2bb26262a6d658c3a9352054c09433e1e6)] - docs: add section about ECMAScript versions (@blond) 170 | - [[`883ea5b`](https://github.com/blond/eslint-config-pedant/commit/883ea5bb5bdd0b62189770be70980a82cf87b945)] - docs(example): separate example for es3 (@blond) 171 | - [[`f1e985a`](https://github.com/blond/eslint-config-pedant/commit/f1e985a2846a68730fb8ceeb3d0932fd40f6f27a)] - feat: add sub configs for es3, es5 and es6 (@blond) 172 | - [[`4a67e81`](https://github.com/blond/eslint-config-pedant/commit/4a67e81408b0b7eba8525354995e236425333a1d)] - chore(package): update eslint to version 2.10.1 (@greenkeeperio-bot) 173 | 174 | v0.4.0 (2016-05-05) 175 | ------------------- 176 | 177 | ### Rules 178 | 179 | * Added the [no-unsafe-finally](http://eslint.org/docs/rules/no-unsafe-finally) rule. 180 | 181 | ### Commits 182 | 183 | * [[`75f4c00`](https://github.com/blond/eslint-config-pedant/commit/75f4c00867)] - docs: add example for `no-unsafe-finally` rule (@blond) 184 | * [[`e3999c0`](https://github.com/blond/eslint-config-pedant/commit/e3999c0860)] - feat: add `no-unsafe-finally` rule (@blond) 185 | * [[`30e9caa`](https://github.com/blond/eslint-config-pedant/commit/30e9caa767)] - docs: update question about stylistic rules (@blond) 186 | * [[`a70ed61`](https://github.com/blond/eslint-config-pedant/commit/a70ed61d34)] - chore(package): update eslint to version 2.9.0 (@greenkeeperio-bot) 187 | * [[`43b454d`](https://github.com/blond/eslint-config-pedant/commit/43b454df9d)] - chore(package): update eslint to version 2.8.0 (@greenkeeperio-bot) 188 | 189 | v0.3.0 (2016-04-12) 190 | ------------------- 191 | 192 | ### Rules 193 | 194 | Added ES 2015 rules: 195 | 196 | * [constructor-super](http://eslint.org/docs/rules/constructor-super) 197 | * [no-this-before-super](http://eslint.org/docs/rules/no-this-before-super) 198 | * [no-dupe-class-members](http://eslint.org/docs/rules/no-dupe-class-members) 199 | * [no-class-assign](http://eslint.org/docs/rules/no-class-assign) 200 | * [no-const-assign](http://eslint.org/docs/rules/no-const-assign) 201 | * [no-new-symbol](http://eslint.org/docs/rules/no-new-symbol) 202 | * [require-yield](http://eslint.org/docs/rules/require-yield) 203 | 204 | ### Commits 205 | 206 | * [[`f802a06`](https://github.com/blond/eslint-config-pedant/commit/f802a06015)] - examples: add examples for es6 rules (blond) 207 | * [[`9baed36`](https://github.com/blond/eslint-config-pedant/commit/9baed3645e)] - rules: add es6 rules (blond) 208 | 209 | v0.2.0 (2016-03-08) 210 | ------------------- 211 | 212 | ### Rules 213 | 214 | * Add [no-new-require](http://eslint.org/docs/rules/no-new-require) rule. 215 | 216 | ### Commits 217 | 218 | * [[`938f82e`](https://github.com/blond/eslint-config-pedant/commit/938f82e6ca)] - update npm scripts (@blond) 219 | * [[`b8add01`](https://github.com/blond/eslint-config-pedant/commit/b8add01ac5)] - npm: update keywords (@blond) 220 | * [[`9cfe57c`](https://github.com/blond/eslint-config-pedant/commit/9cfe57c502)] - examples: add example for `no-new-requir` rule (@blond) 221 | * [[`8d43a72`](https://github.com/blond/eslint-config-pedant/commit/8d43a722ae)] - rules: add `no-new-require` rule (@blond) 222 | * [[`2cbcb02`](https://github.com/blond/eslint-config-pedant/commit/2cbcb02186)] - examples: remove `no-undefined` rule (@blond) 223 | * [[`904bc94`](https://github.com/blond/eslint-config-pedant/commit/904bc94421)] - examples: fix `comma-dangle` rule (@blond) 224 | * [[`929c79c`](https://github.com/blond/eslint-config-pedant/commit/929c79c5a5)] - docs: fix to no-undefined rule in bad examples (@guria) 225 | * [[`8f27afc`](https://github.com/blond/eslint-config-pedant/commit/8f27afcca0)] - chore(package): update eslint to version 2.7.0 (@greenkeeperio-bot) 226 | * [[`13f4aed`](https://github.com/blond/eslint-config-pedant/commit/13f4aed582)] - chore(package): update eslint to version 2.6.0 (@greenkeeperio-bot) 227 | * [[`1acc399`](https://github.com/blond/eslint-config-pedant/commit/1acc399b7b)] - chore(package): update eslint to version 2.5.3 (@greenkeeperio-bot) 228 | * [[`40c3dbe`](https://github.com/blond/eslint-config-pedant/commit/40c3dbed20)] - docs(install): update install guide (@blond) 229 | --------------------------------------------------------------------------------