Skip to content

Commit a813747

Browse files
Implement Stylelint for CSS/SCSS linting and confirm ESLint for JS
- Added Stylelint configuration to enforce styling rules in CSS/SCSS. Signed-off-by: Timothy Asir Jeyasingh <[email protected]>
1 parent 3cdcb9d commit a813747

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module.exports = {
6868
'default-case': 'off',
6969
'global-require': 'off',
7070
'implicit-arrow-linebreak': 'off',
71+
camelcase: ['error', { allow: ['pfV5', 'pfM'] }],
7172
'import/no-extraneous-dependencies': [
7273
'error',
7374
{

.stylelintrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: ['./stylelint-pf-prefix-rule.js'],
3+
rules: {
4+
'custom/pf-prefix': true,
5+
},
6+
};

stylelint-pf-prefix-rule.js

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const stylelint = require('stylelint');
2+
3+
const ruleName = 'custom/pf-prefix';
4+
const messages = stylelint.utils.ruleMessages(ruleName, {
5+
expected: (name) =>
6+
`Expected "${name}" to be prefixed with "pf-v5-" or "pf-m-" if it starts with "pf-" or ".pf-".`,
7+
});
8+
9+
module.exports = stylelint.createPlugin(ruleName, () => {
10+
return (root, result) => {
11+
// Regular expression to match variables, class names, mixins, etc., that start with pf- or .pf-
12+
const pfRegex = /(\.pf-|pf-)(?!v5-|m-)/;
13+
14+
root.walkDecls((decl) => {
15+
const value = decl.value;
16+
const prop = decl.prop;
17+
18+
// Check the value and property of the declaration
19+
if (pfRegex.test(value) || pfRegex.test(prop)) {
20+
stylelint.utils.report({
21+
message: messages.expected(prop),
22+
node: decl,
23+
result,
24+
ruleName,
25+
});
26+
}
27+
});
28+
29+
root.walkRules((rule) => {
30+
const selector = rule.selector;
31+
32+
// Check the selector (e.g., class names, IDs)
33+
if (pfRegex.test(selector)) {
34+
stylelint.utils.report({
35+
message: messages.expected(selector),
36+
node: rule,
37+
result,
38+
ruleName,
39+
});
40+
}
41+
});
42+
43+
root.walkAtRules((atRule) => {
44+
const name = atRule.name;
45+
const params = atRule.params;
46+
47+
// Check the name and parameters of at-rules (e.g., mixins, functions)
48+
if (pfRegex.test(name) || pfRegex.test(params)) {
49+
stylelint.utils.report({
50+
message: messages.expected(name),
51+
node: atRule,
52+
result,
53+
ruleName,
54+
});
55+
}
56+
});
57+
};
58+
});
59+
60+
module.exports.ruleName = ruleName;
61+
module.exports.messages = messages;

0 commit comments

Comments
 (0)