From bc65d4380007e75f17ea6dbc6f1c849dc0ed74f6 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Mon, 30 Nov 2020 21:55:16 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20warn=20about=20eslint-plugin-pr?= =?UTF-8?q?ettier=20rules=20if=20prettier/prettier=20is=20off?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli.js | 12 +++++++----- bin/validators.js | 8 ++++---- test/cli.test.js | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index f649336..a349193 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -84,17 +84,19 @@ function processRules(configRules) { (ruleName, value) => value === 0 && !(ruleName in validators) ); - const flaggedRules = configRules + const enabledRules = configRules .map(([ruleName, value, source]) => { const arrayValue = Array.isArray(value) ? value : [value]; const [level, ...options] = arrayValue; const isOff = level === "off" || level === 0; - return !isOff && ruleName in allRules - ? { ruleName, options, source } - : null; + return isOff ? null : { ruleName, options, source }; }) .filter(Boolean); + const flaggedRules = enabledRules.filter( + ({ ruleName }) => ruleName in allRules + ); + const regularFlaggedRuleNames = filterRuleNames( flaggedRules, (ruleName) => ruleName in regularRules @@ -103,7 +105,7 @@ function processRules(configRules) { flaggedRules, (ruleName, options, source) => ruleName in optionsRules && - !validators[ruleName](options, source, configRules) + !validators[ruleName](options, source, enabledRules) ); const specialFlaggedRuleNames = filterRuleNames( flaggedRules, diff --git a/bin/validators.js b/bin/validators.js index 5339d33..4c89221 100644 --- a/bin/validators.js +++ b/bin/validators.js @@ -66,9 +66,9 @@ module.exports = { }, }; -function checkEslintConfigPrettier(_options, source, rules) { - return !rules.some( - ([name, _options2, source2]) => - name === "prettier/prettier" && source === source2 +function checkEslintConfigPrettier(_options, currentSource, enabledRules) { + return !enabledRules.some( + ({ ruleName, source }) => + ruleName === "prettier/prettier" && currentSource === source ); } diff --git a/test/cli.test.js b/test/cli.test.js index 02c72c3..6971758 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -193,3 +193,18 @@ test("eslint-plugin-prettier no warnings because different sources", () => { } `); }); + +test("eslint-plugin-prettier no warnings because the rule is off", () => { + expect( + cli.processRules([ + ["prettier/prettier", [0, {}], "test-source.js"], + ["arrow-body-style", "error", "test-source.js"], + ["prefer-arrow-callback", "error", "test-source.js"], + ]) + ).toMatchInlineSnapshot(` + Object { + "code": 0, + "stdout": "No rules that are unnecessary or conflict with Prettier were found.", + } + `); +});