Skip to content

Instantly share code, notes, and snippets.

@mLuby
Last active January 29, 2017 03:58
Show Gist options
  • Save mLuby/5d6e67fb63c9f195044c39abf7f58829 to your computer and use it in GitHub Desktop.
Save mLuby/5d6e67fb63c9f195044c39abf7f58829 to your computer and use it in GitHub Desktop.
Comprehensive JS lint file (+ es6, react)
{
"rules": { // And why they're best practice (alphabetized).
"accessor-pairs": [2, {"getWithoutSet": true}], // omission is usually by mistake.
"array-bracket-spacing": 2, // spaces can make arrays take up a lot of space, and concise code allows for more reading context.
"array-callback-return": 2, // omission is usually by mistake.
"arrow-body-style": [2, "as-needed"], // improves consistency and readability.
// "arrow-parens": [2, "as-needed"], // allows for concise arrows while improving consistency.
"arrow-spacing": 2, // improves consistency and readability.
"block-scoped-var": 2, // can behave unexpectedly due to variable hoisting.
"block-spacing": 2, // helps differentiate blocks (spaced) from objects (not spaced).
"brace-style": [2, "1tbs", {"allowSingleLine": true}], // common and concise.
"callback-return": [2, ["callback", "cb", "next"]], // usually returns control to cb, so best to return out of function as well.
// "camelcase": 2, // camelCase is JS convention, and this still allows capcase constants.*/
"comma-dangle": 2, // causes bug in IE8.
"comma-spacing": 2, // improves consistency.
"comma-style": [2, "last"], // improves consistency.
"complexity": 1, // code with high cyclomatic complexity is difficult to reason about.
"computed-property-spacing": 2, // usually a typo.
"consistent-return": 2, // reduces ambiguity about what gets returned.
"consistent-this": [2, "context"], // enforces a standard var for capturing context (which should be done sparingly).
"constructor-super": 2, // catches runtime syntax errors.
"curly": 2, // reduces ambiguity around blocks and line breaks.
"default-case": 2, // not having default (and break) lead to unexpected results.
"dot-location": [2, "property"], // easier to notice . at the beginning of a line.
"dot-notation": 2, // easier to read.
"eol-last": 2, // aids in file concatination; github complains without this.
"eqeqeq": 2, // avoids unexpected type coercion.
"func-names": 2, // having named functions makes following stack traces much easier.
"func-style": [2, "declaration"], // differentiates funcs from consts; hoisting allows more readable code ordering.
// "generator-star": 0, // removed.
"generator-star-spacing": [2, {"before": false, "after": true}], // standard on MDN docs.
"global-require": 2, // avoid unexpected sync file load.
// "global-strict": 0, // removed.
"guard-for-in": 2, // protects against looping over props up prototype chain.
"handle-callback-err": [2, "^.*(e|E)rr"], // often omitted in error.
"id-blacklist": 0, // will add variable names to this list if abused.
"id-length": 0, // variable naming is difficult enough without limits.
"id-match": 0, // covered by camelCase.
"indent": [2, 2], // improves consistency.
"init-declarations": 2, // not assigning an initialized variable should be explicit, not a mistake.
"jsx-quotes": 2, // improves consistency; more common to have to quote single quotes than double so double is default.
"key-spacing": 2, // improves consistency.
"keyword-spacing": 2, // distinguishes keyword invocation from function invocation.
"linebreak-style": [2, "unix"], // improves consistency; prevents windows users from introducing \r.
"lines-around-comment": 0, // comments are bad enough; don't give them extra padding.
"max-depth": [1, 4], // deeply nested code can be difficult to read.
"max-len": [0, {"code": 100, "ignoreTrailingComments": true, "ignoreUrls": true}], // vertically-concise code gives reader more context.
"max-nested-callbacks": [1, 2], // a sign that the nested code should be refactored out.
"max-params": 0, // better to have many params than obscure them with a config object.
"max-statements": [1, 10], // functions should be focused and concise.
"max-statements-per-line": 2, // improves readability; exceptions should be explicitly noted.
"new-cap": 2, // makes it easy to tell if a function is a constructor requiring the new keyword.
"new-parens": 2, // usually omitted by mistake.
"newline-after-var": 0, // improves consistency; concise code gives reader more context.
"newline-before-return": 0, // vertical space is too precious to be wasted.
"newline-per-chained-call": 0, // some chained calls belong together.
"no-alert": 2, // alerts are annoying.
"no-array-constructor": 2, // can do surprising things; better to use [].
// "no-arrow-condition": 0, // removed.
"no-bitwise": 2, // these are usually typos; can be difficult to reason about.
"no-caller": 2, // deprecated.
"no-case-declarations": 0, // can lead to unexpected behavior.
"no-catch-shadow": 2, // causes a bug in IE8.
"no-class-assign": 2, // usually a typo.
// "no-comma-dangle": 0, // removed.
"no-cond-assign": 2, // usually typos.
"no-confusing-arrow": [2, {"allowParens": true}], // avoids typos and ambiguity while allowing concise syntax.
"no-console": 2, // for debugging only; shouldn't be committed.
"no-const-assign": 2, // catches runtime syntax errors.
"no-constant-condition": 2, // unnecessary; usually a typo.
"no-continue": 2, // makes reasoning about loops more difficult.
"no-control-regex": 2, // usually a typo.
"no-debugger": 2, // for debugging only; shouldn't be committed.
"no-delete-var": 2, // only properties should be deleted.
"no-div-regex": 2, // regex are difficult enough; also operator-assignment disallows /= operator.
"no-dupe-args": 2, // shadowing increases ambiguity.
"no-dupe-class-members": 2, // can behave unexpectedly, probably a typo.
"no-dupe-keys": 2, // can cause unexpected behavior.
"no-duplicate-case": 2, // almost certainly a mistake.
"no-duplicate-imports": 2, // should be consolidated for brevity.
"no-else-return": 2, // explicit conditional paths are better than implicit.
"no-empty": 2, // probably a mistake.
"no-empty-character-class": 2, // probably a typo.
// "no-empty-class": 0, // removed.
"no-empty-function": 2, // probably a mistake.
// "no-empty-label": 0, // removed.
"no-empty-pattern": 2, // looks like object but is in fact noop.
"no-eq-null": 2, // use strict equality.
"no-eval": 2, // eval is often unsafe and performs poorly.
"no-ex-assign": 2, // overwriting params is usually bad; can obscure errors.
"no-extend-native": 2, // can cause unexpected behavior for other devs.
"no-extra-bind": 2, // removes useless code.
"no-extra-boolean-cast": 2, // unnecessary.
"no-extra-label": 2, // don't use labels
"no-extra-parens": 0, // parens can be useful for decreasing ambiguity.
"no-extra-semi": 2, // probably a typo.
// "no-extra-strict": 0, // removed.
"no-fallthrough": 2, // catches mistakes that lead to unexpected behavior.
"no-floating-decimal": 2, // looks too much like dot operator.
"no-func-assign": 2, // probably a typo.
"no-implicit-coercion": 2, // avoids fancy coercion tricks that inhibit readability.
"no-implicit-globals": 0, // modules make this rule unnecessary.
"no-implied-eval": 2, // eval is often unsafe and performs poorly.
"no-inline-comments": 0, // helps prevent post-refactor orphaned comments.
"no-invalid-regexp": 2, // the more checks on regex correctness the better.
"no-inner-declarations": 2, // avoids unexpected behavior.
// "no-invalid-this": 1, // avoids possible undefined or typeerror this.
"no-irregular-whitespace": 2, // improves consistency.
"no-iterator": 2, // this feature is obsolete and not widely supported.
"no-label-var": 2, // a bad feature related to loop control flow, like GOTO.
"no-labels": 2, // a bad feature related to loop control flow, like GOTO.
"no-lone-blocks": 2, // unless in es6, these are just useless clutter.
"no-lonely-if": 2, // extra-verbose and unusual.
"no-loop-func": 2, // functions in loops are difficult to reason about.
"no-magic-numbers": [2, {"enforceConst": true, "ignore": [0,1,2]}], // what the number represents gets lost.
"no-mixed-requires": 2, // group requires and seperate from other init for clearer code.
"no-mixed-spaces-and-tabs": 2, // just spaces for consistency.
"no-multi-spaces": 2, // these are almost always typos.
"no-multi-str": 2, // use newline chars or template strings instead.
"no-multiple-empty-lines": 2, // concise code gives reader more context.
"no-native-reassign": 2, // can cause unexpected behavior for other devs.
"no-negated-condition": 2, // improves reasonability.
"no-negated-in-lhs": 2, // reduces ambiguity and typos.
"no-nested-ternary": 2, // improves reasonability.
"no-new": 2, // using new for side effects is bad because side effects are bad and OO is bad.
"no-new-func": 2, // eval is often unsafe and performs poorly.
"no-new-object": 2, // use more concise {} instead.
"no-new-require": 2, // unusual; just use require.
"no-new-symbol": 2, // should be called as a function without new.
"no-new-wrappers": 2, // does not do what it looks like it does.
"no-obj-calls": 2, // part of the spec.
"no-octal": 2, // can be confusing.
"no-octal-escape": 2, // deprecated.
"no-param-reassign": 0, // useful for guarding a function.
"no-path-concat": 2, // breaks for non-unix system.
"no-plusplus": 2, // may cause semicolon issues, and can be expressed more explicitly.
"no-process-env": 2, // global deps are bad; better to use config files.
"no-process-exit": 2, // too drastic; almost always better to throw and handle.
"no-proto": 2, // deprecated.
"no-redeclare": [2, {"builtinGlobals": true}], // probably a mistake; should use const/let instead anyway.
"no-regex-spaces": 2, // probably a typo.
// "no-reserved-keys": 0, // removed.
"no-restricted-globals": 0, // not (yet) necessary.
"no-restricted-imports": 0, // not (yet) necessary.
"no-restricted-modules": 0, // not (yet) necessary.
"no-restricted-syntax": [2, "TryStatement"], // try-catch makes tracing errors difficult.
"no-return-assign": [2, "always"], // can cover up typos.
"no-script-url": 2, // eval is often unsafe and performs poorly.
"no-self-assign": 2, // no effect; probably a typo.
"no-self-compare": 2, // usually a typo; better to use isNaN.
"no-sequences": 2, // usually a typo; obscures side effects.
"no-shadow": 2, // difficult to read, limits access to higher scope vars.
"no-shadow-restricted-names": 2, // should not mess with restricted.
// "no-space-before-semi": 0, // removed.
"no-sparse-arrays": 2, // usually typos.
"no-spaced-func": 2, // space between func and params differentiates declaration from invocation.
"no-sync": 2, // blocks single thread; use async.
"no-ternary": 0, // ternaries more concise and more strict than if/else.
"no-this-before-super": 2, // catches a reference error.
"no-throw-literal": 2, // be consistent about only throwing Error objects.
"no-trailing-spaces": 2, // unnecessary; github doesn't like them.
"no-undef": 2, // catches ReferenceErrors.
"no-undef-init": 2, // unnecessary.
"no-undefined": 2, // better to check typeof
"no-underscore-dangle": 2, // should not rely on variable name to reason about scoping, as it may change.
"no-unexpected-multiline": 2, // prevents issues related to semicolons.
"no-unmodified-loop-condition": 2, // possible infinite loop; probably a mistake.
"no-unneeded-ternary": 2, // improves consistency and readability.
"no-unreachable": 2, // helps keep things clean during refactoring.
"no-unsafe-finally": 2, // leads to unexpected behavior.
"no-unused-expressions": 2, // usually a typo; has o effect.
"no-unused-labels": 2, // don't use labels.
"no-unused-vars": 2, // probably a mistake.
"no-use-before-define": [2, {"functions": false}], // avoids temporal dead zone; functions below can improve readability.
"no-useless-call": 2, // slower than normal invocation.
"no-useless-computed-key": 2, // unnecessary; can cause confusion.
"no-useless-concat": 2, // slower than static combination.
"no-useless-constructor": 2, // unnecessary.
"no-useless-escape": 2, // makes code easier to read.
"no-var": 2, // const is best, and let is useful for counters, but they eclipse var's uses. #ES6only
"no-void": 2, // unusual and unnecessary.
"no-warning-comments": 2, // warning comments should be addressed before merge (or moved out of code).
"no-whitespace-before-property": 2, // typos.
"no-with": 2, // can add unexpected variables to scope.
// "no-wrap-func": 0, // removed.
"object-curly-spacing": 2, // helps differentiate blocks (spaced) from objects (not spaced).
"object-shorthand": 2, // increases consistency. #ES6only
"one-var": [2, "never"], // grouped statement types are more consistent and readable.
"one-var-declaration-per-line": 0, // superceded by one-var.
"operator-assignment": [2, "never"], // better to be explicit about what is happening than relying on shorthand.
"operator-linebreak": [2, "none"], // if the statement is too long, it can probably be refactored.
"padded-blocks": [0, "never"], // concise code gives reader more context.
"prefer-arrow-callback": 2, // increases readability and consistency.
"prefer-const": 2, // better to be explicit about what is expected to change.
"prefer-reflect": 0, // this rule is deprecated.
"prefer-rest-params": 2, // easier to read than slicing args. #ES6only
"prefer-spread": 2, // avoids unneecessary call and apply.
"prefer-template": 2, // string concatenation is slow and error-prone. #ES6only
"quote-props": [2, "as-needed"], // improves consistency and readability.
"quotes": [2, "double"], // improves consistency; more common to have to quote single quotes than double so double is default.
"radix": 2, // should be explicit about what kind of int is being parsed.
"react/display-name": 2, // components should have names to make stack traces easier to read.
"react/forbid-prop-types": 2, // should use arrayOf and shape to be more explicit about array and object prop requirements.
"react/jsx-boolean-value": 2, // better to be explicit about a boolean value.
"react/jsx-closing-bracket-location": 2, // improves consistency.
"react/jsx-curly-spacing": 2, // improves consistency.
"react/jsx-equals-spacing": 2, // improves consistency.
// "react/jsx-first-prop-new-line": [2, "multiline"], // improves consistency and readability. #TODO broken.
"react/jsx-handler-names": 1, // improves consistency.
"react/jsx-indent": [2, 2], // improves consistency, readability.
"react/jsx-indent-props": 2, // improves consistency, readability.
"react/jsx-key": 2, // avoid warning.
"react/jsx-max-props-per-line": 0, // concise code gives reader more context.
"react/jsx-no-bind": 2, // performance issue, happens on every render.
"react/jsx-no-duplicate-props": 2, // usually mistakes.
"react/jsx-no-literals": 0, // prevents unexpected behavior.
// "react/jsx-no-target-blank": 2, // prevents security vulnerability. #TODO broken.
"react/jsx-no-undef": 2, // catches syntax errors.
"react/jsx-pascal-case": 2, // improves consistency and readability.
"react/jsx-sort-props": [2, {"ignoreCase": true}], // improves consistency and readability.
"react/jsx-space-before-closing": 2, // improves consistency.
"react/jsx-uses-react": 2, // helps linter know that react is used by jsx.
"react/jsx-uses-vars": 2, // unused variables are useless.
"react/no-danger": 2, // protects against html injection vulnerabilities.
"react/no-deprecated": 2, // should stay up to date.
"react/no-did-mount-set-state": 2, // will cause a multiple render calls.
"react/no-did-update-set-state": 2, // will cause a multiple render calls.
"react/no-direct-mutation-state": 2, // state mutation is incompatible with redux.
"react/no-is-mounted": 2, // deprecated.
"react/no-multi-comp": 2, // improves readability.
"react/no-set-state": 1, // use redux to change state instead.
"react/no-string-refs": 2, // deprecated.
"react/no-unknown-property": 2, // can cause unexpected HTML errors.
"react/prefer-es6-class": [0, "always"], // should use stateless functional components whenever possible.
// "react/prefer-stateless-function": 2, // should use stateless functional components whenever possible. #TODO broken.
"react/prop-types": 2, // validating inputs improves reusability.
"react/react-in-jsx-scope": 2, // catches typos.
"react/require-extension": [2, {"extensions": [".js", ".jsx"]}], // improves consistency.
// "react/require-render-return": 2, // catches omission mistakes. #TODO broken.
"react/self-closing-comp": 2, // improves consistency and readability.
"react/sort-comp": 2, // improves consistency, readability.
"react/sort-prop-types": [2, {"ignoreCase": true}], // improves consistency, readability.
"react/wrap-multilines": 2, // improves consistency, readability.
"require-jsdoc": 0, // unless using jsdoc.
"require-yield": 2, // omission is probably a mistake.
"semi": [2, "never"], // unnecessary due to ASI; improves consistency and readability.
"semi-spacing": 2, // improves consistency.
"sort-imports": [2, {"ignoreCase": true}], // improves consistency, readability.
"sort-vars": 2, // improves consistency.
// "space-after-function-name": 0, // removed.
// "space-after-keywords": 0, // removed.
"space-before-blocks": 2, // makes things look consistent with keyword spacing.
"space-before-function-paren": 2, // distinguishes keyword invocation from function invocation.
// "space-before-function-parentheses": 0, // removed.
// "space-before-keywords": 0, // removed.
// "space-in-brackets": 0, // removed.
"space-in-parens": 2, // increases consistency.
"space-infix-ops": 2, // increases consistency, avoids unexpected behavior due to typos.
// "space-return-throw-case": 0, // removed.
"space-unary-ops": 2, // unusual, improves consistency.
// "space-unary-word-ops": 0, // removed.
"spaced-comment": 2, // improves consistency.
// "spaced-line-comment": 0, // removed.
"strict": [0, "global"], // unnecessary when babbling.
"template-curly-spacing": 2, // makes code concise, and therefore more readable.
"use-isnan": 2, // comparing to NaN can be difficult to reason about.
"valid-jsdoc": 0, // not using jsdoc.
"valid-typeof": 2, // there are ways to type-check, but will least prevent typos.
"vars-on-top": 2, // best to have code agree with hoisting.
"wrap-iife": [2, "inside"], // make IIFE's more obvious; inside fits standard invocation syntax better.
"wrap-regex": 2, // avoids possible confusion with comments or division operator.
"yield-star-spacing": [2, {"before": false, "after": true}], // standard on MDN docs.
"yoda": 2 // improves readability and consistency.
},
"env": {
"es6": true,
"browser": true,
"node": true,
"jasmine": true
},
"plugins": ["react"],
"parser": "babel-eslint", // would fix class property syntax issues (static x = 0, @decorator).
"parserOptions": {
"ecmaVersion": 6,
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": true,
"jsx": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": true,
"regexUFlag": true,
"regexYFlag": true,
"restParams": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true,
"experimentalObjectRestSpread": true
},
"sourceType": "module"
},
"extends": "eslint:recommended"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment