Skip to content

Commit

Permalink
Don’t warn about eslint-plugin-prettier rules if prettier/prettier is…
Browse files Browse the repository at this point in the history
… off
  • Loading branch information
lydell committed Nov 30, 2020
1 parent dcba135 commit bc65d43
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
12 changes: 7 additions & 5 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions bin/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
15 changes: 15 additions & 0 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
}
`);
});

0 comments on commit bc65d43

Please sign in to comment.