Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jathak committed Aug 14, 2020
1 parent 2e4f925 commit 0719481
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/__tests__/disableRanges.test.js
Expand Up @@ -749,9 +749,9 @@ it('SCSS // line-disabling comment (with description)', () => {

it('SCSS // disable next-line comment (with multi-line description)', () => {
const scssSource = `a {
// stylelint-disable-next-line declaration-no-important
// --
// Long-winded description
// stylelint-disable-next-line declaration-no-important
// --
// Long-winded description
color: pink !important;
}`;

Expand Down Expand Up @@ -798,9 +798,9 @@ it('Less // line-disabling comment (with description)', () => {

it('Less // disable next-line comment (with multi-line description)', () => {
const lessSource = `a {
// stylelint-disable-next-line declaration-no-important
// --
// Long-winded description
// stylelint-disable-next-line declaration-no-important
// --
// Long-winded description
color: pink !important;
}`;

Expand Down
15 changes: 12 additions & 3 deletions lib/assignDisabledRanges.js
Expand Up @@ -62,17 +62,17 @@ module.exports = function (root, result) {

root.walkComments((/** @type {PostcssComment} */ comment) => {
if (inlineEnd) {
// Ignore comments that were already processed by grouping with
// Ignore comments already processed by grouping with a previous one.
if (inlineEnd === comment) inlineEnd = null;
} else if (comment.inline || comment.raws.inline) {
} else if (isInlineComment(comment)) {
const fullComment = comment.clone();
let next = comment.next();

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

if (!current.inline && !current.raws.inline) break;
if (!isInlineComment(current)) break;

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

Expand All @@ -91,6 +91,15 @@ module.exports = function (root, result) {

return result;

/**
* @param {PostcssComment} comment
*/
function isInlineComment(comment) {
// We check both here because the Sass parser uses `raws.inline` to indicate
// inline comments, while the Less parser uses `inline`.
return comment.inline || comment.raws.inline;
}

/**
* @param {PostcssComment} comment
*/
Expand Down

0 comments on commit 0719481

Please sign in to comment.