diff --git a/.eslintrc.base.js b/.eslintrc.base.js index e642e0b..a17afc8 100644 --- a/.eslintrc.base.js +++ b/.eslintrc.base.js @@ -7,6 +7,8 @@ const config = require("."); +const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED; + module.exports = { extends: [ "google", @@ -68,6 +70,19 @@ module.exports = { "object-curly-spacing": "off", "babel/object-curly-spacing": ["error", "never"], "@babel/object-curly-spacing": ["error", "never"], + + // Workaround: These rules are deprecated, but added by eslint-config-google. + // We have to exclude them when testing the flat config, but also turn them + // off for the linting tests to pass. It’s time to get rid of eslint-config-google + // (their GitHub repo is archived as well). + ...(includeDeprecated + ? {} + : { + "comma-dangle": "off", + "max-len": "off", + "operator-linebreak": "off", + "quotes": "off", + }), }, overrides: [ { diff --git a/README.md b/README.md index 240cf56..259d354 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ Example ESLint configuration: } ``` -### [lines-around-comment] +### [lines-around-comment] \(deprecated) (The following applies to [@typescript-eslint/lines-around-comment] as well.) @@ -334,7 +334,7 @@ Example ESLint configuration: } ``` -### [max-len] +### [max-len] \(deprecated) (The following applies to [vue/max-len] as well.) @@ -357,7 +357,7 @@ Example ESLint configuration: } ``` -### [no-confusing-arrow] +### [no-confusing-arrow] \(deprecated) **This rule requires certain options.** @@ -407,7 +407,7 @@ Example ESLint configuration: (Note: The CLI helper tool considers `{allowParens: true}` to be the default, which is the case since ESLint 6.0.0. The tool will produce a warning if you use the default even if you use an older version of ESLint. It doesn’t hurt to explicitly set `{allowParens: false}` even though it is technically redundant. This way you are prepared for a future ESLint upgrade and the CLI tool can be kept simple.) -### [no-mixed-operators] +### [no-mixed-operators] \(deprecated) **This rule requires special attention when writing code.** @@ -460,7 +460,7 @@ Example ESLint configuration: } ``` -### [no-tabs] +### [no-tabs] \(deprecated) **This rule requires certain options.** @@ -546,7 +546,7 @@ Example configuration: } ``` -### [quotes] +### [quotes] \(deprecated) (The following applies to [babel/quotes] and [@typescript-eslint/quotes] as well.) diff --git a/index.js b/index.js index 102ab60..73e4f71 100644 --- a/index.js +++ b/index.js @@ -2,85 +2,24 @@ const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED; +const specialRule = 0; + module.exports = { rules: { // The following rules can be used in some cases. See the README for more - // information. (These are marked with `0` instead of `"off"` so that a - // script can distinguish them.) - "curly": 0, - "lines-around-comment": 0, - "max-len": 0, - "no-confusing-arrow": 0, - "no-mixed-operators": 0, - "no-tabs": 0, - "no-unexpected-multiline": 0, - "quotes": 0, - "@typescript-eslint/lines-around-comment": 0, - "@typescript-eslint/quotes": 0, - "babel/quotes": 0, - "unicorn/template-indent": 0, - "vue/html-self-closing": 0, - "vue/max-len": 0, + // information. These are marked with `0` instead of `"off"` so that a + // script can distinguish them. Note that there are a few more of these + // in the deprecated section below. + "curly": specialRule, + "no-unexpected-multiline": specialRule, + "@typescript-eslint/lines-around-comment": specialRule, + "@typescript-eslint/quotes": specialRule, + "babel/quotes": specialRule, + "unicorn/template-indent": specialRule, + "vue/html-self-closing": specialRule, + "vue/max-len": specialRule, // The rest are rules that you never need to enable when using Prettier. - "array-bracket-newline": "off", - "array-bracket-spacing": "off", - "array-element-newline": "off", - "arrow-parens": "off", - "arrow-spacing": "off", - "block-spacing": "off", - "brace-style": "off", - "comma-dangle": "off", - "comma-spacing": "off", - "comma-style": "off", - "computed-property-spacing": "off", - "dot-location": "off", - "eol-last": "off", - "func-call-spacing": "off", - "function-call-argument-newline": "off", - "function-paren-newline": "off", - "generator-star-spacing": "off", - "implicit-arrow-linebreak": "off", - "indent": "off", - "jsx-quotes": "off", - "key-spacing": "off", - "keyword-spacing": "off", - "linebreak-style": "off", - "max-statements-per-line": "off", - "multiline-ternary": "off", - "newline-per-chained-call": "off", - "new-parens": "off", - "no-extra-parens": "off", - "no-extra-semi": "off", - "no-floating-decimal": "off", - "no-mixed-spaces-and-tabs": "off", - "no-multi-spaces": "off", - "no-multiple-empty-lines": "off", - "no-trailing-spaces": "off", - "no-whitespace-before-property": "off", - "nonblock-statement-body-position": "off", - "object-curly-newline": "off", - "object-curly-spacing": "off", - "object-property-newline": "off", - "one-var-declaration-per-line": "off", - "operator-linebreak": "off", - "padded-blocks": "off", - "quote-props": "off", - "rest-spread-spacing": "off", - "semi": "off", - "semi-spacing": "off", - "semi-style": "off", - "space-before-blocks": "off", - "space-before-function-paren": "off", - "space-in-parens": "off", - "space-infix-ops": "off", - "space-unary-ops": "off", - "switch-colon-spacing": "off", - "template-curly-spacing": "off", - "template-tag-spacing": "off", - "wrap-iife": "off", - "wrap-regex": "off", - "yield-star-spacing": "off", "@babel/object-curly-spacing": "off", "@babel/semi": "off", "@typescript-eslint/block-spacing": "off", @@ -173,51 +112,103 @@ module.exports = { "vue/template-curly-spacing": "off", ...(includeDeprecated && { + // Removed in version 0.10.0. + // https://eslint.org/docs/latest/rules/space-unary-word-ops + "space-unary-word-ops": "off", + // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/generator-star + // https://github.com/eslint/eslint/issues/1898 "generator-star": "off", - // Deprecated since version 4.0.0. - // https://github.com/eslint/eslint/pull/8286 - "indent-legacy": "off", - // Removed in version 2.0.0. - // https://eslint.org/docs/latest/rules/no-arrow-condition - "no-arrow-condition": "off", - // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/no-comma-dangle "no-comma-dangle": "off", - // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/no-reserved-keys "no-reserved-keys": "off", - // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/no-space-before-semi "no-space-before-semi": "off", - // Deprecated since version 3.3.0. - // https://eslint.org/docs/rules/no-spaced-func - "no-spaced-func": "off", - // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/no-wrap-func "no-wrap-func": "off", - // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/space-after-function-name "space-after-function-name": "off", - // Removed in version 2.0.0. - // https://eslint.org/docs/latest/rules/space-after-keywords - "space-after-keywords": "off", - // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/space-before-function-parentheses "space-before-function-parentheses": "off", - // Removed in version 2.0.0. - // https://eslint.org/docs/latest/rules/space-before-keywords - "space-before-keywords": "off", - // Removed in version 1.0.0. - // https://eslint.org/docs/latest/rules/space-in-brackets "space-in-brackets": "off", + // Removed in version 2.0.0. - // https://eslint.org/docs/latest/rules/space-return-throw-case + // https://github.com/eslint/eslint/issues/5032 + "no-arrow-condition": "off", + "space-after-keywords": "off", + "space-before-keywords": "off", "space-return-throw-case": "off", - // Removed in version 0.10.0. - // https://eslint.org/docs/latest/rules/space-unary-word-ops - "space-unary-word-ops": "off", + + // Deprecated since version 3.3.0. + // https://eslint.org/docs/rules/no-spaced-func + "no-spaced-func": "off", + + // Deprecated since version 4.0.0. + // https://github.com/eslint/eslint/pull/8286 + "indent-legacy": "off", + + // Deprecated since version 8.53.0. + // https://eslint.org/blog/2023/10/deprecating-formatting-rules/ + "array-bracket-newline": "off", + "array-bracket-spacing": "off", + "array-element-newline": "off", + "arrow-parens": "off", + "arrow-spacing": "off", + "block-spacing": "off", + "brace-style": "off", + "comma-dangle": "off", + "comma-spacing": "off", + "comma-style": "off", + "computed-property-spacing": "off", + "dot-location": "off", + "eol-last": "off", + "func-call-spacing": "off", + "function-call-argument-newline": "off", + "function-paren-newline": "off", + "generator-star-spacing": "off", + "implicit-arrow-linebreak": "off", + "indent": "off", + "jsx-quotes": "off", + "key-spacing": "off", + "keyword-spacing": "off", + "linebreak-style": "off", + "lines-around-comment": specialRule, + "max-len": specialRule, + "max-statements-per-line": "off", + "multiline-ternary": "off", + "new-parens": "off", + "newline-per-chained-call": "off", + "no-confusing-arrow": specialRule, + "no-extra-parens": "off", + "no-extra-semi": "off", + "no-floating-decimal": "off", + "no-mixed-operators": specialRule, + "no-mixed-spaces-and-tabs": "off", + "no-multi-spaces": "off", + "no-multiple-empty-lines": "off", + "no-tabs": specialRule, + "no-trailing-spaces": "off", + "no-whitespace-before-property": "off", + "nonblock-statement-body-position": "off", + "object-curly-newline": "off", + "object-curly-spacing": "off", + "object-property-newline": "off", + "one-var-declaration-per-line": "off", + "operator-linebreak": "off", + "padded-blocks": "off", + "quote-props": "off", + "quotes": specialRule, + "rest-spread-spacing": "off", + "semi": "off", + "semi-spacing": "off", + "semi-style": "off", + "space-before-blocks": "off", + "space-before-function-paren": "off", + "space-in-parens": "off", + "space-infix-ops": "off", + "space-unary-ops": "off", + "switch-colon-spacing": "off", + "template-curly-spacing": "off", + "template-tag-spacing": "off", + "wrap-iife": "off", + "wrap-regex": "off", + "yield-star-spacing": "off", + // Deprecated since version 7.0.0. // https://github.com/yannickcr/eslint-plugin-react/blob/master/CHANGELOG.md#700---2017-05-06 "react/jsx-space-before-closing": "off", diff --git a/package-lock.json b/package-lock.json index ea29ebb..7ab0fb2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@babel/plugin-transform-react-jsx": "7.23.4", "@typescript-eslint/eslint-plugin": "6.13.1", "@typescript-eslint/parser": "6.13.1", - "eslint": "8.52.0", + "eslint": "8.55.0", "eslint-config-google": "0.14.0", "eslint-find-rules": "4.1.0", "eslint-plugin-babel": "5.3.1", @@ -669,9 +669,9 @@ } }, "node_modules/@eslint/js": { - "version": "8.52.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.52.0.tgz", - "integrity": "sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==", + "version": "8.55.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.55.0.tgz", + "integrity": "sha512-qQfo2mxH5yVom1kacMtZZJFVdW+E70mqHMJvVg6WTLo+VBuQJ4TojZlfWBjK0ve5BdEeNAVxOsl/nvNMpJOaJA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -3181,15 +3181,15 @@ } }, "node_modules/eslint": { - "version": "8.52.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz", - "integrity": "sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==", + "version": "8.55.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.55.0.tgz", + "integrity": "sha512-iyUUAM0PCKj5QpwGfmCAG9XXbZCWsqP/eWAWrG/W0umvjuLRBECwSFdt+rCntju0xEH7teIABPwXpahftIaTdA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.2", - "@eslint/js": "8.52.0", + "@eslint/eslintrc": "^2.1.4", + "@eslint/js": "8.55.0", "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", @@ -9314,9 +9314,9 @@ } }, "@eslint/js": { - "version": "8.52.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.52.0.tgz", - "integrity": "sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==", + "version": "8.55.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.55.0.tgz", + "integrity": "sha512-qQfo2mxH5yVom1kacMtZZJFVdW+E70mqHMJvVg6WTLo+VBuQJ4TojZlfWBjK0ve5BdEeNAVxOsl/nvNMpJOaJA==", "dev": true }, "@humanwhocodes/config-array": { @@ -11173,15 +11173,15 @@ "dev": true }, "eslint": { - "version": "8.52.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz", - "integrity": "sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==", + "version": "8.55.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.55.0.tgz", + "integrity": "sha512-iyUUAM0PCKj5QpwGfmCAG9XXbZCWsqP/eWAWrG/W0umvjuLRBECwSFdt+rCntju0xEH7teIABPwXpahftIaTdA==", "dev": true, "requires": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.2", - "@eslint/js": "8.52.0", + "@eslint/eslintrc": "^2.1.4", + "@eslint/js": "8.55.0", "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", diff --git a/package.json b/package.json index 6317d74..13a13d1 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "@babel/plugin-transform-react-jsx": "7.23.4", "@typescript-eslint/eslint-plugin": "6.13.1", "@typescript-eslint/parser": "6.13.1", - "eslint": "8.52.0", + "eslint": "8.55.0", "eslint-config-google": "0.14.0", "eslint-find-rules": "4.1.0", "eslint-plugin-babel": "5.3.1", diff --git a/test-lint/core.js b/test-lint/core.js index 60faab9..20073d1 100644 --- a/test-lint/core.js +++ b/test-lint/core.js @@ -1,2 +1,5 @@ -// Prettier wants double quotes, but `eslint-config-google` wants single quotes. "use strict"; + +// Prettier wants a newline after the condition, but `eslint-config-google` does not. +if (cart.items && cart.items[0] && cart.items[0].quantity === 0) + updateCart(cart); diff --git a/test/cli.test.js b/test/cli.test.js index 8bbc510..8962565 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -41,7 +41,7 @@ describe("does not flag", () => { }); describe("does flag", () => { - const rules = ["strict", "arrow-parens"]; + const rules = ["strict", "unicorn/empty-brace-spaces"]; const results = onPatterns.map((pattern) => ({ pattern: JSON.stringify(pattern), @@ -54,7 +54,7 @@ describe("does flag", () => { "code": 2, "stdout": "The following rules are unnecessary or might conflict with Prettier: - - arrow-parens", + - unicorn/empty-brace-spaces", } `); }); @@ -90,14 +90,14 @@ test("conflicting options", () => { }); test("special rules", () => { - const rules = ["strict", "max-len"]; + const rules = ["strict", "no-unexpected-multiline"]; expect(cli.processRules(createRules(rules, "error"))).toMatchInlineSnapshot(` { "code": 0, "stdout": "The following rules are enabled but cannot be automatically checked. See: https://github.com/prettier/eslint-config-prettier#special-rules - - max-len + - no-unexpected-multiline Other than that, no rules that are unnecessary or conflict with Prettier were found.", } @@ -128,7 +128,33 @@ test("all the things", () => { "arrow-body-style", "unicorn/template-indent", ]; - expect(cli.processRules(createRules(rules, "error"))).toMatchInlineSnapshot(` + + const result = cli.processRules(createRules(rules, "error")); + + if (process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED) { + expect(result).toMatchInlineSnapshot(` + { + "code": 2, + "stdout": "The following rules are unnecessary or might conflict with Prettier: + + - flowtype/semi + - react/jsx-indent + + The following rules are enabled with config that might conflict with Prettier. See: + https://github.com/prettier/eslint-config-prettier#special-rules + + - curly + - unicorn/template-indent + - vue/html-self-closing + + The following rules are enabled but cannot be automatically checked. See: + https://github.com/prettier/eslint-config-prettier#special-rules + + - no-unexpected-multiline", + } + `); + } else { + expect(result).toMatchInlineSnapshot(` { "code": 2, "stdout": "The following rules are unnecessary or might conflict with Prettier: @@ -157,6 +183,7 @@ test("all the things", () => { - quotes", } `); + } }); test("eslint-plugin-prettier", () => {