Skip to content

Commit

Permalink
Avoid combining disable comments with a blank line
Browse files Browse the repository at this point in the history
Fixes #4911.
  • Loading branch information
jathak committed Aug 31, 2020
1 parent cf2f45f commit eb3b04a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/__tests__/disableRanges.test.js
Expand Up @@ -781,6 +781,54 @@ it('SCSS // disable next-line comment (with multi-line description)', () => {
});
});

it('SCSS // disable comment (with // comment after blank line)', () => {
const scssSource = `a {
// stylelint-disable declaration-no-important
// Unrelated
color: pink !important;
}`;

return postcss()
.use(assignDisabledRanges)
.process(scssSource, { syntax: scss, from: undefined })
.then((result) => {
expect(result.stylelint.disabledRanges).toEqual({
all: [],
'declaration-no-important': [
{
start: 2,
strictStart: true,
},
],
});
});
});

it('SCSS /* disable comment (with // comment after blank line)', () => {
const scssSource = `a {
/* stylelint-disable declaration-no-important */
// Unrelated
color: pink !important;
}`;

return postcss()
.use(assignDisabledRanges)
.process(scssSource, { syntax: scss, from: undefined })
.then((result) => {
expect(result.stylelint.disabledRanges).toEqual({
all: [],
'declaration-no-important': [
{
start: 2,
strictStart: true,
},
],
});
});
});

it('Less // line-disabling comment (with description)', () => {
const lessSource = `a {
color: pink !important; // stylelint-disable-line declaration-no-important -- Description
Expand Down
6 changes: 6 additions & 0 deletions lib/assignDisabledRanges.js
Expand Up @@ -69,13 +69,18 @@ module.exports = function (root, result) {
} else if (isInlineComment(comment)) {
const fullComment = comment.clone();
let next = comment.next();
let lastLine = (comment.source && comment.source.end && comment.source.end.line) || 0;

while (next && next.type === 'comment') {
/** @type {PostcssComment} */
const current = next;

if (!isInlineComment(current)) break;

const currentLine = (current.source && current.source.end && current.source.end.line) || 0;

if (lastLine + 1 !== currentLine) break;

fullComment.text += `\n${current.text}`;

if (fullComment.source && current.source) {
Expand All @@ -84,6 +89,7 @@ module.exports = function (root, result) {

inlineEnd = current;
next = current.next();
lastLine = currentLine;
}
checkComment(fullComment);
} else {
Expand Down

0 comments on commit eb3b04a

Please sign in to comment.