diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js index e36e4020..5a200594 100644 --- a/src/__tests__/utils.js +++ b/src/__tests__/utils.js @@ -246,6 +246,29 @@ test("eslint max-len.tabWidth value should be used for tabWidth when tabs are us }); }); +test("Turn off prettier/prettier rule if found, but still infer options from it", () => { + const { eslint, prettier } = getOptionsForFormatting({ + rules: { + "prettier/prettier": [ + 2, + { + trailingComma: "all" + } + ] + } + }); + + expect(eslint).toMatchObject({ + rules: { + "prettier/prettier": ["off"] + } + }); + + expect(prettier).toMatchObject({ + trailingComma: "all" + }); +}); + test("eslint config has only necessary properties", () => { const { eslint } = getOptionsForFormatting({ globals: ["window:false"], diff --git a/src/utils.js b/src/utils.js index 9970f1e1..4542d746 100644 --- a/src/utils.js +++ b/src/utils.js @@ -64,12 +64,22 @@ function getOptionsForFormatting( prettierOptions = {}, fallbackPrettierOptions = {} ) { - const eslint = getRelevantESLintConfig(eslintConfig); + let eslint = getRelevantESLintConfig(eslintConfig); const prettier = getPrettierOptionsFromESLintRules( eslintConfig, prettierOptions, fallbackPrettierOptions ); + + // Disable "prettier/prettier", we don't need to run prettier twice + eslint = { + ...eslint, + rules: { + ...eslint.rules, + "prettier/prettier": ["off"] + } + }; + return { eslint, prettier }; }