Skip to content

Commit

Permalink
feat: warn if the primary option is false
Browse files Browse the repository at this point in the history
  • Loading branch information
Mouvedia authored and Gary G committed Aug 9, 2022
1 parent 0bd6976 commit 34e17d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/utils/__tests__/validateOptions.test.js
Expand Up @@ -26,17 +26,17 @@ describe('validateOptions for primary options', () => {
expect(result.warn.mock.calls[0][0]).toBe('Invalid option value "d" for rule "foo"');
});

it('passing boolean equivalence', () => {
it('passing null equivalence', () => {
validateOptions(result, 'foo', {
possible: [true, false],
actual: false,
possible: [true, null],
actual: null,
});
expect(result.warn).toHaveBeenCalledTimes(0);
});

it('failing boolean equivalence', () => {
it('failing null equivalence', () => {
validateOptions(result, 'foo', {
possible: [true, false],
possible: [true, null],
actual: 'a',
});
expect(result.warn).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('validateOptions for `*-no-*` rule with no valid options', () => {
});
expect(result.warn.mock.calls[0]).toHaveLength(2);
expect(result.warn.mock.calls[0][0]).toBe(
'Unexpected option value "false" for rule "no-dancing"',
'Invalid option value "false" for rule "no-dancing". Are you trying to disable this rule? If so use "null" instead',
);
});

Expand Down
11 changes: 11 additions & 0 deletions lib/utils/validateOptions.js
Expand Up @@ -65,6 +65,17 @@ function validate(opts, ruleName, complain) {
const possible = opts.possible;
const actual = opts.actual;
const optional = opts.optional;
const whitelist = [
'reportDescriptionlessDisables',
'reportInvalidScopeDisables',
'reportNeedlessDisables',
];

if (actual === false && !whitelist.includes(ruleName)) {
return complain(
`Invalid option value "false" for rule "${ruleName}". Are you trying to disable this rule? If so use "null" instead`,
);
}

if (actual === null || arrayEqual(actual, [null])) {
return;
Expand Down

0 comments on commit 34e17d0

Please sign in to comment.