Skip to content

Commit

Permalink
test to fix autofix
Browse files Browse the repository at this point in the history
  • Loading branch information
langermank committed Sep 28, 2023
1 parent bf08eea commit eb2ad67
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/rules/new-color-css-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,22 @@ module.exports = {
Object.keys(cssVars).forEach(cssVar => {
if (Array.isArray(cssVars[cssVar])) {
cssVars[cssVar].forEach(cssVarObject => {
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}))`)
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)
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)
}
})
}
})
}
}
})
})
}
})
Expand Down

0 comments on commit eb2ad67

Please sign in to comment.