Skip to content

Commit

Permalink
fix: STRF-11281 Narrow comma separation cases and Improve Base Rules …
Browse files Browse the repository at this point in the history
…Error (#1139)
  • Loading branch information
jairo-bc authored Oct 6, 2023
1 parent 579e3b2 commit 3879486
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/nodeSass/AutoFixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class AutoFixer {
}
if (
err.formatted.includes('Invalid CSS after') &&
err.formatted.includes('expected selector, was ', '')
err.formatted.includes('expected selector, was ",')
) {
return POSSIBLE_WRONG_COMMA;
}
Expand Down
13 changes: 11 additions & 2 deletions lib/nodeSass/BaseRulesFixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,28 @@ class BaseRulesFixer extends BaseFixer {
}

transform() {
const self = this;
return {
postcssPlugin: 'Transform Base Rules Issues into Comments',
Rule(rule, { Comment }) {
if (
rule.parent.type === 'root' &&
(rule.selector.startsWith('&--') || rule.selector.startsWith('&.'))
(rule.selector.startsWith('&') ||
rule.selector.startsWith(':not(&)') ||
rule.selector.startsWith('* &'))
) {
const comment = new Comment({ text: rule.toString() });
const comment = new Comment({ text: self.replaceInnerComments(rule) });
rule.replaceWith(comment);
}
},
};
}

// when we replace rule with comment, there might be a case when comment is inside another rule
// which breaks the commenting root rule
replaceInnerComments(rule) {
return rule.toString().replace(/\/\*(.*)\*\//g, '//$1');
}
}

module.exports = BaseRulesFixer;

0 comments on commit 3879486

Please sign in to comment.