Created
January 27, 2025 14:49
-
-
Save EduardoSimon/b98174d9f02265e193d80af6e2efea28 to your computer and use it in GitHub Desktop.
Draft eslint plugin to prevent css classes to be removed from the code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
meta: { | |
type: 'problem', | |
docs: { | |
description: 'Disallow removal of specific CSS classes', | |
category: 'Best Practices', | |
}, | |
schema: [], // No options | |
}, | |
create(context) { | |
const classesToKeep = ['specific-class-to-keep', /^regex-to-keep-classes$/]; | |
return { | |
Literal(node) { | |
if (typeof node.value === 'string') { | |
classesToKeep.forEach((cls) => { | |
const regex = cls instanceof RegExp ? cls : new RegExp(`\\b${cls}\\b`); | |
if (regex.test(node.value)) { | |
context.report({ | |
node, | |
message: `The class "${cls}" should not be removed.`, | |
}); | |
} | |
}); | |
} | |
}, | |
}; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment