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

Remove unused condition #4497

Merged
merged 4 commits into from Jan 5, 2020
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
11 changes: 11 additions & 0 deletions lib/__tests__/disableRanges.test.js
Expand Up @@ -238,6 +238,17 @@ it('disable single line multiple rules', () => {
);
});

it('disable single line one rule and re-enable all', () => {
return testDisableRanges(
'a {} /* stylelint-disable-line block-no-empty */\n/* stylelint-enable */',
() => {
throw new Error('should have errored');
},
).catch((err) => {
expect(err.reason).toBe('No rules have been disabled');
});
});

it('disable next line all rules', () => {
return testDisableRanges('/* stylelint-disable-next-line */\na {} ').then((result) => {
expect(result.stylelint.disabledRanges).toEqual(
Expand Down
2 changes: 1 addition & 1 deletion lib/__tests__/needlessDisables.test.js
Expand Up @@ -81,7 +81,7 @@ it('needlessDisables complex case', () => {
ranges: [
{ start: 5, end: 5, unusedRule: 'color-named' },
{ start: 6, end: 6, unusedRule: 'block-no-empty' },
{ start: 8, unusedRule: 'block-no-empty' },
{ start: 8, end: 10, unusedRule: 'block-no-empty' },
Copy link
Member

@vankop vankop Jan 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],
},
]);
Expand Down
17 changes: 9 additions & 8 deletions lib/assignDisabledRanges.js
Expand Up @@ -95,20 +95,22 @@ module.exports = function(root, result) {
});
}

if (ruleIsDisabled(ruleName)) {
throw comment.error(`"${ruleName}" has already been disabled`, {
plugin: 'stylelint',
});
}

if (ruleName === ALL_RULES) {
Object.keys(disabledRanges).forEach((disabledRuleName) => {
if (ruleIsDisabled(disabledRuleName)) return;

const strict = disabledRuleName === ALL_RULES;

startDisabledRange(line, disabledRuleName, strict);
endDisabledRange(line, disabledRuleName, strict);
});
} else {
if (ruleIsDisabled(ruleName)) {
throw comment.error(`"${ruleName}" has already been disabled`, {
plugin: 'stylelint',
});
}

startDisabledRange(line, ruleName, true);
endDisabledRange(line, ruleName, true);
}
Expand Down Expand Up @@ -159,8 +161,7 @@ module.exports = function(root, result) {
if (ruleToEnable === ALL_RULES) {
if (
Object.values(disabledRanges).every(
// @ts-ignore https://github.com/stylelint/stylelint/issues/4328
(ranges) => _.isEmpty(ranges) || Boolean(_.last(ranges.end)),
(ranges) => ranges.length === 0 || typeof ranges[ranges.length - 1].end === 'number',
)
) {
throw comment.error('No rules have been disabled', {
Expand Down