From 0719481255db32305c7a819b2813d5141548a0ff Mon Sep 17 00:00:00 2001 From: Jennifer Thakar Date: Fri, 14 Aug 2020 15:31:42 -0700 Subject: [PATCH] Code review --- lib/__tests__/disableRanges.test.js | 12 ++++++------ lib/assignDisabledRanges.js | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lib/__tests__/disableRanges.test.js b/lib/__tests__/disableRanges.test.js index cabcd94781..d31bea78e8 100644 --- a/lib/__tests__/disableRanges.test.js +++ b/lib/__tests__/disableRanges.test.js @@ -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; }`; @@ -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; }`; diff --git a/lib/assignDisabledRanges.js b/lib/assignDisabledRanges.js index 6709760393..0f1b4352ba 100644 --- a/lib/assignDisabledRanges.js +++ b/lib/assignDisabledRanges.js @@ -62,9 +62,9 @@ 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(); @@ -72,7 +72,7 @@ module.exports = function (root, result) { /** @type {PostcssComment} */ const current = next; - if (!current.inline && !current.raws.inline) break; + if (!isInlineComment(current)) break; fullComment.text += `\n${current.text}`; @@ -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 */