From 6d0bd9294aeeea34cf9004bde2e6cb79883141fa Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 2 Dec 2023 10:20:25 +0100 Subject: [PATCH] Update tests to handle newly deprecated rules --- .eslintrc.base.js | 15 +++++++++++++++ test-lint/core.js | 5 ++++- test/cli.test.js | 37 ++++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 6 deletions(-) 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/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", () => {