diff --git a/.eslintrc.js b/.eslintrc.js index 45fc4c94140f1c..285f4668eb53bb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,7 +19,7 @@ const majorMinorRegExp = escapeRegExp( version.replace( /\.\d+$/, '' ) ) + '(\\. module.exports = { root: true, extends: [ - './eslint/config.js', + '@wordpress/eslint-config', 'plugin:jest/recommended' ], env: { diff --git a/package-lock.json b/package-lock.json index c2e08b8f0d9031..067cdb63b36755 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2593,6 +2593,16 @@ "@babel/runtime": "^7.0.0" } }, + "@wordpress/eslint-config": { + "version": "file:packages/eslint-config", + "dev": true, + "requires": { + "babel-eslint": "^8.0.3", + "eslint-config-wordpress": "2.0.0", + "eslint-plugin-jsx-a11y": "6.0.2", + "eslint-plugin-react": "7.7.0" + } + }, "@wordpress/format-library": { "version": "file:packages/format-library", "requires": { @@ -3058,16 +3068,6 @@ } } }, - "aria-query": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-0.7.1.tgz", - "integrity": "sha1-Jsu1r/ZBRLCoJb4YRuCxbPoAsR4=", - "dev": true, - "requires": { - "ast-types-flow": "0.0.7", - "commander": "^2.11.0" - } - }, "arr-diff": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-4.0.0.tgz", @@ -3326,15 +3326,6 @@ "integrity": "sha512-32NDda82rhwD9/JBCCkB+MRYDp0oSvlo2IL6rQWA10PQi7tDUM3eqMSltXmY+Oyl/7N3P3qNtAlv7X0d9bI28w==", "dev": true }, - "axobject-query": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-0.1.0.tgz", - "integrity": "sha1-YvWdvFnJ+SQnWco0mWDnov48NsA=", - "dev": true, - "requires": { - "ast-types-flow": "0.0.7" - } - }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -5674,15 +5665,6 @@ "integrity": "sha512-sVXqklSaotK9at437sFlFpyOcJonxe0yST/AG9DkQKUdIE6IqGIMv4SfAQSKaJbSdVEJYItASCrBiVQHq1HQew==", "dev": true }, - "comment-parser": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-0.4.2.tgz", - "integrity": "sha1-+lo/eAEwcBFIZtx7jpzzF6ljX3Q=", - "dev": true, - "requires": { - "readable-stream": "^2.0.4" - } - }, "commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -7574,28 +7556,12 @@ "integrity": "sha1-UgEgbGlk1kgxUjLt9t+9LpJeTNY=", "dev": true }, - "eslint-plugin-i18n": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-i18n/-/eslint-plugin-i18n-1.2.0.tgz", - "integrity": "sha1-SfP0OA7e/oyHbwyXlh9lw6w3zao=", - "dev": true - }, "eslint-plugin-jest": { "version": "21.5.0", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-21.5.0.tgz", "integrity": "sha512-4fxfe2RcqzU+IVNQL5n4pqibLcUhKKxihYsA510+6kC/FTdGInszDDHgO4ntBzPWu8mcHAvKJLs8o3AQw6eHTg==", "dev": true }, - "eslint-plugin-jsdoc": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-3.5.0.tgz", - "integrity": "sha512-qoNpVicVWGjGBXAJsqRoqVuAnajgX7PWtSa2Men36XKRiXe3RS/QmRv215PXZwo4OHskYOsUoJUeiPiWtS9ULA==", - "dev": true, - "requires": { - "comment-parser": "^0.4.2", - "lodash": "^4.17.4" - } - }, "eslint-plugin-jsx-a11y": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.0.2.tgz", @@ -7609,23 +7575,38 @@ "damerau-levenshtein": "^1.0.0", "emoji-regex": "^6.1.0", "jsx-ast-utils": "^1.4.0" - } - }, - "eslint-plugin-node": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-node/-/eslint-plugin-node-6.0.1.tgz", - "integrity": "sha512-Q/Cc2sW1OAISDS+Ji6lZS2KV4b7ueA/WydVWd1BECTQwVvfQy5JAi3glhINoKzoMnfnuRgNP+ZWKrGAbp3QDxw==", - "dev": true, - "requires": { - "ignore": "^3.3.6", - "minimatch": "^3.0.4", - "resolve": "^1.3.3", - "semver": "^5.4.1" + }, + "dependencies": { + "aria-query": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-0.7.1.tgz", + "integrity": "sha1-Jsu1r/ZBRLCoJb4YRuCxbPoAsR4=", + "dev": true, + "requires": { + "ast-types-flow": "0.0.7", + "commander": "^2.11.0" + } + }, + "axobject-query": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-0.1.0.tgz", + "integrity": "sha1-YvWdvFnJ+SQnWco0mWDnov48NsA=", + "dev": true, + "requires": { + "ast-types-flow": "0.0.7" + } + }, + "jsx-ast-utils": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz", + "integrity": "sha1-OGchPo3Xm/Ho8jAMDPwe+xgsDfE=", + "dev": true + } } }, "eslint-plugin-react": { "version": "7.7.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.7.0.tgz", + "resolved": "http://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.7.0.tgz", "integrity": "sha512-KC7Snr4YsWZD5flu6A5c0AcIZidzW3Exbqp7OT67OaD2AppJtlBr/GuPrW/vaQM/yfZotEvKAdrxrO+v8vwYJA==", "dev": true, "requires": { @@ -7635,15 +7616,6 @@ "prop-types": "^15.6.0" }, "dependencies": { - "jsx-ast-utils": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz", - "integrity": "sha1-6AGxs5mF4g//yHtA43SAgOLcrH8=", - "dev": true, - "requires": { - "array-includes": "^3.0.3" - } - }, "prop-types": { "version": "15.6.2", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.2.tgz", @@ -7656,27 +7628,6 @@ } } }, - "eslint-plugin-wordpress": { - "version": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#1774343f6226052a46b081e01db3fca8793cc9f1", - "from": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#1774343f6226052a46b081e01db3fca8793cc9f1", - "dev": true, - "requires": { - "eslint-plugin-i18n": "~1.2.0", - "eslint-plugin-jsdoc": "~3.5.0", - "eslint-plugin-node": "~6.0.1", - "eslint-plugin-wpcalypso": "~4.0.1", - "merge": "~1.2.0" - } - }, - "eslint-plugin-wpcalypso": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-wpcalypso/-/eslint-plugin-wpcalypso-4.0.1.tgz", - "integrity": "sha512-fU5NSc0XGdel/tlEIUoESOdqphBWQN2FfSgXXNHpXKX7ftTcqXacqgzXU8OVziyhXz6s2RUzK0+JSJaNxhZ+Mw==", - "dev": true, - "requires": { - "requireindex": "^1.1.0" - } - }, "eslint-scope": { "version": "3.7.3", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.3.tgz", @@ -13301,10 +13252,13 @@ } }, "jsx-ast-utils": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz", - "integrity": "sha1-OGchPo3Xm/Ho8jAMDPwe+xgsDfE=", - "dev": true + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-2.0.1.tgz", + "integrity": "sha1-6AGxs5mF4g//yHtA43SAgOLcrH8=", + "dev": true, + "requires": { + "array-includes": "^3.0.3" + } }, "keyv": { "version": "3.0.0", @@ -18625,12 +18579,6 @@ } } }, - "requireindex": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", - "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", - "dev": true - }, "resolve": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", diff --git a/package.json b/package.json index 41b226272d1bad..4b7ebb5d84f854 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "@wordpress/babel-preset-default": "file:packages/babel-preset-default", "@wordpress/browserslist-config": "file:packages/browserslist-config", "@wordpress/custom-templated-path-webpack-plugin": "file:packages/custom-templated-path-webpack-plugin", + "@wordpress/eslint-config": "file:packages/eslint-config", "@wordpress/jest-console": "file:packages/jest-console", "@wordpress/jest-preset-default": "file:packages/jest-preset-default", "@wordpress/library-export-default-webpack-plugin": "file:packages/library-export-default-webpack-plugin", @@ -80,11 +81,7 @@ "deasync": "0.1.13", "deep-freeze": "0.0.1", "doctrine": "2.1.0", - "eslint-config-wordpress": "2.0.0", "eslint-plugin-jest": "21.5.0", - "eslint-plugin-jsx-a11y": "6.0.2", - "eslint-plugin-react": "7.7.0", - "eslint-plugin-wordpress": "git://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress.git#1774343f6226052a46b081e01db3fca8793cc9f1", "espree": "3.5.4", "glob": "7.1.2", "husky": "0.14.3", diff --git a/packages/eslint-config/README.md b/packages/eslint-config/README.md new file mode 100644 index 00000000000000..e4d484632bc9d2 --- /dev/null +++ b/packages/eslint-config/README.md @@ -0,0 +1,24 @@ +# Eslint Config + +[Eslint](https://eslint.org/) config for WordPress development. + +## Installation + +Install the module + +```bash +npm install @wordpress/eslint-config --save-dev +``` + +### Usage + +Next, extend the configuration from your project's `.eslintrc` file: + +```json +"extends": "@wordpress/eslint-config" +``` + +Refer to the [ESLint documentation on Shareable Configs](http://eslint.org/docs/developer-guide/shareable-configs) for more information. + + +

Code is Poetry.

diff --git a/packages/eslint-config/configs/esnext.js b/packages/eslint-config/configs/esnext.js new file mode 100644 index 00000000000000..d762a5095968ca --- /dev/null +++ b/packages/eslint-config/configs/esnext.js @@ -0,0 +1,7 @@ +module.exports = { + env: { + es6: true, + }, + + rules: require( './rules/esnext' ), +}; diff --git a/packages/eslint-config/configs/rules/esnext.js b/packages/eslint-config/configs/rules/esnext.js new file mode 100644 index 00000000000000..dcfc27f06554f3 --- /dev/null +++ b/packages/eslint-config/configs/rules/esnext.js @@ -0,0 +1,66 @@ +// see https://eslint.org/docs/rules/#ecmascript-6 +// +module.exports = { + // require braces around arrow function bodies + 'arrow-body-style': 'off', + // require parentheses around arrow function arguments + 'arrow-parens': 'off', + // enforce consistent spacing before and after the arrow in arrow functions + 'arrow-spacing': 'off', + // require super() calls in constructors + 'constructor-super': 'error', + // enforce consistent spacing around * operators in generator functions + 'generator-star-spacing': 'off', + // disallow reassigning class members + 'no-class-assign': 'off', + // disallow arrow functions where they could be confused with comparisons + 'no-confusing-arrow': 'off', + // disallow reassigning `const` variables + 'no-const-assign': 'error', + // disallow duplicate class members + 'no-dupe-class-members': 'error', + // disallow duplicate module imports + 'no-duplicate-imports': 'error', + // disallow `new` operators with the `Symbol` object + 'no-new-symbol': 'off', + // disallow specified modules when loaded by `import` + 'no-restricted-imports': 'off', + // disallow `this`/`super` before calling `super()` in constructors + 'no-this-before-super': 'off', + // disallow unnecessary computed property keys in object literals + 'no-useless-computed-key': 'error', + // disallow unnecessary constructors + 'no-useless-constructor': 'error', + // disallow renaming import, export, and destructured assignments to the same name + 'no-useless-rename': 'off', + // require `let` or `const` instead of `var` + 'no-var': 'error', + // require or disallow method and property shorthand syntax for object literals + 'object-shorthand': 'off', + // require arrow functions as callbacks + 'prefer-arrow-callback': 'off', + // require `const` declarations for variables that are never reassigned after declared + 'prefer-const': 'error', + // require destructuring from arrays and/or objects + 'prefer-destructuring': 'off', + // disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals + 'prefer-numeric-literals': 'off', + // require rest parameters instead of `arguments` + 'prefer-rest-params': 'off', + // require spread operators instead of `.apply()` + 'prefer-spread': 'off', + // require template literals instead of string concatenation + 'prefer-template': 'off', + // require generator functions to contain `yield` + 'require-yield': 'off', + // enforce spacing between rest and spread operators and their expressions + 'rest-spread-spacing': 'off', + // enforce sorted import declarations within modules + 'sort-imports': 'off', + // require symbol descriptions + 'symbol-description': 'off', + // require or disallow spacing around embedded expressions of template strings + 'template-curly-spacing': [ 'error', 'always' ], + // require or disallow spacing around the `*` in `yield*` expressions + 'yield-star-spacing': 'off', +}; diff --git a/eslint/config.js b/packages/eslint-config/index.js similarity index 98% rename from eslint/config.js rename to packages/eslint-config/index.js index 5ba1ba4f43e843..551b6bdbc306e8 100644 --- a/eslint/config.js +++ b/packages/eslint-config/index.js @@ -2,13 +2,12 @@ module.exports = { parser: 'babel-eslint', extends: [ 'wordpress', - 'plugin:wordpress/esnext', + './configs/esnext.js', 'plugin:react/recommended', 'plugin:jsx-a11y/recommended', ], env: { browser: false, - es6: true, node: true, }, parserOptions: { @@ -22,7 +21,6 @@ module.exports = { document: true, }, plugins: [ - 'wordpress', 'react', 'jsx-a11y', ], diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json new file mode 100644 index 00000000000000..b055efd9670e3e --- /dev/null +++ b/packages/eslint-config/package.json @@ -0,0 +1,28 @@ +{ + "name": "@wordpress/eslint-config", + "version": "1.0.0-alpha.0", + "description": "Eslint config for WordPress development.", + "author": "The WordPress Contributors", + "license": "GPL-2.0-or-later", + "keywords": [ + "wordpress", + "eslint" + ], + "homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/eslint-config/README.md", + "repository": { + "type": "git", + "url": "https://github.com/WordPress/gutenberg.git" + }, + "bugs": { + "url": "https://github.com/WordPress/gutenberg/issues" + }, + "dependencies": { + "babel-eslint": "^8.0.3", + "eslint-config-wordpress": "2.0.0", + "eslint-plugin-jsx-a11y": "6.0.2", + "eslint-plugin-react": "7.7.0" + }, + "publishConfig": { + "access": "public" + } +}