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 2 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
18 changes: 18 additions & 0 deletions lib/__tests__/disableRanges.test.js
Expand Up @@ -238,6 +238,24 @@ 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 */',
).then((result) => {
expect(result.stylelint.disabledRanges).toEqual({
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.

We must expect error here since there is nothing to enable, if I understand correctly condition with No rules have been disabled error =)

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right :)

Copy link
Member

Choose a reason for hiding this comment

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

Hah, I found a bug in ranges assignment, I will do fix

all: [],
'block-no-empty': [
{
start: 1,
end: 1,
strictStart: true,
strictEnd: true,
},
],
});
});
});

it('disable next line all rules', () => {
return testDisableRanges('/* stylelint-disable-next-line */\na {} ').then((result) => {
expect(result.stylelint.disabledRanges).toEqual(
Expand Down
7 changes: 1 addition & 6 deletions lib/assignDisabledRanges.js
Expand Up @@ -157,12 +157,7 @@ module.exports = function(root, result) {
/** @type {number} */ (comment.source && comment.source.end && comment.source.end.line);

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)),
)
) {
if (Object.values(disabledRanges).every((ranges) => _.isEmpty(ranges))) {
throw comment.error('No rules have been disabled', {
plugin: 'stylelint',
});
Expand Down