Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: STRF-11281 Narrow comma separation cases and Improve Base Rules Error #1139

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Loading