Skip to content

Commit

Permalink
Various cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
lydell committed Dec 5, 2020
1 parent 0d0b1ac commit bd551b9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"use strict";

// This file is only used in `./.eslintrc.js` and in the tests – it’s not part
// of the eslint-config-prettier npm package.

const fs = require("fs");

module.exports = {
Expand Down
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"use strict";

// This is the internal ESLint config for this project itself – it’s not part of
// the eslint-config-prettier npm package. The idea here is to extends some
// sharable config from npm and then include the configs exposed by this package
// as an “eat your own dogfood” test. That feels like a good test, but
// complicates things a little sometimes.

const fs = require("fs");

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ You can also supply a custom message if you want:
eslint-config-prettier has been tested with:

- ESLint 7.14.0
- eslint-config-prettier 7.0.0 requires ESLint 7.0.0 or newer, while eslint-config-prettier 6.15.0 and older should also work with ESLint versions down to 3.x.
- eslint-config-prettier 6.11.0 and older were tested with ESLint 6.x
- eslint-config-prettier 5.1.0 and older were tested with ESLint 5.x
- eslint-config-prettier 2.10.0 and older were tested with ESLint 4.x
Expand Down
15 changes: 5 additions & 10 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,16 @@ function processRules(configRules) {

const regularFlaggedRuleNames = filterRuleNames(
flaggedRules,
(ruleName) => ruleName in regularRules
({ ruleName }) => ruleName in regularRules
);
const optionsFlaggedRuleNames = filterRuleNames(
flaggedRules,
(ruleName, options, source) =>
ruleName in optionsRules &&
!validators[ruleName](options, source, enabledRules)
({ ruleName, ...rule }) =>
ruleName in optionsRules && !validators[ruleName](rule, enabledRules)
);
const specialFlaggedRuleNames = filterRuleNames(
flaggedRules,
(ruleName) => ruleName in specialRules
({ ruleName }) => ruleName in specialRules
);

if (
Expand Down Expand Up @@ -187,11 +186,7 @@ function filterRules(rules, fn) {

function filterRuleNames(rules, fn) {
return [
...new Set(
rules
.filter((rule) => fn(rule.ruleName, rule.options, rule.source))
.map((rule) => rule.ruleName)
),
...new Set(rules.filter((rule) => fn(rule)).map((rule) => rule.ruleName)),
];
}

Expand Down
16 changes: 8 additions & 8 deletions bin/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// `false` if the options DO conflict with Prettier, and `true` if they don’t.

module.exports = {
"arrow-body-style": checkEslintConfigPrettier,
"arrow-body-style": checkEslintPluginPrettier,

curly(options) {
curly({ options }) {
if (options.length === 0) {
return true;
}
Expand All @@ -15,7 +15,7 @@ module.exports = {
return firstOption !== "multi-line" && firstOption !== "multi-or-nest";
},

"lines-around-comment"(options) {
"lines-around-comment"({ options }) {
if (options.length === 0) {
return false;
}
Expand All @@ -32,7 +32,7 @@ module.exports = {
);
},

"no-confusing-arrow"(options) {
"no-confusing-arrow"({ options }) {
if (options.length === 0) {
return false;
}
Expand All @@ -41,7 +41,7 @@ module.exports = {
return firstOption ? firstOption.allowParens === false : false;
},

"no-tabs"(options) {
"no-tabs"({ options }) {
if (options.length === 0) {
return false;
}
Expand All @@ -50,9 +50,9 @@ module.exports = {
return Boolean(firstOption && firstOption.allowIndentationTabs);
},

"prefer-arrow-callback": checkEslintConfigPrettier,
"prefer-arrow-callback": checkEslintPluginPrettier,

"vue/html-self-closing"(options) {
"vue/html-self-closing"({ options }) {
if (options.length === 0) {
return false;
}
Expand All @@ -66,7 +66,7 @@ module.exports = {
},
};

function checkEslintConfigPrettier(_options, currentSource, enabledRules) {
function checkEslintPluginPrettier({ source: currentSource }, enabledRules) {
return !enabledRules.some(
({ ruleName, source }) =>
ruleName === "prettier/prettier" && currentSource === source
Expand Down
10 changes: 5 additions & 5 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const validators = require("../bin/validators");
const { inspect } = require("util");

expect.extend({
toPass(validator, opts) {
const pass = validator(opts);
toPass(validator, options) {
const pass = validator({ options, source: "test-source.js" }, []);
return {
message: () =>
`expected ${inspect(opts)} to be ${pass ? "invalid" : "valid"}`,
`expected ${inspect(options)} to be ${pass ? "invalid" : "valid"}`,
pass,
};
},
Expand All @@ -17,8 +17,8 @@ expect.extend({
function rule(name, { valid, invalid }) {
test(name, () => {
const validator = validators[name];
valid.forEach((opts) => expect(validator).toPass(opts));
invalid.forEach((opts) => expect(validator).not.toPass(opts));
valid.forEach((options) => expect(validator).toPass(options));
invalid.forEach((options) => expect(validator).not.toPass(options));
});
}

Expand Down

0 comments on commit bd551b9

Please sign in to comment.