@salesforce-ux/eslint-plugin-slds 0.1.4-alpha.0 → 0.1.4-alpha.2
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.
|
@@ -34,13 +34,13 @@ module.exports = {
|
|
|
34
34
|
if (!classList.includes("slds-modal__close")) {
|
|
35
35
|
return; // Stop execution if the class is missing
|
|
36
36
|
}
|
|
37
|
-
if (classList.includes("slds-button_icon-inverse")) {
|
|
37
|
+
if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
|
|
38
38
|
context.report({
|
|
39
39
|
node,
|
|
40
40
|
messageId: "removeClass",
|
|
41
41
|
fix(fixer) {
|
|
42
42
|
const newClassList = classList
|
|
43
|
-
.filter((cls) => cls !== "slds-button_icon-inverse")
|
|
43
|
+
.filter((cls) => (cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse"))
|
|
44
44
|
.join(" ");
|
|
45
45
|
return fixer.replaceText(classAttr, // Replace the full attribute
|
|
46
46
|
`class="${newClassList}"` // Updated class list
|
|
@@ -55,41 +55,33 @@ module.exports = {
|
|
|
55
55
|
const variantAttr = (0, node_1.findAttr)(node, "variant");
|
|
56
56
|
const sizeAttr = (0, node_1.findAttr)(node, "size");
|
|
57
57
|
const classAttr = (0, node_1.findAttr)(node, "class");
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return fixer.insertTextAfterRange([variantAttr?.range[1], variantAttr?.range[1]], ' size="large"');
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
// Ensure 'slds-button' and 'slds-button_icon' are in the class attribute
|
|
88
|
-
if (classAttr && classAttr.value) {
|
|
89
|
-
const classList = classAttr.value.value.split(/\s+/);
|
|
58
|
+
const iconClassAttr = (0, node_1.findAttr)(node, "icon-class"); // 🔍 Check for icon-class attribute
|
|
59
|
+
function validateClassAttr(attribute, attrName) {
|
|
60
|
+
if (attribute && attribute.value) {
|
|
61
|
+
const classList = attribute.value.value.split(/\s+/);
|
|
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
|
+
// Remove inverse classes
|
|
67
|
+
if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
|
|
68
|
+
context.report({
|
|
69
|
+
node,
|
|
70
|
+
messageId: "removeClass",
|
|
71
|
+
fix(fixer) {
|
|
72
|
+
const newClassList = classList
|
|
73
|
+
.filter((cls) => cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse")
|
|
74
|
+
.join(" ");
|
|
75
|
+
return fixer.replaceText(attribute, // Replace the full attribute
|
|
76
|
+
`${attrName}="${newClassList}"` // Correctly modifies the respective attribute
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Ensure 'slds-button' and 'slds-button_icon' exist
|
|
90
82
|
if (!classList.includes("slds-button") || !classList.includes("slds-button_icon")) {
|
|
91
83
|
context.report({
|
|
92
|
-
node:
|
|
84
|
+
node: attribute,
|
|
93
85
|
messageId: "ensureButtonClasses",
|
|
94
86
|
fix(fixer) {
|
|
95
87
|
const newClassList = [
|
|
@@ -97,12 +89,37 @@ module.exports = {
|
|
|
97
89
|
"slds-button_icon",
|
|
98
90
|
...classList.filter((cls) => cls !== "slds-button_icon-inverse"),
|
|
99
91
|
].join(" ");
|
|
100
|
-
return fixer.replaceText(
|
|
92
|
+
return fixer.replaceText(attribute.value, `"${newClassList}"`);
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Fix variant="bare-inverse" to "bare"
|
|
97
|
+
if (variantAttr && variantAttr.value && variantAttr.value.value === "bare-inverse") {
|
|
98
|
+
context.report({
|
|
99
|
+
node: variantAttr,
|
|
100
|
+
messageId: "changeVariant",
|
|
101
|
+
fix(fixer) {
|
|
102
|
+
return fixer.replaceText(variantAttr.value, `bare`);
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Ensure size="large" exists
|
|
107
|
+
if (!sizeAttr) {
|
|
108
|
+
context.report({
|
|
109
|
+
node,
|
|
110
|
+
messageId: "ensureSizeAttribute",
|
|
111
|
+
fix(fixer) {
|
|
112
|
+
if (variantAttr) {
|
|
113
|
+
return fixer.insertTextAfterRange([variantAttr.range[1], variantAttr.range[1]], ' size="large"');
|
|
114
|
+
}
|
|
101
115
|
},
|
|
102
116
|
});
|
|
103
117
|
}
|
|
104
118
|
}
|
|
105
119
|
}
|
|
120
|
+
// ✅ Validate `class` and `icon-class` separately, maintaining their own attribute names
|
|
121
|
+
validateClassAttr(classAttr, "class");
|
|
122
|
+
validateClassAttr(iconClassAttr, "icon-class");
|
|
106
123
|
}
|
|
107
124
|
// ✅ Scenario 3: Fix <lightning-icon> inside <button> & the class name of the parent name as button and it should have `slds-modal__close`
|
|
108
125
|
if ((tagName === "lightning-icon" || tagName === "lightning:icon") && node.parent?.name === "button") {
|