From ca7a240de5d7e7db8d02520eeee329e4c37bbb8c Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Sat, 14 Jul 2018 18:08:19 +0200 Subject: [PATCH 1/5] Packages: Extract Eslint config package --- .eslintrc.js | 2 +- package-lock.json | 142 ++++++------------ package.json | 5 +- packages/eslint-config/README.md | 24 +++ packages/eslint-config/configs/esnext.js | 7 + .../eslint-config/configs/rules/esnext.js | 66 ++++++++ .../eslint-config/index.js | 4 +- packages/eslint-config/package.json | 28 ++++ 8 files changed, 173 insertions(+), 105 deletions(-) create mode 100644 packages/eslint-config/README.md create mode 100644 packages/eslint-config/configs/esnext.js create mode 100644 packages/eslint-config/configs/rules/esnext.js rename eslint/config.js => packages/eslint-config/index.js (98%) create mode 100644 packages/eslint-config/package.json diff --git a/.eslintrc.js b/.eslintrc.js index 45fc4c94140f1..285f4668eb53b 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 ab4562395d1a1..76c837ce7cf51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2590,6 +2590,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": { @@ -3055,16 +3065,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", @@ -3323,15 +3323,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", @@ -5671,15 +5662,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", @@ -7571,28 +7553,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", @@ -7606,23 +7572,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": { @@ -7632,15 +7613,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", @@ -7653,27 +7625,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", @@ -13298,10 +13249,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", @@ -18617,12 +18571,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 41b226272d1ba..4b7ebb5d84f85 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 0000000000000..e4d484632bc9d --- /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 0000000000000..d762a5095968c --- /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 0000000000000..dcfc27f06554f --- /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 5ba1ba4f43e84..551b6bdbc306e 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 0000000000000..b055efd9670e3 --- /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" + } +} From c1bea47bed396831dc17ce01984993dfcc82467d Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 27 Nov 2018 16:06:04 +0100 Subject: [PATCH 2/5] Copy config from eslint-config-wordpress --- package-lock.json | 7 -- packages/eslint-config/configs/esnext.js | 5 + packages/eslint-config/configs/wordpress.js | 103 ++++++++++++++++++++ packages/eslint-config/index.js | 2 +- packages/eslint-config/package.json | 1 - 5 files changed, 109 insertions(+), 9 deletions(-) create mode 100644 packages/eslint-config/configs/wordpress.js diff --git a/package-lock.json b/package-lock.json index 76c837ce7cf51..92f84cbe3e34e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2595,7 +2595,6 @@ "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" } @@ -7547,12 +7546,6 @@ } } }, - "eslint-config-wordpress": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-wordpress/-/eslint-config-wordpress-2.0.0.tgz", - "integrity": "sha1-UgEgbGlk1kgxUjLt9t+9LpJeTNY=", - "dev": true - }, "eslint-plugin-jest": { "version": "21.5.0", "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-21.5.0.tgz", diff --git a/packages/eslint-config/configs/esnext.js b/packages/eslint-config/configs/esnext.js index d762a5095968c..2e56e7a2f5fcd 100644 --- a/packages/eslint-config/configs/esnext.js +++ b/packages/eslint-config/configs/esnext.js @@ -1,3 +1,8 @@ +/** + * The original version of this file is based on WordPress ESLint rules and shared configs: + * https://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress. + */ + module.exports = { env: { es6: true, diff --git a/packages/eslint-config/configs/wordpress.js b/packages/eslint-config/configs/wordpress.js new file mode 100644 index 0000000000000..486bfde23c1f8 --- /dev/null +++ b/packages/eslint-config/configs/wordpress.js @@ -0,0 +1,103 @@ +/** + * The original version of this file is based on ESLint shareable config for WordPress: + * https://github.com/WordPress-Coding-Standards/eslint-config-wordpress. + */ + +module.exports = { + env: { + browser: true, + }, + + globals: { + _: false, + Backbone: false, + jQuery: false, + JSON: false, + wp: false, + }, + + rules: { + // Possible Errors + // Disallow assignment in conditional expressions + 'no-cond-assign': [ 'error', 'except-parens' ], + // Disallow irregular whitespace outside of strings and comments + 'no-irregular-whitespace': 'error', + // Best Practices + // Specify curly brace conventions for all control statements + curly: [ 'error', 'all' ], + // Encourages use of dot notation whenever possible + 'dot-notation': [ 'error', { + allowKeywords: true, + allowPattern: '^[a-z]+(_[a-z]+)+$', + } ], + // Disallow use of multiline strings + 'no-multi-str': 'error', + // Disallow use of the with statement + 'no-with': 'error', + // Requires to declare all vars on top of their containing scope + 'vars-on-top': 'error', + // Require immediate function invocation to be wrapped in parentheses + 'wrap-iife': 'error', + // Require or disallow Yoda conditions + yoda: [ 'error', 'always' ], + // Strict Mode + // Variables + // Stylistic Issues + // Enforce spacing inside array brackets + 'array-bracket-spacing': [ 'error', 'always' ], + // Enforce one true brace style + 'brace-style': 'error', + // Require camel case names + camelcase: [ 'error', { + properties: 'always', + } ], + // Disallow or enforce trailing commas + 'comma-dangle': [ 'error', 'never' ], + // Enforce spacing before and after comma + 'comma-spacing': 'error', + // Enforce one true comma style + 'comma-style': [ 'error', 'last' ], + // Enforce newline at the end of file, with no multiple empty lines + 'eol-last': 'error', + // Enforces spacing between keys and values in object literal properties + 'key-spacing': [ 'error', { + beforeColon: false, + afterColon: true, + } ], + // Enforce spacing before and after keywords + 'keyword-spacing': 'error', + // Disallow mixed "LF" and "CRLF" as linebreaks + 'linebreak-style': [ 'error', 'unix' ], + // Enforces empty lines around comments + 'lines-around-comment': [ 'error', { + beforeLineComment: true, + } ], + // Disallow mixed spaces and tabs for indentation + 'no-mixed-spaces-and-tabs': 'error', + // Disallow multiple empty lines + 'no-multiple-empty-lines': 'error', + // Disallow trailing whitespace at the end of lines + 'no-trailing-spaces': 'error', + // Require or disallow an newline around variable declarations + 'one-var-declaration-per-line': [ 'error', 'initializations' ], + // Enforce operators to be placed before or after line breaks + 'operator-linebreak': [ 'error', 'after' ], + // Specify whether backticks, double or single quotes should be used + quotes: [ 'error', 'single' ], + // Require or disallow use of semicolons instead of ASI + semi: [ 'error', 'always' ], + // Require or disallow space before blocks + 'space-before-blocks': [ 'error', 'always' ], + // Require or disallow space before function opening parenthesis + 'space-before-function-paren': [ 'error', 'never' ], + // Require or disallow space before blocks + 'space-in-parens': [ 'error', 'always', { exceptions: [ '{}', '[]' ] } ], + // Require spaces around operators + 'space-infix-ops': 'error', + // Require or disallow spaces before/after unary operators (words on by default, nonwords) + 'space-unary-ops': [ 'error', { + overrides: { '!': true }, + } ], + // Legacy + }, +}; diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index 551b6bdbc306e..8f796d9d6a6c7 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -1,7 +1,7 @@ module.exports = { parser: 'babel-eslint', extends: [ - 'wordpress', + './configs/wordpress.js', './configs/esnext.js', 'plugin:react/recommended', 'plugin:jsx-a11y/recommended', diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index b055efd9670e3..79fb5465e2c17 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -18,7 +18,6 @@ }, "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" }, From 0f78b5181a143f5903ae366bbb14f2280c92a40b Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Tue, 27 Nov 2018 16:19:50 +0100 Subject: [PATCH 3/5] Docs: Expose documentation for the newly added package --- docs/manifest.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/manifest.json b/docs/manifest.json index c461c5d3b9a36..e199fc740e32d 100644 --- a/docs/manifest.json +++ b/docs/manifest.json @@ -335,6 +335,12 @@ "markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/escape-html/README.md", "parent": "packages" }, + { + "title": "@wordpress/eslint-config", + "slug": "packages-eslint-config", + "markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/eslint-config/README.md", + "parent": "packages" + }, { "title": "@wordpress/format-library", "slug": "packages-format-library", From b1cfdc44f1302d58c3de63b1bff37bc41996b3de Mon Sep 17 00:00:00 2001 From: Grzegorz Ziolkowski Date: Wed, 28 Nov 2018 16:24:24 +0100 Subject: [PATCH 4/5] Remove no longer necessary globals from the Eslint config --- .eslintrc.js | 14 +-- packages/block-library/src/classic/edit.js | 2 + .../hooks/components/media-upload/index.js | 6 +- packages/eslint-config/configs/es5.js | 12 ++ packages/eslint-config/configs/esnext.js | 6 +- packages/eslint-config/configs/rules/es5.js | 84 ++++++++++++++ packages/eslint-config/configs/wordpress.js | 103 ------------------ packages/eslint-config/index.js | 3 +- 8 files changed, 110 insertions(+), 120 deletions(-) create mode 100644 packages/eslint-config/configs/es5.js create mode 100644 packages/eslint-config/configs/rules/es5.js delete mode 100644 packages/eslint-config/configs/wordpress.js diff --git a/.eslintrc.js b/.eslintrc.js index 285f4668eb53b..feced45620657 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -20,13 +20,7 @@ module.exports = { root: true, extends: [ '@wordpress/eslint-config', - 'plugin:jest/recommended' - ], - env: { - 'jest/globals': true, - }, - plugins: [ - 'jest', + 'plugin:jest/recommended', ], rules: { 'no-restricted-syntax': [ @@ -189,9 +183,13 @@ module.exports = { overrides: [ { files: [ 'test/e2e/**/*.js' ], + env: { + browser: true, + }, globals: { - page: true, browser: true, + page: true, + wp: true, }, }, ], diff --git a/packages/block-library/src/classic/edit.js b/packages/block-library/src/classic/edit.js index db1467b630139..2502c0f7e0eb5 100644 --- a/packages/block-library/src/classic/edit.js +++ b/packages/block-library/src/classic/edit.js @@ -5,6 +5,8 @@ import { Component } from '@wordpress/element'; import { __, _x } from '@wordpress/i18n'; import { BACKSPACE, DELETE, F10 } from '@wordpress/keycodes'; +const { wp } = window; + function isTmceEmpty( editor ) { // When tinyMce is empty the content seems to be: //


