Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add invalid rule primary option message for false #6250

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/__tests__/fixtures/plugin-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ruleName = 'plugin/async';
const rule = (enabled) => (root, result) => {
const validOptions = stylelint.utils.validateOptions(result, ruleName, {
actual: enabled,
possible: [true, false],
possible: [true],
});

if (!validOptions) {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/selector-no-qualifying-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const rule = (primary, secondaryOptions) => {
ruleName,
{
actual: primary,
possible: [true, false],
possible: [true],
Mouvedia marked this conversation as resolved.
Show resolved Hide resolved
},
{
actual: secondaryOptions,
Expand Down
12 changes: 6 additions & 6 deletions lib/utils/__tests__/validateOptions.test.js
Original file line number Diff line number Diff line change
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
6 changes: 6 additions & 0 deletions lib/utils/validateOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ function validate(opts, ruleName, complain) {
const actual = opts.actual;
const optional = opts.optional;

if (actual === false && !ruleName.startsWith('report')) {
Mouvedia marked this conversation as resolved.
Show resolved Hide resolved
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