@salesforce-ux/eslint-plugin-slds 0.1.4-alpha.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/rules/enforce-bem-class.d.ts +0 -3
- package/build/rules/enforce-bem-class.js +1 -4
- package/build/rules/modal-close-button-issue.d.ts +0 -7
- package/build/rules/modal-close-button-issue.js +73 -60
- package/build/rules/no-deprecated-classes-slds2.d.ts +0 -3
- package/build/rules/no-deprecated-classes-slds2.js +1 -4
- package/build/rules/utils/rule.d.ts +7 -0
- package/build/rules/utils/rule.js +10 -0
- package/package.json +1 -1
|
@@ -19,9 +19,6 @@ module.exports = {
|
|
|
19
19
|
additionalProperties: false,
|
|
20
20
|
},
|
|
21
21
|
],
|
|
22
|
-
messages: {
|
|
23
|
-
suggestedMsg: "{{actual}} has been retired. Update it to the new name {{newValue}}.",
|
|
24
|
-
},
|
|
25
22
|
},
|
|
26
23
|
create(context) {
|
|
27
24
|
function check(node) {
|
|
@@ -54,7 +51,7 @@ module.exports = {
|
|
|
54
51
|
actual: className,
|
|
55
52
|
newValue
|
|
56
53
|
},
|
|
57
|
-
|
|
54
|
+
message: JSON.stringify({ message: "{{actual}} has been retired. Update it to the new name {{newValue}}.", suggestions: [newValue] }),
|
|
58
55
|
fix(fixer) {
|
|
59
56
|
if (newValue) {
|
|
60
57
|
const newClassValue = classAttr.value.value.replace(className, newValue);
|
|
@@ -7,13 +7,6 @@ declare const _default: {
|
|
|
7
7
|
};
|
|
8
8
|
fixable: string;
|
|
9
9
|
schema: any[];
|
|
10
|
-
messages: {
|
|
11
|
-
removeClass: string;
|
|
12
|
-
changeVariant: string;
|
|
13
|
-
removeVariant: string;
|
|
14
|
-
ensureButtonClasses: string;
|
|
15
|
-
ensureSizeAttribute: string;
|
|
16
|
-
};
|
|
17
10
|
};
|
|
18
11
|
create(context: any): {
|
|
19
12
|
Tag: (node: any) => void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const node_1 = require("./utils/node");
|
|
3
|
+
const rule_1 = require("./utils/rule");
|
|
3
4
|
module.exports = {
|
|
4
5
|
meta: {
|
|
5
6
|
type: "problem",
|
|
@@ -9,13 +10,6 @@ module.exports = {
|
|
|
9
10
|
},
|
|
10
11
|
fixable: "code",
|
|
11
12
|
schema: [],
|
|
12
|
-
messages: {
|
|
13
|
-
removeClass: "Remove the slds-button_icon-inverse class from the modal close button in components that use the SLDS modal blueprint.",
|
|
14
|
-
changeVariant: "Change the variant attribute value from bare-inverse to bare in <lightning-button-icon> or <lightning-icon>.",
|
|
15
|
-
removeVariant: "Remove the variant attribute from the <lightning-icon> component inside the <button> element.",
|
|
16
|
-
ensureButtonClasses: "Add or move slds-button and slds-button_icon to the class attribute of the <button> element or <lightning-button-icon> component.",
|
|
17
|
-
ensureSizeAttribute: "To size icons properly, set the size attribute to large in the <lightning-icon> and <lightning-button-icon> components.",
|
|
18
|
-
},
|
|
19
13
|
},
|
|
20
14
|
create(context) {
|
|
21
15
|
function check(node) {
|
|
@@ -35,13 +29,14 @@ module.exports = {
|
|
|
35
29
|
return; // Stop execution if the class is missing
|
|
36
30
|
}
|
|
37
31
|
if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
|
|
32
|
+
const newClassList = classList
|
|
33
|
+
.filter((cls) => (cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse"))
|
|
34
|
+
.join(" ");
|
|
38
35
|
context.report({
|
|
39
36
|
node,
|
|
40
|
-
|
|
37
|
+
loc: classAttr.loc,
|
|
38
|
+
message: JSON.stringify({ message: rule_1.messages["removeClass"], suggestions: [`class="${newClassList}"`] }),
|
|
41
39
|
fix(fixer) {
|
|
42
|
-
const newClassList = classList
|
|
43
|
-
.filter((cls) => (cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse"))
|
|
44
|
-
.join(" ");
|
|
45
40
|
return fixer.replaceText(classAttr, // Replace the full attribute
|
|
46
41
|
`class="${newClassList}"` // Updated class list
|
|
47
42
|
);
|
|
@@ -59,19 +54,25 @@ module.exports = {
|
|
|
59
54
|
function validateClassAttr(attribute, attrName) {
|
|
60
55
|
if (attribute && attribute.value) {
|
|
61
56
|
const classList = attribute.value.value.split(/\s+/);
|
|
57
|
+
// Irrespective of whether we are checking for class or icon-class we need to check whether the attribute is present or not.
|
|
62
58
|
// ✅ Ensure "slds-modal__close" exists before proceeding
|
|
63
|
-
if (!
|
|
64
|
-
return;
|
|
59
|
+
if (!classAttr?.value?.value?.includes("slds-modal__close")) {
|
|
60
|
+
return;
|
|
65
61
|
}
|
|
62
|
+
// ✅ Ensure "slds-modal__close" exists before proceeding
|
|
63
|
+
// if (!classList.includes("slds-modal__close")) {
|
|
64
|
+
// return; // Stop execution if the class is missing
|
|
65
|
+
// }
|
|
66
66
|
// Remove inverse classes
|
|
67
67
|
if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
|
|
68
|
+
const newClassList = classList
|
|
69
|
+
.filter((cls) => cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse")
|
|
70
|
+
.join(" ");
|
|
68
71
|
context.report({
|
|
69
72
|
node,
|
|
70
|
-
|
|
73
|
+
loc: attribute.loc,
|
|
74
|
+
message: JSON.stringify({ message: rule_1.messages["removeClass"], suggestions: [`${attrName}="${newClassList}"`] }),
|
|
71
75
|
fix(fixer) {
|
|
72
|
-
const newClassList = classList
|
|
73
|
-
.filter((cls) => cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse")
|
|
74
|
-
.join(" ");
|
|
75
76
|
return fixer.replaceText(attribute, // Replace the full attribute
|
|
76
77
|
`${attrName}="${newClassList}"` // Correctly modifies the respective attribute
|
|
77
78
|
);
|
|
@@ -80,16 +81,25 @@ module.exports = {
|
|
|
80
81
|
}
|
|
81
82
|
// Ensure 'slds-button' and 'slds-button_icon' exist
|
|
82
83
|
if (!classList.includes("slds-button") || !classList.includes("slds-button_icon")) {
|
|
84
|
+
let newClassList;
|
|
85
|
+
if (attrName === 'icon-class') {
|
|
86
|
+
newClassList = [
|
|
87
|
+
...classList.filter((cls) => cls !== "slds-button_icon-inverse"),
|
|
88
|
+
].join(" ");
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
newClassList = [
|
|
92
|
+
"slds-button",
|
|
93
|
+
"slds-button_icon",
|
|
94
|
+
...classList.filter((cls) => cls !== "slds-button_icon-inverse"),
|
|
95
|
+
].join(" ");
|
|
96
|
+
}
|
|
83
97
|
context.report({
|
|
84
98
|
node: attribute,
|
|
85
|
-
|
|
99
|
+
loc: attribute.value.loc,
|
|
100
|
+
message: JSON.stringify({ message: rule_1.messages["ensureButtonClasses"], suggestions: [newClassList] }),
|
|
86
101
|
fix(fixer) {
|
|
87
|
-
|
|
88
|
-
"slds-button",
|
|
89
|
-
"slds-button_icon",
|
|
90
|
-
...classList.filter((cls) => cls !== "slds-button_icon-inverse"),
|
|
91
|
-
].join(" ");
|
|
92
|
-
return fixer.replaceText(attribute.value, `"${newClassList}"`);
|
|
102
|
+
return fixer.replaceText(attribute.value, `${newClassList}`);
|
|
93
103
|
},
|
|
94
104
|
});
|
|
95
105
|
}
|
|
@@ -97,24 +107,25 @@ module.exports = {
|
|
|
97
107
|
if (variantAttr && variantAttr.value && variantAttr.value.value === "bare-inverse") {
|
|
98
108
|
context.report({
|
|
99
109
|
node: variantAttr,
|
|
100
|
-
|
|
110
|
+
message: JSON.stringify({ message: rule_1.messages["changeVariant"], suggestions: ["bare"] }),
|
|
111
|
+
loc: variantAttr.value.loc,
|
|
101
112
|
fix(fixer) {
|
|
102
113
|
return fixer.replaceText(variantAttr.value, `bare`);
|
|
103
114
|
},
|
|
104
115
|
});
|
|
105
116
|
}
|
|
106
117
|
// Ensure size="large" exists
|
|
107
|
-
if (!sizeAttr) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
+
// if (!sizeAttr) {
|
|
119
|
+
// context.report({
|
|
120
|
+
// node,
|
|
121
|
+
// message: messages["ensureSizeAttribute"],
|
|
122
|
+
// fix(fixer) {
|
|
123
|
+
// if (variantAttr) {
|
|
124
|
+
// return fixer.insertTextAfterRange([variantAttr.range[1], variantAttr.range[1]], ' size="large"');
|
|
125
|
+
// }
|
|
126
|
+
// },
|
|
127
|
+
// });
|
|
128
|
+
// }
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
131
|
// ✅ Validate `class` and `icon-class` separately, maintaining their own attribute names
|
|
@@ -136,35 +147,37 @@ module.exports = {
|
|
|
136
147
|
if (variantAttr && variantAttr.value && variantAttr.value.value === "bare-inverse") {
|
|
137
148
|
context.report({
|
|
138
149
|
node: variantAttr,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return fixer.replaceText(variantAttr.value, `"bare"`);
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
// Remove variant attribute completely
|
|
146
|
-
if (variantAttr) {
|
|
147
|
-
context.report({
|
|
148
|
-
node: variantAttr,
|
|
149
|
-
messageId: "removeVariant",
|
|
150
|
+
message: JSON.stringify({ message: rule_1.messages["changeVariant"], suggestions: ["bare"] }),
|
|
151
|
+
loc: variantAttr.value.loc,
|
|
150
152
|
fix(fixer) {
|
|
151
|
-
return fixer.
|
|
153
|
+
return fixer.replaceText(variantAttr.value, `bare`);
|
|
152
154
|
},
|
|
153
155
|
});
|
|
154
156
|
}
|
|
157
|
+
// // Remove variant attribute completely
|
|
158
|
+
// if (variantAttr) {
|
|
159
|
+
// context.report({
|
|
160
|
+
// node: variantAttr,
|
|
161
|
+
// messageId: "removeVariant",
|
|
162
|
+
// fix(fixer) {
|
|
163
|
+
// return fixer.remove(variantAttr);
|
|
164
|
+
// },
|
|
165
|
+
// });
|
|
166
|
+
// }
|
|
155
167
|
//Ensure size="large" is set
|
|
156
|
-
if (!sizeAttr) {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
+
// if (!sizeAttr) {
|
|
169
|
+
// context.report({
|
|
170
|
+
// node,
|
|
171
|
+
// message: messages["ensureSizeAttribute"],
|
|
172
|
+
// fix(fixer) {
|
|
173
|
+
// //return fixer.insertTextAfter(node, ' size="large"');
|
|
174
|
+
// if(variantAttr)
|
|
175
|
+
// {
|
|
176
|
+
// return fixer.insertTextAfterRange([variantAttr.range[1], variantAttr.range[1]], ' size="large"')
|
|
177
|
+
// }
|
|
178
|
+
// },
|
|
179
|
+
// });
|
|
180
|
+
// }
|
|
168
181
|
}
|
|
169
182
|
}
|
|
170
183
|
}
|
|
@@ -10,9 +10,6 @@ module.exports = {
|
|
|
10
10
|
recommended: true,
|
|
11
11
|
},
|
|
12
12
|
schema: [], // No additional options needed
|
|
13
|
-
messages: {
|
|
14
|
-
errorMsg: "The class {{className}} isn't available in SLDS 2. Update it to a class supported in SLDS 2. See lightningdesignsystem.com for more information.",
|
|
15
|
-
},
|
|
16
13
|
},
|
|
17
14
|
create(context) {
|
|
18
15
|
function check(node) {
|
|
@@ -42,7 +39,7 @@ module.exports = {
|
|
|
42
39
|
data: {
|
|
43
40
|
className,
|
|
44
41
|
},
|
|
45
|
-
|
|
42
|
+
message: JSON.stringify({ message: "The class {{className}} isn't available in SLDS 2. Update it to a class supported in SLDS 2. See lightningdesignsystem.com for more information.", suggestions: [] }),
|
|
46
43
|
});
|
|
47
44
|
}
|
|
48
45
|
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.messages = void 0;
|
|
4
|
+
exports.messages = {
|
|
5
|
+
removeClass: "Remove the slds-button_icon-inverse class from the modal close button in components that use the SLDS modal blueprint.",
|
|
6
|
+
changeVariant: "Change the variant attribute value from bare-inverse to bare in <lightning-button-icon> or <lightning-icon>.",
|
|
7
|
+
removeVariant: "Remove the variant attribute from the <lightning-icon> component inside the <button> element.",
|
|
8
|
+
ensureButtonClasses: "Add or move slds-button and slds-button_icon to the class attribute of the <button> element or <lightning-button-icon> component.",
|
|
9
|
+
ensureSizeAttribute: "To size icons properly, set the size attribute to large in the <lightning-icon> and <lightning-button-icon> components.",
|
|
10
|
+
};
|