tpai
10/13/2016 - 7:22 AM

ESLint Cheatsheet

ESLint Cheatsheet

Install Dependencies

yarn add babel-eslint \
eslint \
eslint-config-airbnb \
eslint-loader \
eslint-plugin-import \
eslint-plugin-jsx-a11y \
eslint-plugin-react

Lint Command

eslint $(find src -name \*.js?)

ESLint Configuration

.vimrc

let g:syntastic_javascript_checkers=['eslint']

.eslintrc

{
    "parser": "babel-eslint",
    "extends": "airbnb",
    "plugins": [
        "react"
    ],
    "rules": {
        "new-cap": 0,
        "no-else-return": 0,
        "no-debugger": 0,
        "no-console": 0,
        "no-mixed-operators": 0,
        "no-param-reassign": 0,
        "no-prototype-builtins": 0,
        "no-underscore-dangle": 0,
        "no-eval": 0,
        "no-case-declarations": 0,
        "global-require": 0,

        // comma
        "comma-dangle": [ 2, "never" ],

        // parentheses
        "arrow-parens": [ 2, "as-needed" ],

        // module import
        "import/no-extraneous-dependencies": 0,
        "import/no-unresolved": 0,
        "import/extensions": 0,
        "import/imports-first": 0,

        // indentation
        "indent": [ 2, 4 ],

        // spacing
        "space-in-parens": [ 2, "never" ],
        "object-curly-spacing": [ 2, "always" ],
        "no-multiple-empty-lines": [ 2, { "max": 1, "maxEOF": 0, "maxBOF": 0 } ],
        "linebreak-style": ["error", "unix"],

        // strings
        "quotes": [ 2, "single", { "allowTemplateLiterals": true } ],

        // code arrangement matter
        "no-use-before-define": 0,

        // allowed 'ForInStatement'
        "no-restricted-syntax": 0,

        // make it meaningful
        "prefer-const": 1,

        // react
        "react/prefer-es6-class": 0,
        "react/jsx-filename-extension": 0,
        "react/jsx-curly-spacing": [ 2, "never" ],
        "react/jsx-indent": [ 2, 4 ],
        "react/no-unused-prop-types": 0,
        "react/no-danger": 0,
        "react/no-string-refs": 0,
        "react/no-did-mount-set-state": 0,
        "react/require-default-props": 0,

        // div could have event listener
        "jsx-a11y/no-static-element-interactions": 0,
        "jsx-a11y/img-has-alt": 0,
        "jsx-a11y/anchor-is-valid": 0,

        // no default export
        "import/prefer-default-export": 0,

        // allow anonymous functions
        "func-names": [ 2, "never" ],
    }
}