Skip to content

Commit

Permalink
Update tests to handle newly deprecated rules
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell committed Dec 2, 2023
1 parent 4c876b9 commit 6d0bd92
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

const config = require(".");

const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED;

module.exports = {
extends: [
"google",
Expand Down Expand Up @@ -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: [
{
Expand Down
5 changes: 4 additions & 1 deletion test-lint/core.js
Original file line number Diff line number Diff line change
@@ -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);
37 changes: 32 additions & 5 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
}
`);
});
Expand Down Expand Up @@ -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.",
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -157,6 +183,7 @@ test("all the things", () => {
- quotes",
}
`);
}
});

test("eslint-plugin-prettier", () => {
Expand Down

0 comments on commit 6d0bd92

Please sign in to comment.