Skip to content

Commit

Permalink
Fix parseError for double-slash comments within selector lists in no-…
Browse files Browse the repository at this point in the history
…descending-specificity (#5891)
  • Loading branch information
jeddy3 committed Feb 7, 2022
1 parent 12a35ba commit e81473d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lib/rules/no-descending-specificity/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const postcssScss = require('postcss-scss');
const postcssLess = require('postcss-less');
const stripIndent = require('common-tags').stripIndent;

const { messages, ruleName } = require('..');

Expand Down Expand Up @@ -172,6 +174,22 @@ testRule({
],
});

testRule({
ruleName,
customSyntax: postcssLess,
config: [true],

accept: [
{
code: stripIndent`
a,
// comment2
b {}
`,
},
],
});

testRule({
skip: true,
ruleName,
Expand Down
5 changes: 4 additions & 1 deletion lib/utils/__tests__/isStandardSyntaxSelector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ describe('isStandardSyntaxSelector', () => {
expect(isStandardSyntaxSelector('.foo(@a)')).toBeFalsy();
expect(isStandardSyntaxSelector('.foo(@a: 5px)')).toBeFalsy();
});

it('SCSS or Less comments', () => {
expect(isStandardSyntaxSelector('a\n// comment\nb')).toBeFalsy();
expect(isStandardSyntaxSelector('a\n//comment\nb')).toBeFalsy();
});
it('ERB templates', () => {
// E. g. like in https://github.com/stylelint/stylelint/issues/4489
expect(isStandardSyntaxSelector('<% COLORS.each do |color| %>\na')).toBe(false);
Expand Down
5 changes: 5 additions & 0 deletions lib/utils/isStandardSyntaxSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,10 @@ module.exports = function (selector) {
return false;
}

// SCSS and Less comments
if (selector.includes('//')) {
return false;
}

return true;
};

0 comments on commit e81473d

Please sign in to comment.