diff --git a/packages/edit-post/src/hooks/components/media-upload/index.js b/packages/edit-post/src/hooks/components/media-upload/index.js index 9160f4f84c15b..c855216803389 100644 --- a/packages/edit-post/src/hooks/components/media-upload/index.js +++ b/packages/edit-post/src/hooks/components/media-upload/index.js @@ -1,7 +1,7 @@ /** * External Dependencies */ -import { castArray, pick } from 'lodash'; +import { castArray, defaults, pick } from 'lodash'; /** * WordPress dependencies @@ -9,6 +9,8 @@ import { castArray, pick } from 'lodash'; import { Component } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; +const { wp } = window; + // Getter for the sake of unit tests. const getGalleryDetailsMediaFrame = () => { /** @@ -36,7 +38,7 @@ const getGalleryDetailsMediaFrame = () => { multiple: 'add', editable: false, - library: wp.media.query( _.defaults( { + library: wp.media.query( defaults( { type: 'image', }, this.options.library ) ), } ), diff --git a/packages/eslint-config/configs/es5.js b/packages/eslint-config/configs/es5.js new file mode 100644 index 0000000000000..2e56e7a2f5fcd --- /dev/null +++ b/packages/eslint-config/configs/es5.js @@ -0,0 +1,12 @@ +/** + * The original version of this file is based on WordPress ESLint rules and shared configs: + * https://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress. + */ + +module.exports = { + env: { + es6: true, + }, + + rules: require( './rules/esnext' ), +}; diff --git a/packages/eslint-config/configs/esnext.js b/packages/eslint-config/configs/esnext.js index 2e56e7a2f5fcd..3b3a80d7d4cd8 100644 --- a/packages/eslint-config/configs/esnext.js +++ b/packages/eslint-config/configs/esnext.js @@ -4,9 +4,5 @@ */ module.exports = { - env: { - es6: true, - }, - - rules: require( './rules/esnext' ), + rules: require( './rules/es5' ), }; diff --git a/packages/eslint-config/configs/rules/es5.js b/packages/eslint-config/configs/rules/es5.js new file mode 100644 index 0000000000000..61e3e01c343f1 --- /dev/null +++ b/packages/eslint-config/configs/rules/es5.js @@ -0,0 +1,84 @@ +module.exports = { + // Possible Errors + // Disallow assignment in conditional expressions + 'no-cond-assign': [ 'error', 'except-parens' ], + // Disallow irregular whitespace outside of strings and comments + 'no-irregular-whitespace': 'error', + // Best Practices + // Specify curly brace conventions for all control statements + curly: [ 'error', 'all' ], + // Encourages use of dot notation whenever possible + 'dot-notation': [ 'error', { + allowKeywords: true, + allowPattern: '^[a-z]+(_[a-z]+)+$', + } ], + // Disallow use of multiline strings + 'no-multi-str': 'error', + // Disallow use of the with statement + 'no-with': 'error', + // Requires to declare all vars on top of their containing scope + 'vars-on-top': 'error', + // Require immediate function invocation to be wrapped in parentheses + 'wrap-iife': 'error', + // Require or disallow Yoda conditions + yoda: [ 'error', 'always' ], + // Strict Mode + // Variables + // Stylistic Issues + // Enforce spacing inside array brackets + 'array-bracket-spacing': [ 'error', 'always' ], + // Enforce one true brace style + 'brace-style': 'error', + // Require camel case names + camelcase: [ 'error', { + properties: 'always', + } ], + // Disallow or enforce trailing commas + 'comma-dangle': [ 'error', 'never' ], + // Enforce spacing before and after comma + 'comma-spacing': 'error', + // Enforce one true comma style + 'comma-style': [ 'error', 'last' ], + // Enforce newline at the end of file, with no multiple empty lines + 'eol-last': 'error', + // Enforces spacing between keys and values in object literal properties + 'key-spacing': [ 'error', { + beforeColon: false, + afterColon: true, + } ], + // Enforce spacing before and after keywords + 'keyword-spacing': 'error', + // Disallow mixed "LF" and "CRLF" as linebreaks + 'linebreak-style': [ 'error', 'unix' ], + // Enforces empty lines around comments + 'lines-around-comment': [ 'error', { + beforeLineComment: true, + } ], + // Disallow mixed spaces and tabs for indentation + 'no-mixed-spaces-and-tabs': 'error', + // Disallow multiple empty lines + 'no-multiple-empty-lines': 'error', + // Disallow trailing whitespace at the end of lines + 'no-trailing-spaces': 'error', + // Require or disallow an newline around variable declarations + 'one-var-declaration-per-line': [ 'error', 'initializations' ], + // Enforce operators to be placed before or after line breaks + 'operator-linebreak': [ 'error', 'after' ], + // Specify whether backticks, double or single quotes should be used + quotes: [ 'error', 'single' ], + // Require or disallow use of semicolons instead of ASI + semi: [ 'error', 'always' ], + // Require or disallow space before blocks + 'space-before-blocks': [ 'error', 'always' ], + // Require or disallow space before function opening parenthesis + 'space-before-function-paren': [ 'error', 'never' ], + // Require or disallow space before blocks + 'space-in-parens': [ 'error', 'always', { exceptions: [ '{}', '[]' ] } ], + // Require spaces around operators + 'space-infix-ops': 'error', + // Require or disallow spaces before/after unary operators (words on by default, nonwords) + 'space-unary-ops': [ 'error', { + overrides: { '!': true }, + } ], + // Legacy +}; diff --git a/packages/eslint-config/configs/wordpress.js b/packages/eslint-config/configs/wordpress.js deleted file mode 100644 index 486bfde23c1f8..0000000000000 --- a/packages/eslint-config/configs/wordpress.js +++ /dev/null @@ -1,103 +0,0 @@ -/** - * The original version of this file is based on ESLint shareable config for WordPress: - * https://github.com/WordPress-Coding-Standards/eslint-config-wordpress. - */ - -module.exports = { - env: { - browser: true, - }, - - globals: { - _: false, - Backbone: false, - jQuery: false, - JSON: false, - wp: false, - }, - - rules: { - // Possible Errors - // Disallow assignment in conditional expressions - 'no-cond-assign': [ 'error', 'except-parens' ], - // Disallow irregular whitespace outside of strings and comments - 'no-irregular-whitespace': 'error', - // Best Practices - // Specify curly brace conventions for all control statements - curly: [ 'error', 'all' ], - // Encourages use of dot notation whenever possible - 'dot-notation': [ 'error', { - allowKeywords: true, - allowPattern: '^[a-z]+(_[a-z]+)+$', - } ], - // Disallow use of multiline strings - 'no-multi-str': 'error', - // Disallow use of the with statement - 'no-with': 'error', - // Requires to declare all vars on top of their containing scope - 'vars-on-top': 'error', - // Require immediate function invocation to be wrapped in parentheses - 'wrap-iife': 'error', - // Require or disallow Yoda conditions - yoda: [ 'error', 'always' ], - // Strict Mode - // Variables - // Stylistic Issues - // Enforce spacing inside array brackets - 'array-bracket-spacing': [ 'error', 'always' ], - // Enforce one true brace style - 'brace-style': 'error', - // Require camel case names - camelcase: [ 'error', { - properties: 'always', - } ], - // Disallow or enforce trailing commas - 'comma-dangle': [ 'error', 'never' ], - // Enforce spacing before and after comma - 'comma-spacing': 'error', - // Enforce one true comma style - 'comma-style': [ 'error', 'last' ], - // Enforce newline at the end of file, with no multiple empty lines - 'eol-last': 'error', - // Enforces spacing between keys and values in object literal properties - 'key-spacing': [ 'error', { - beforeColon: false, - afterColon: true, - } ], - // Enforce spacing before and after keywords - 'keyword-spacing': 'error', - // Disallow mixed "LF" and "CRLF" as linebreaks - 'linebreak-style': [ 'error', 'unix' ], - // Enforces empty lines around comments - 'lines-around-comment': [ 'error', { - beforeLineComment: true, - } ], - // Disallow mixed spaces and tabs for indentation - 'no-mixed-spaces-and-tabs': 'error', - // Disallow multiple empty lines - 'no-multiple-empty-lines': 'error', - // Disallow trailing whitespace at the end of lines - 'no-trailing-spaces': 'error', - // Require or disallow an newline around variable declarations - 'one-var-declaration-per-line': [ 'error', 'initializations' ], - // Enforce operators to be placed before or after line breaks - 'operator-linebreak': [ 'error', 'after' ], - // Specify whether backticks, double or single quotes should be used - quotes: [ 'error', 'single' ], - // Require or disallow use of semicolons instead of ASI - semi: [ 'error', 'always' ], - // Require or disallow space before blocks - 'space-before-blocks': [ 'error', 'always' ], - // Require or disallow space before function opening parenthesis - 'space-before-function-paren': [ 'error', 'never' ], - // Require or disallow space before blocks - 'space-in-parens': [ 'error', 'always', { exceptions: [ '{}', '[]' ] } ], - // Require spaces around operators - 'space-infix-ops': 'error', - // Require or disallow spaces before/after unary operators (words on by default, nonwords) - 'space-unary-ops': [ 'error', { - overrides: { '!': true }, - } ], - // Legacy - }, -}; diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index 8f796d9d6a6c7..aa02fdc33ff9d 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -1,13 +1,12 @@ module.exports = { parser: 'babel-eslint', extends: [ - './configs/wordpress.js', + './configs/es5.js', './configs/esnext.js', 'plugin:react/recommended', 'plugin:jsx-a11y/recommended', ], env: { - browser: false, node: true, }, parserOptions: { From 6d88a8da7a50b2b4677dfd34839632fd360824da Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Fri, 30 Nov 2018 10:19:18 +0100 Subject: [PATCH 5/5] Apply suggestions from code review Fix ESLint typo Kudos to @ntwb for catching Co-Authored-By: gziolo --- packages/eslint-config/README.md | 4 ++-- packages/eslint-config/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-config/README.md b/packages/eslint-config/README.md index e4d484632bc9d..5f2b003e765c5 100644 --- a/packages/eslint-config/README.md +++ b/packages/eslint-config/README.md @@ -1,6 +1,6 @@ -# Eslint Config +# ESLint Config -[Eslint](https://eslint.org/) config for WordPress development. +[ESLint](https://eslint.org/) config for WordPress development. ## Installation diff --git a/packages/eslint-config/package.json b/packages/eslint-config/package.json index 79fb5465e2c17..07a609d7278fa 100644 --- a/packages/eslint-config/package.json +++ b/packages/eslint-config/package.json @@ -1,7 +1,7 @@ { "name": "@wordpress/eslint-config", "version": "1.0.0-alpha.0", - "description": "Eslint config for WordPress development.", + "description": "ESLint config for WordPress development.", "author": "The WordPress Contributors", "license": "GPL-2.0-or-later", "keywords": [