From 2de318ad71b5c72d9f40ea86ae05db8a08c2038d Mon Sep 17 00:00:00 2001 From: vvo Date: Mon, 11 Jul 2016 11:23:20 +0200 Subject: [PATCH] feat(major): eslint 3, stop relying on airbnb and too much invisible defaults The default setup for our eslint-config-algolia was starting to be too dependent on a lot of other packages which made us in a situation where we could not upgrade easily. I have created a complete config with some new defaults given eslint 3. If you are using npm 3, the only package to install is eslint-config-algolia. Then since eslint-config-algolia depends on eslint, eslint-plugin-react and eslint-plugin-import, and npm 3 flattens by default, it should work. --- .eslintrc | 3 - README.md | 37 +++---- index.js | 269 +++++++++++++++++++++++++++++++++++++++++++++++++-- package.json | 22 ++--- 4 files changed, 282 insertions(+), 49 deletions(-) delete mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index cbd251a2..00000000 --- a/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "algolia" -} diff --git a/README.md b/README.md index 37141a2b..69f3da5a 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,25 @@ # eslint-config-algolia -This is [Algolia](https://www.algolia.com/)'s [ESLint](http://eslint.org/) configuration for es5 and es6. - -We [extend](http://eslint.org/docs/user-guide/configuring.html#extending-configuration-files) [airbnb/javascript](https://github.com/airbnb/javascript) rules. +This is [Algolia](https://www.algolia.com/)'s [ESLint](http://eslint.org/) configuration. ## Usage ```sh -npm install eslint eslint-config-algolia eslint-config-airbnb eslint-plugin-react babel-eslint --save-dev +npm install eslint-config-algolia --save-dev ``` -create an `.eslintrc` file: -```json -{ - "extends": "algolia" -} +create an `.eslintrc.js` file: +```js +module.exports = { + "extends": ["algolia"] +}; ``` ### Tips If you are using [any editors plugin](http://eslint.org/docs/user-guide/integrations.html#editors) for ESLint then it will show you warnings/errors. -Now you can create an npm `lint` [script](https://docs.npmjs.com/files/package.json#scripts) that will run `eslint .` to lint all files or `eslint . --quiet` to hide warnings. - -## Rules - -The rules are the ones from the [Airbnb JavaScript style guide](https://github.com/airbnb/javascript#airbnb-javascript-style-guide-) with [modifications](./index.js): - -- disallow [space-in-brackets](http://eslint.org/docs/rules/space-in-brackets) ~~`var arr = [ 1 ]`~~ -- disallow [space-in-parens](http://eslint.org/docs/rules/space-in-parens) ~~`if ( true ) { }`~~ -- disable [vars-on-top](http://eslint.org/docs/rules/vars-on-top) -- disable [no-param-reassign](http://eslint.org/docs/rules/no-param-reassign) `function(param) { param = param }` -- warn on long lines [max-len](http://eslint.org/docs/rules/max-len) -- enable [no-use-before-define](http://eslint.org/docs/rules/no-use-before-define) for functions -- prefer function declarations [func-style](http://eslint.org/docs/rules/) +Now you can create an npm `lint` [script](https://docs.npmjs.com/files/package.json#scripts) that will run `eslint "**/*.js"` to lint all files. ## Ignoring files @@ -41,9 +27,9 @@ See "Ignoring Files and Directories" on [ESLint website](http://eslint.org/docs/ ## Using as a global eslint config -You can have a `~/.eslintrc` config that will be used if your project has no `.eslintrc`. +You can have a `~/.eslintrc.js` config that will be used if your project has no `.eslintrc.js`. -Create a `~/.eslintrc` with: +Create a `~/.eslintrc.js` with: ```json { @@ -55,6 +41,5 @@ Then: ```sh cd ~ -npm install eslint eslint-config-algolia eslint-config-airbnb eslint-plugin-react +npm install eslint-config-algolia ``` - diff --git a/index.js b/index.js index 92dfe93c..e7f90e17 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,265 @@ module.exports = { - extends: [ - 'eslint:recommended', - 'airbnb', - 'algolia/rules/base', - 'algolia/rules/react' - ] + "env": { + "browser": true, + "es6": true, + "node": true + }, + "parserOptions": { + "ecmaFeatures": { + "experimentalObjectRestSpread": true, + "jsx": true + }, + "sourceType": "module" + }, + "plugins": [ + "react", + "import" + ], + "extends": [ + "plugin:react/recommended", + "plugin:import/errors", + "plugin:import/warnings" + ], + "rules": { + // Possible errors + // http://eslint.org/docs/rules/#possible-errors + "no-cond-assign": ["error"], + "no-console": ["error"], + "no-constant-condition": ["error"], + "no-control-regex": ["error"], + "no-debugger": ["error"], + "no-dupe-args": ["error"], + "no-dupe-keys": ["error"], + "no-duplicate-case": ["error"], + "no-empty": ["error"], + "no-empty-character-class": ["error"], + "no-ex-assign": ["error"], + "no-extra-boolean-cast": ["error"], + "no-extra-parens": ["error"], + "no-extra-semi": ["error"], + "no-func-assign": ["error"], + "no-inner-declarations": ["error"], + "no-invalid-regexp": ["error"], + "no-irregular-whitespace": ["error"], + "no-negated-in-lhs": ["error"], + "no-obj-calls": ["error"], + "no-prototype-builtins": ["error"], + "no-regex-spaces": ["error"], + "no-sparse-arrays": ["error"], + "no-unexpected-multiline": ["error"], + "no-unreachable": ["error"], + "no-unsafe-finally": ["error"], + "use-isnan": ["error"], + "valid-jsdoc": ["error"], + "valid-typeof": ["error"], + + // Best practices + // http://eslint.org/docs/rules/#best-practices + "accessor-pairs": ["error"], + "array-callback-return": ["error"], + "block-scoped-var": ["error"], + "complexity": ["error"], + "consistent-return": ["error"], + "curly": ["off"], + "default-case": ["error"], + "dot-location": ["off"], + "dot-notation": ["error"], + "eqeqeq": ["error"], + "guard-for-in": ["error"], + "no-alert": ["error"], + "no-caller": ["error"], + "no-case-declarations": ["error"], + "no-div-regex": ["error"], + "no-empty-function": ["off"], + "no-empty-pattern": ["error"], + "no-eq-null": ["error"], + "no-eval": ["error"], + "no-extend-native": ["error"], + "no-extra-bind": ["error"], + "no-extra-label": ["error"], + "no-fallthrough": ["error"], + "no-floating-decimal": ["error"], + "no-implicit-coercion": ["error", {"string": false}], + "no-implicit-globals": ["error"], + "no-implied-eval": ["error"], + "no-invalid-this": ["off"], + "no-iterator": ["error"], + "no-labels": ["error"], + "no-lone-blocks": ["error"], + "no-loop-func": ["error"], + "no-magic-numbers": ["off"], + "no-multi-spaces": ["error"], + "no-multi-str": ["error"], + "no-native-reassign": ["error"], + "no-new": ["error"], + "no-new-func": ["error"], + "no-new-wrappers": ["error"], + "no-octal": ["error"], + "no-octal-escape": ["error"], + "no-param-reassign": ["off"], + "no-proto": ["error"], + "no-redeclare": ["error"], + "no-return-assign": ["error"], + "no-script-url": ["error"], + "no-self-assign": ["error"], + "no-self-compare": ["error"], + "no-sequences": ["error"], + "no-throw-literal": ["error"], + "no-unmodified-loop-condition": ["error"], + "no-unused-expressions": ["error"], + "no-unused-labels": ["error"], + "no-useless-call": ["error"], + "no-useless-concat": ["error"], + "no-useless-escape": ["error"], + "no-void": ["error"], + "no-warning-comments": ["error"], + "no-with": ["error"], + "radix": ["error"], + "vars-on-top": ["error"], + "wrap-iife": ["error"], + "yoda": ["error"], + + // Strict mode + // http://eslint.org/docs/rules/#strict-mode + "strict": ["error", "never"], + + // Variables + // http://eslint.org/docs/rules/#variables + "init-declarations": ["off"], + "no-catch-shadow": ["error"], + "no-delete-var": ["error"], + "no-label-var": ["error"], + "no-restricted-globals": ["error", "event"], + "no-shadow": ["error"], + "no-shadow-restricted-names": ["error"], + "no-undef": ["error"], + "no-undefined": ["off"], + "no-unused-vars": ["error"], + "no-use-before-define": ["error", {"functions": false}], + + // Node.js and Common.js + // http://eslint.org/docs/rules/#nodejs-and-commonjs + "callback-return": ["off"], + "global-require": ["off"], + "handle-callback-err": ["error"], + "no-mixed-requires": ["error"], + "no-new-require": ["error"], + "no-path-concat": ["error"], + "no-process-env": ["off"], + "no-process-exit": ["error"], + "no-restricted-modules": ["error"], + "no-sync": ["off"], + + // Stylistic issues + // http://eslint.org/docs/rules/#stylistic-issues + "array-bracket-spacing": ["error"], + "block-spacing": ["error"], + "brace-style": ["error", "1tbs", {"allowSingleLine": true}], + "camelcase": ["error"], + "comma-dangle": ["error"], + "comma-spacing": ["error"], + "comma-style": ["error"], + "computed-property-spacing": ["error"], + "consistent-this": ["error"], + "eol-last": ["error"], + "func-names": ["off"], + "func-style": ["off"], + "id-blacklist": ["off"], + "id-length": ["off"], + "id-match": ["off"], + "indent": ["error", 2], + "jsx-quotes": ["error"], + "key-spacing": ["error", ], + "keyword-spacing": ["error"], + "linebreak-style": ["error"], + "lines-around-comment": ["off"], + "max-depth": ["error"], + "max-len": ["error", {"code": 120, "ignoreComments": true, "ignoreTrailingComments": true, "ignoreUrls": true}], + "max-lines": ["off"], + "max-nested-callbacks": ["error"], + "max-params": ["error", 5], + "max-statements": ["off"], + "max-statements-per-line": ["off"], + "new-cap": ["error"], + "new-parens": ["error"], + "newline-after-var": ["off"], + "newline-before-return": ["off"], + "newline-per-chained-call": ["off"], + "no-array-constructor": ["error"], + "no-bitwise": ["error"], + "no-continue": ["error"], + "no-inline-comments": ["off"], + "no-lonely-if": ["error"], + "no-mixed-operators": ["off"], + "no-mixed-spaces-and-tabs": ["error"], + "no-multiple-empty-lines": ["error"], + "no-negated-condition": ["off"], + "no-nested-ternary": ["error"], + "no-new-object": ["error"], + "no-plusplus": ["off"], + "no-restricted-syntax": ["off"], + "no-spaced-func": ["error"], + "no-ternary": ["off"], + "no-trailing-spaces": ["error"], + "no-underscore-dangle": ["off"], + "no-unneeded-ternary": ["error"], + "no-whitespace-before-property": ["error"], + "object-curly-newline": ["off"], + "object-curly-spacing": ["error"], + "object-property-newline": ["off"], + "one-var": ["error", "never"], + "one-var-declaration-per-line": ["error"], + "operator-assignment": ["off"], + "operator-linebreak": ["off"], + "padded-blocks": ["error", "never"], + "quote-props": ["error", "consistent-as-needed"], + "quotes": ["error", "single"], + "require-jsdoc": ["off"], + "semi": ["error"], + "semi-spacing": ["error"], + "sort-vars": ["off"], + "space-before-blocks": ["off"], + "space-before-function-paren": ["off"], + "space-in-parens": ["error"], + "space-infix-ops": ["error"], + "space-unary-ops": ["error"], + "spaced-comment": ["error"], + "unicode-bom": ["error"], + "wrap-regex": ["error"], + + // ECMAScript 6 + // http://eslint.org/docs/rules/#ecmascript-6 + "arrow-body-style": ["error"], + "arrow-parens": ["error", "as-needed"], + "arrow-spacing": ["error"], + "constructor-super": ["error"], + "generator-star-spacing": ["error"], + "no-class-assign": ["error"], + "no-confusing-arrow": ["off"], + "no-const-assign": ["error"], + "no-dupe-class-members": ["error"], + "no-duplicate-imports": ["error"], + "no-new-symbol": ["error"], + "no-restricted-imports": ["off"], + "no-this-before-super": ["error"], + "no-useless-computed-key": ["error"], + "no-useless-constructor": ["error"], + "no-useless-rename": ["error"], + "no-var": ["error"], + "object-shorthand": ["error"], + "prefer-arrow-callback": ["error"], + "prefer-const": ["error"], + "prefer-reflect": ["off"], + "prefer-rest-params": ["error"], + "prefer-spread": ["error"], + "prefer-template": ["error"], + "require-yield": ["error"], + "rest-spread-spacing": ["error"], + "sort-imports": ["off"], + "template-curly-spacing": ["error"], + "yield-star-spacing": ["error"], + + "react/no-danger": ["off"], + "react/display-name": ["off"] + } }; diff --git a/package.json b/package.json index 9f106f26..76f6e9a8 100644 --- a/package.json +++ b/package.json @@ -1,30 +1,24 @@ { "name": "eslint-config-algolia", "version": "4.2.0", - "description": "Algolia's ESLint config. Based on the Airbnb ESLint config, with some modifications.", + "description": "Algolia's ESLint config.", "repository": "algolia/eslint-config-algolia", "keywords": [ "eslint", "eslintconfig", - "es5", - "es6" + "es6", + "algolia" ], "main": "index.js", - "scripts": { - "lint": "eslint .", - "test": "npm run lint" - }, "author": "Algolia ", "license": "MIT", "bugs": { "url": "https://github.com/algolia/eslint-config-algolia" }, "homepage": "https://github.com/algolia/eslint-config-algolia", - "devDependencies": { - "babel-eslint": "^4.1.3", - "eslint": "^1.7.3", - "eslint-config-airbnb": "^0.1.0", - "eslint-config-algolia": "latest", - "eslint-plugin-react": "^3.6.3" + "dependencies": { + "eslint": "^3.0.1", + "eslint-plugin-import": "^1.10.2", + "eslint-plugin-react": "^5.2.2" } -} \ No newline at end of file +}