Skip to content

Commit

Permalink
try to fix autofix again
Browse files Browse the repository at this point in the history
  • Loading branch information
langermank committed Sep 28, 2023
1 parent eb2ad67 commit a089bcd
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions src/rules/new-color-css-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,19 @@ module.exports = {
Object.keys(cssVars).forEach(cssVar => {
if (Array.isArray(cssVars[cssVar])) {
cssVars[cssVar].forEach(cssVarObject => {
cssVarObject.props.forEach(prop => {
const regex = new RegExp(`var\\(${cssVar}\\)`, 'g')
if (rawText.includes(prop) && regex.test(rawText)) {
const fixedString = rawText.replace(regex, `var(${cssVarObject.replacement}, var(${cssVar}))`)
if (!rawText.includes(fixedString)) {
// Check if the autofix has already been applied
context.report({
node,
message: `Replace var(${cssVar}) with var(${cssVarObject.replacement}, var(${cssVar}))`,
fix: function(fixer) {
return fixer.replaceText(node, node.type === 'Literal' ? `"${fixedString}"` : fixedString)
}
})
}
const regex = new RegExp(`var\\(${cssVar}\\)`, 'g')
if (cssVarObject.props.some(prop => rawText.includes(prop)) && regex.test(rawText)) {
const fixedString = rawText.replace(regex, `var(${cssVarObject.replacement}, var(${cssVar}))`)
if (!rawText.includes(fixedString)) {
context.report({
node,
message: `Replace var(${cssVar}) with var(${cssVarObject.replacement}, var(${cssVar}))`,
fix: function(fixer) {
return fixer.replaceText(node, node.type === 'Literal' ? `"${fixedString}"` : fixedString)
}
})
}
})
}
})
}
})
Expand Down

0 comments on commit a089bcd

Please sign in to comment.