@salesforce-ux/eslint-plugin-slds 0.5.2 → 1.0.0-internal-alpha.0

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.
Files changed (114) hide show
  1. package/build/index.js +2309 -50
  2. package/build/index.js.map +4 -4
  3. package/build/rules/enforce-bem-usage.js +325 -85
  4. package/build/rules/enforce-bem-usage.js.map +4 -4
  5. package/build/rules/modal-close-button-issue.js +324 -179
  6. package/build/rules/modal-close-button-issue.js.map +4 -4
  7. package/build/rules/no-deprecated-classes-slds2.js +247 -53
  8. package/build/rules/no-deprecated-classes-slds2.js.map +4 -4
  9. package/build/rules/v9/enforce-bem-usage.js +236 -0
  10. package/build/rules/v9/enforce-bem-usage.js.map +7 -0
  11. package/build/rules/v9/enforce-component-hook-naming-convention.js +262 -0
  12. package/build/rules/v9/enforce-component-hook-naming-convention.js.map +7 -0
  13. package/build/rules/v9/enforce-sds-to-slds-hooks.js +260 -0
  14. package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +7 -0
  15. package/build/rules/v9/lwc-token-to-slds-hook.js +330 -0
  16. package/build/rules/v9/lwc-token-to-slds-hook.js.map +7 -0
  17. package/build/rules/v9/no-deprecated-slds-classes.js +227 -0
  18. package/build/rules/v9/no-deprecated-slds-classes.js.map +7 -0
  19. package/build/rules/v9/no-deprecated-tokens-slds1.js +270 -0
  20. package/build/rules/v9/no-deprecated-tokens-slds1.js.map +7 -0
  21. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +339 -0
  22. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +7 -0
  23. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +348 -0
  24. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +7 -0
  25. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +344 -0
  26. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +7 -0
  27. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +388 -0
  28. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +7 -0
  29. package/build/rules/v9/no-hardcoded-values/handlers/index.js +834 -0
  30. package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +7 -0
  31. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +1112 -0
  32. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +7 -0
  33. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +1112 -0
  34. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +7 -0
  35. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +945 -0
  36. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +7 -0
  37. package/build/rules/v9/no-slds-class-overrides.js +233 -0
  38. package/build/rules/v9/no-slds-class-overrides.js.map +7 -0
  39. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +250 -0
  40. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +7 -0
  41. package/build/rules/v9/no-slds-private-var.js +230 -0
  42. package/build/rules/v9/no-slds-private-var.js.map +7 -0
  43. package/build/rules/v9/no-slds-var-without-fallback.js +253 -0
  44. package/build/rules/v9/no-slds-var-without-fallback.js.map +7 -0
  45. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +253 -0
  46. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +7 -0
  47. package/build/rules/v9/no-unsupported-hooks-slds2.js +243 -0
  48. package/build/rules/v9/no-unsupported-hooks-slds2.js.map +7 -0
  49. package/build/rules/v9/reduce-annotations.js +234 -0
  50. package/build/rules/v9/reduce-annotations.js.map +7 -0
  51. package/build/src/rules/enforce-bem-usage.d.ts +17 -0
  52. package/build/{rules → src/rules}/modal-close-button-issue.d.ts +2 -1
  53. package/build/{rules → src/rules}/no-deprecated-classes-slds2.d.ts +2 -1
  54. package/build/src/rules/v9/enforce-bem-usage.d.ts +3 -0
  55. package/build/src/rules/v9/enforce-component-hook-naming-convention.d.ts +3 -0
  56. package/build/src/rules/v9/enforce-sds-to-slds-hooks.d.ts +3 -0
  57. package/build/src/rules/v9/lwc-token-to-slds-hook.d.ts +3 -0
  58. package/build/src/rules/v9/no-deprecated-slds-classes.d.ts +3 -0
  59. package/build/src/rules/v9/no-deprecated-tokens-slds1.d.ts +3 -0
  60. package/build/src/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.d.ts +5 -0
  61. package/build/src/rules/v9/no-hardcoded-values/handlers/colorHandler.d.ts +7 -0
  62. package/build/src/rules/v9/no-hardcoded-values/handlers/densityHandler.d.ts +7 -0
  63. package/build/src/rules/v9/no-hardcoded-values/handlers/fontHandler.d.ts +6 -0
  64. package/build/src/rules/v9/no-hardcoded-values/handlers/index.d.ts +8 -0
  65. package/build/src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.d.ts +3 -0
  66. package/build/src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.d.ts +3 -0
  67. package/build/src/rules/v9/no-hardcoded-values/noHardcodedValueRule.d.ts +9 -0
  68. package/build/src/rules/v9/no-slds-class-overrides.d.ts +8 -0
  69. package/build/src/rules/v9/no-slds-namespace-for-custom-hooks.d.ts +3 -0
  70. package/build/src/rules/v9/no-slds-private-var.d.ts +3 -0
  71. package/build/src/rules/v9/no-slds-var-without-fallback.d.ts +3 -0
  72. package/build/src/rules/v9/no-sldshook-fallback-for-lwctoken.d.ts +3 -0
  73. package/build/src/rules/v9/no-unsupported-hooks-slds2.d.ts +3 -0
  74. package/build/src/rules/v9/reduce-annotations.d.ts +3 -0
  75. package/build/src/types/index.d.ts +26 -0
  76. package/build/src/utils/boxShadowValueParser.d.ts +17 -0
  77. package/build/src/utils/color-lib-utils.d.ts +18 -0
  78. package/build/src/utils/css-functions.d.ts +7 -0
  79. package/build/src/utils/css-utils.d.ts +7 -0
  80. package/build/src/utils/hardcoded-shared-utils.d.ts +60 -0
  81. package/build/src/utils/property-matcher.d.ts +23 -0
  82. package/build/src/utils/styling-hook-utils.d.ts +7 -0
  83. package/build/src/utils/value-utils.d.ts +40 -0
  84. package/build/types/index.js +18 -0
  85. package/build/types/index.js.map +7 -0
  86. package/build/types/yaml.d.js +1 -0
  87. package/build/types/yaml.d.js.map +7 -0
  88. package/build/utils/boxShadowValueParser.js +197 -0
  89. package/build/utils/boxShadowValueParser.js.map +7 -0
  90. package/build/utils/color-lib-utils.js +160 -0
  91. package/build/utils/color-lib-utils.js.map +7 -0
  92. package/build/utils/css-functions.js +68 -0
  93. package/build/utils/css-functions.js.map +7 -0
  94. package/build/utils/css-utils.js +33 -0
  95. package/build/utils/css-utils.js.map +7 -0
  96. package/build/utils/hardcoded-shared-utils.js +300 -0
  97. package/build/utils/hardcoded-shared-utils.js.map +7 -0
  98. package/build/utils/node.js +158 -0
  99. package/build/{rules/utils → utils}/node.js.map +2 -2
  100. package/build/utils/property-matcher.js +159 -0
  101. package/build/utils/property-matcher.js.map +7 -0
  102. package/build/utils/styling-hook-utils.js +80 -0
  103. package/build/utils/styling-hook-utils.js.map +7 -0
  104. package/build/utils/value-utils.js +65 -0
  105. package/build/utils/value-utils.js.map +7 -0
  106. package/package.json +9 -4
  107. package/src/config/rule-messages.yml +143 -0
  108. package/build/rules/enforce-bem-usage.d.ts +0 -28
  109. package/build/rules/utils/node.js +0 -197
  110. package/build/rules/utils/rule.d.ts +0 -7
  111. package/build/rules/utils/rule.js +0 -10
  112. package/build/rules/utils/rule.js.map +0 -7
  113. /package/build/{index.d.ts → src/index.d.ts} +0 -0
  114. /package/build/{rules → src}/utils/node.d.ts +0 -0
@@ -1,190 +1,335 @@
1
- "use strict";
2
- const node_1 = require("./utils/node");
3
- const rule_1 = require("./utils/rule");
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ // If the importer is in node compatibility mode or this is not an ESM
20
+ // file that has been converted to a CommonJS file using a Babel-
21
+ // compatible transform (i.e. "__esModule" has not been set), then set
22
+ // "default" to the CommonJS "module.exports" for node compatibility.
23
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
24
+ mod
25
+ ));
26
+
27
+ // yaml-file:/Users/ritesh.kumar2/Documents/projects/stylelint-sds/packages/eslint-plugin-slds/src/config/rule-messages.yml
28
+ var require_rule_messages = __commonJS({
29
+ "yaml-file:/Users/ritesh.kumar2/Documents/projects/stylelint-sds/packages/eslint-plugin-slds/src/config/rule-messages.yml"(exports2, module2) {
30
+ module2.exports = {
31
+ "no-slds-class-overrides": {
32
+ "description": "Create new custom CSS classes instead of overriding SLDS selectors",
33
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-class-overrides",
34
+ "type": "problem",
35
+ "messages": {
36
+ "sldsClassOverride": "Overriding .{{className}} isn't supported. To differentiate SLDS and custom classes, create a CSS class in your namespace. Examples: myapp-input, myapp-button."
37
+ }
38
+ },
39
+ "no-deprecated-slds-classes": {
40
+ "description": "Please replace the deprecated classes with a modern equivalent",
41
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-deprecated-slds-classes",
42
+ "type": "problem",
43
+ "messages": {
44
+ "deprecatedClass": "The class {{className}} is deprecated and not available in SLDS2. Please update to a supported class."
45
+ }
46
+ },
47
+ "no-deprecated-tokens-slds1": {
48
+ "description": "Update outdated design tokens to SLDS 2 styling hooks with similar values. For more information, see Styling Hooks on lightningdesignsystem.com.",
49
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-deprecated-tokens-slds1",
50
+ "type": "problem",
51
+ "messages": {
52
+ "deprecatedToken": "Consider removing {{oldValue}} or replacing it with {{newValue}}. Set the fallback to {{oldValue}}. For more info, see Styling Hooks on lightningdesignsystem.com.",
53
+ "noReplacement": "Update outdated design tokens to SLDS 2 styling hooks with similar values. For more information, see Styling Hooks on lightningdesignsystem.com."
54
+ }
55
+ },
56
+ "enforce-sds-to-slds-hooks": {
57
+ "description": "Convert your existing --sds styling hooks to --slds styling hooks. See lightningdesignsystem.com for more info.",
58
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#enforce-sds-to-slds-hooks",
59
+ "type": "problem",
60
+ "messages": {
61
+ "replaceSdsWithSlds": "Replace {{oldValue}} with {{suggestedMatch}} styling hook."
62
+ }
63
+ },
64
+ "enforce-bem-usage": {
65
+ "description": "Replace BEM double-dash syntax in class names with single underscore syntax",
66
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#enforce-bem-usage",
67
+ "type": "problem",
68
+ "messages": {
69
+ "bemDoubleDash": "{{actual}} has been retired. Update it to the new name {{newValue}}.",
70
+ "fixBemNaming": "Update to correct BEM naming convention"
71
+ }
72
+ },
73
+ "modal-close-button-issue": {
74
+ "description": "Update component attributes or CSS classes for the modal close button to comply with the modal component blueprint",
75
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#modal-close-button-issue",
76
+ "type": "problem",
77
+ "messages": {
78
+ "modalCloseButtonIssue": "Update component attributes or CSS classes for the modal close button to comply with the modal component blueprint.",
79
+ "removeClass": "Remove the slds-button_icon-inverse class from the modal close button in components that use the SLDS modal blueprint.",
80
+ "changeVariant": "Change the variant attribute value from bare-inverse to bare in <lightning-button-icon> or <lightning-icon>.",
81
+ "removeVariant": "Remove the variant attribute from the <lightning-icon> component inside the <button> element.",
82
+ "ensureButtonClasses": "Add or move slds-button and slds-button_icon to the class attribute of the <button> element or <lightning-button-icon> component.",
83
+ "ensureSizeAttribute": "To size icons properly, set the size attribute \u200Cto large in the <lightning-icon> and <lightning-button-icon> components."
84
+ }
85
+ },
86
+ "no-deprecated-classes-slds2": {
87
+ "description": "Replace classes that aren't available with SLDS 2 classes",
88
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-deprecated-classes-slds2",
89
+ "type": "problem",
90
+ "messages": {
91
+ "deprecatedClass": "The class {{className}} isn't available in SLDS 2. Update it to a class supported in SLDS 2. See lightningdesignsystem.com for more information.",
92
+ "updateToModernClass": "Replace deprecated class with modern equivalent",
93
+ "checkDocumentation": "See lightningdesignsystem.com for SLDS 2 class alternatives"
94
+ }
95
+ },
96
+ "lwc-token-to-slds-hook": {
97
+ "description": "Replace the deprecated --lwc tokens with the latest --slds tokens. See lightningdesignsystem.com for more info.",
98
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#lwc-token-to-slds-hook",
99
+ "type": "problem",
100
+ "messages": {
101
+ "errorWithReplacement": "The '{{oldValue}}' design token is deprecated. Replace it with '{{newValue}}'. For more info, see Global Styling Hooks on lightningdesignsystem.com.",
102
+ "errorWithStyleHooks": "The '{{oldValue}}' design token is deprecated. Replace it with the SLDS 2 '{{newValue}}' styling hook and set the fallback to '{{oldValue}}'. For more info, see Global Styling Hooks on lightningdesignsystem.com.",
103
+ "errorWithNoRecommendation": "The '{{oldValue}}' design token is deprecated. For more info, see the New Global Styling Hook Guidance on lightningdesignsystem.com."
104
+ }
105
+ },
106
+ "no-sldshook-fallback-for-lwctoken": {
107
+ "description": "Avoid using --slds styling hooks as fallback values for --lwc tokens.",
108
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-sldshook-fallback-for-lwctoken",
109
+ "type": "problem",
110
+ "messages": {
111
+ "unsupportedFallback": "Remove the {{sldsToken}} styling hook that is used as a fallback value for {{lwcToken}}."
112
+ }
113
+ },
114
+ "no-unsupported-hooks-slds2": {
115
+ "description": "Identifies styling hooks that aren't present in SLDS 2. They must be replaced with styling hooks that have a similar effect, or they must be removed.",
116
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-unsupported-hooks-slds2",
117
+ "type": "problem",
118
+ "messages": {
119
+ "deprecated": "The {{token}} styling hook isn't present in SLDS 2 and there's no equivalent replacement. Remove it or replace it with a styling hook with a similar effect."
120
+ }
121
+ },
122
+ "no-slds-var-without-fallback": {
123
+ "description": "Add fallback values to SLDS styling hooks. The fallback values are used in Salesforce environments where styling hooks are unavailable.",
124
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-var-without-fallback",
125
+ "type": "problem",
126
+ "messages": {
127
+ "varWithoutFallback": "Your code uses the {{cssVar}} styling hook without a fallback value. Styling hooks are unavailable in some Salesforce environments. To render your component correctly in all environments, add this fallback value: var({{cssVar}}, {{recommendation}}). To make this fallback value brand-aware, use a branded design token instead of a static value. See Design Tokens on v1.lightningdesignsystem.com."
128
+ }
129
+ },
130
+ "no-slds-namespace-for-custom-hooks": {
131
+ "description": "To differentiate custom styling hooks from SLDS styling hooks, create custom styling hooks in your namespace.",
132
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-namespace-for-custom-hooks",
133
+ "type": "problem",
134
+ "messages": {
135
+ "customHookNamespace": "Using the --slds namespace for {{token}} isn't supported. Create the custom styling hook in your namespace. Example: --myapp-{{tokenWithoutNamespace}}"
136
+ }
137
+ },
138
+ "no-slds-private-var": {
139
+ "description": "Some SLDS styling hooks are private and reserved only for internal Salesforce use. Private SLDS styling hooks have prefixes --_slds- and --slds-s-. For more information, look up private CSS in lightningdesignsystem.com.",
140
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-slds-private-var",
141
+ "type": "problem",
142
+ "messages": {
143
+ "privateVar": "This styling hook is reserved for internal Salesforce use. Remove the --_slds- or \u2013slds-s private variable within selector {{prop}}. For more information, look up private CSS in lightningdesignsystem.com."
144
+ }
145
+ },
146
+ "enforce-component-hook-naming-convention": {
147
+ "description": "Replace component styling hooks that use a deprecated naming convention.",
148
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#enforce-component-hook-naming-convention",
149
+ "type": "problem",
150
+ "messages": {
151
+ "replace": "Replace the deprecated {{oldValue}} component styling hook with {{suggestedMatch}}."
152
+ }
153
+ },
154
+ "no-hardcoded-values-slds1": {
155
+ "description": "Replace static values with SLDS 1 design tokens. For more information, look up design tokens on lightningdesignsystem.com.",
156
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-value",
157
+ "type": "suggestion",
158
+ "messages": {
159
+ "hardcodedValue": "Replace the {{oldValue}} static value with an SLDS 1 styling hook: {{newValue}}.",
160
+ "noReplacement": "There's no replacement styling hook for the {{oldValue}} static value. Remove the static value."
161
+ }
162
+ },
163
+ "no-hardcoded-values-slds2": {
164
+ "description": "Replace static values with SLDS 2 styling hooks. For more information, look up design tokens on lightningdesignsystem.com.",
165
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-value",
166
+ "type": "suggestion",
167
+ "messages": {
168
+ "hardcodedValue": "Consider replacing the {{oldValue}} static value with an SLDS 2 styling hook that has a similar value: {{newValue}}.",
169
+ "noReplacement": "There's no replacement styling hook for the {{oldValue}} static value. Remove the static value."
170
+ }
171
+ },
172
+ "reduce-annotations": {
173
+ "description": "Remove your annotations and update your code.",
174
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#reduce-annotations",
175
+ "type": "problem",
176
+ "messages": {
177
+ "removeAnnotation": "Remove this annotation and update the code to SLDS best practices. For help, file an issue at https://github.com/salesforce-ux/slds-linter/"
178
+ }
179
+ }
180
+ };
181
+ }
182
+ });
183
+
184
+ // src/utils/node.ts
185
+ var import_parser = require("@html-eslint/parser");
186
+ function findAttr(node, key) {
187
+ return node.attributes.find(
188
+ (attr) => attr.key && attr.key.value.toLowerCase() === key.toLowerCase()
189
+ );
190
+ }
191
+ function isAttributesEmpty(node) {
192
+ return !node.attributes || node.attributes.length <= 0;
193
+ }
194
+ var lineBreakPattern = /\r\n|[\r\n\u2028\u2029]/u;
195
+ var lineEndingPattern = new RegExp(lineBreakPattern.source, "gu");
196
+
197
+ // src/rules/modal-close-button-issue.ts
198
+ var import_rule_messages = __toESM(require_rule_messages());
199
+ var ruleConfig = import_rule_messages.default["modal-close-button-issue"];
4
200
  module.exports = {
5
- meta: {
6
- type: "problem",
7
- docs: {
8
- category: "Best Practices",
9
- recommended: true,
10
- description: "Update component attributes or CSS classes for the modal close button to comply with the modal component blueprint.",
11
- url: "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#modal-close-button-issue"
12
- },
13
- fixable: "code",
14
- schema: [],
201
+ meta: {
202
+ type: ruleConfig.type,
203
+ docs: {
204
+ category: "Best Practices",
205
+ recommended: true,
206
+ description: ruleConfig.description,
207
+ url: ruleConfig.url
15
208
  },
16
- create(context) {
17
- function check(node) {
18
- if ((0, node_1.isAttributesEmpty)(node)) {
19
- return;
209
+ fixable: "code",
210
+ schema: [],
211
+ messages: ruleConfig.messages
212
+ },
213
+ create(context) {
214
+ function check(node) {
215
+ if (isAttributesEmpty(node)) {
216
+ return;
217
+ }
218
+ const tagName = node.name;
219
+ if (tagName === "button") {
220
+ const classAttr = findAttr(node, "class");
221
+ if (classAttr && classAttr.value) {
222
+ const classList = classAttr.value.value.split(/\s+/);
223
+ if (!classList.includes("slds-modal__close")) {
224
+ return;
225
+ }
226
+ if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
227
+ const newClassList = classList.filter((cls) => cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse").join(" ");
228
+ context.report({
229
+ node,
230
+ loc: classAttr.loc,
231
+ messageId: "removeClass",
232
+ fix(fixer) {
233
+ return fixer.replaceText(
234
+ classAttr,
235
+ // Replace the full attribute
236
+ `class="${newClassList}"`
237
+ // Updated class list
238
+ );
239
+ }
240
+ });
241
+ }
242
+ }
243
+ }
244
+ if (tagName === "lightning-button-icon" || tagName === "lightning:buttonIcon") {
245
+ let validateClassAttr = function(attribute, attrName) {
246
+ if (attribute && attribute.value) {
247
+ const classList = attribute.value.value.split(/\s+/);
248
+ if (!classAttr?.value?.value?.includes("slds-modal__close")) {
249
+ return;
20
250
  }
21
- const tagName = node.name;
22
- // Scenario 1: Remove 'slds-button_icon-inverse' from <button>
23
- // (optional) when the parent of the button has class name `slds-modal`
24
- // and also button should have class `slds-modal__close`
25
- if (tagName === "button") {
26
- const classAttr = (0, node_1.findAttr)(node, "class");
27
- if (classAttr && classAttr.value) {
28
- const classList = classAttr.value.value.split(/\s+/);
29
- // ✅ Ensure button has "slds-modal__close" before proceeding
30
- if (!classList.includes("slds-modal__close")) {
31
- return; // Stop execution if the class is missing
32
- }
33
- if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
34
- const newClassList = classList
35
- .filter((cls) => (cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse"))
36
- .join(" ");
37
- context.report({
38
- node,
39
- loc: classAttr.loc,
40
- message: rule_1.messages["removeClass"],
41
- fix(fixer) {
42
- return fixer.replaceText(classAttr, // Replace the full attribute
43
- `class="${newClassList}"` // Updated class list
44
- );
45
- },
46
- });
47
- }
251
+ if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
252
+ const newClassList = classList.filter((cls) => cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse").join(" ");
253
+ context.report({
254
+ node,
255
+ loc: attribute.loc,
256
+ messageId: "removeClass",
257
+ fix(fixer) {
258
+ return fixer.replaceText(
259
+ attribute,
260
+ // Replace the full attribute
261
+ `${attrName}="${newClassList}"`
262
+ // Correctly modifies the respective attribute
263
+ );
48
264
  }
265
+ });
49
266
  }
50
- // ✅ Scenario 2: Fix <lightning-button-icon> and this should have class `slds-modal__close`
51
- if (tagName === "lightning-button-icon" || tagName === "lightning:buttonIcon") {
52
- const variantAttr = (0, node_1.findAttr)(node, "variant");
53
- const sizeAttr = (0, node_1.findAttr)(node, "size");
54
- const classAttr = (0, node_1.findAttr)(node, "class");
55
- const iconClassAttr = (0, node_1.findAttr)(node, "icon-class"); // 🔍 Check for icon-class attribute
56
- function validateClassAttr(attribute, attrName) {
57
- if (attribute && attribute.value) {
58
- const classList = attribute.value.value.split(/\s+/);
59
- // Irrespective of whether we are checking for class or icon-class we need to check whether the attribute is present or not.
60
- // Ensure "slds-modal__close" exists before proceeding
61
- if (!classAttr?.value?.value?.includes("slds-modal__close")) {
62
- return;
63
- }
64
- // ✅ Ensure "slds-modal__close" exists before proceeding
65
- // if (!classList.includes("slds-modal__close")) {
66
- // return; // Stop execution if the class is missing
67
- // }
68
- // Remove inverse classes
69
- if (classList.includes("slds-button_icon-inverse") || classList.includes("slds-button--icon-inverse")) {
70
- const newClassList = classList
71
- .filter((cls) => cls !== "slds-button_icon-inverse" && cls !== "slds-button--icon-inverse")
72
- .join(" ");
73
- context.report({
74
- node,
75
- loc: attribute.loc,
76
- message: rule_1.messages["removeClass"],
77
- fix(fixer) {
78
- return fixer.replaceText(attribute, // Replace the full attribute
79
- `${attrName}="${newClassList}"` // Correctly modifies the respective attribute
80
- );
81
- },
82
- });
83
- }
84
- // Ensure 'slds-button' and 'slds-button_icon' exist
85
- if (!classList.includes("slds-button") || !classList.includes("slds-button_icon")) {
86
- let newClassList;
87
- if (attrName === 'icon-class') {
88
- newClassList = [
89
- ...classList.filter((cls) => cls !== "slds-button_icon-inverse"),
90
- ].join(" ");
91
- }
92
- else {
93
- newClassList = [
94
- "slds-button",
95
- "slds-button_icon",
96
- ...classList.filter((cls) => cls !== "slds-button_icon-inverse"),
97
- ].join(" ");
98
- }
99
- context.report({
100
- node: attribute,
101
- loc: attribute.value.loc,
102
- message: rule_1.messages["ensureButtonClasses"],
103
- fix(fixer) {
104
- return fixer.replaceText(attribute.value, `${newClassList}`);
105
- },
106
- });
107
- }
108
- // Fix variant="bare-inverse" to "bare"
109
- if (variantAttr && variantAttr.value && variantAttr.value.value === "bare-inverse") {
110
- context.report({
111
- node: variantAttr,
112
- message: rule_1.messages["changeVariant"],
113
- loc: variantAttr.value.loc,
114
- fix(fixer) {
115
- return fixer.replaceText(variantAttr.value, `bare`);
116
- },
117
- });
118
- }
119
- // Ensure size="large" exists
120
- // if (!sizeAttr) {
121
- // context.report({
122
- // node,
123
- // message: messages["ensureSizeAttribute"],
124
- // fix(fixer) {
125
- // if (variantAttr) {
126
- // return fixer.insertTextAfterRange([variantAttr.range[1], variantAttr.range[1]], ' size="large"');
127
- // }
128
- // },
129
- // });
130
- // }
131
- }
267
+ if (!classList.includes("slds-button") || !classList.includes("slds-button_icon")) {
268
+ let newClassList;
269
+ if (attrName === "icon-class") {
270
+ newClassList = [
271
+ ...classList.filter((cls) => cls !== "slds-button_icon-inverse")
272
+ ].join(" ");
273
+ } else {
274
+ newClassList = [
275
+ "slds-button",
276
+ "slds-button_icon",
277
+ ...classList.filter((cls) => cls !== "slds-button_icon-inverse")
278
+ ].join(" ");
279
+ }
280
+ context.report({
281
+ node: attribute,
282
+ loc: attribute.value.loc,
283
+ messageId: "ensureButtonClasses",
284
+ fix(fixer) {
285
+ return fixer.replaceText(attribute.value, `${newClassList}`);
132
286
  }
133
- // ✅ Validate `class` and `icon-class` separately, maintaining their own attribute names
134
- validateClassAttr(classAttr, "class");
135
- validateClassAttr(iconClassAttr, "icon-class");
287
+ });
136
288
  }
137
- // Scenario 3: Fix <lightning-icon> inside <button> & the class name of the parent name as button and it should have `slds-modal__close`
138
- if ((tagName === "lightning-icon" || tagName === "lightning:icon") && node.parent?.name === "button") {
139
- const parentClassAttr = (0, node_1.findAttr)(node.parent, "class");
140
- if (parentClassAttr && parentClassAttr.value) {
141
- const parentClassList = parentClassAttr.value.value.split(/\s+/);
142
- // ✅ Ensure the parent <button> has "slds-modal__close" before proceeding
143
- if (!parentClassList.includes("slds-modal__close")) {
144
- return; // Stop execution if the class is missing
145
- }
146
- const variantAttr = (0, node_1.findAttr)(node, "variant");
147
- const sizeAttr = (0, node_1.findAttr)(node, "size");
148
- // Fix variant="bare-inverse" to "bare"
149
- if (variantAttr && variantAttr.value && variantAttr.value.value === "bare-inverse") {
150
- context.report({
151
- node: variantAttr,
152
- message: rule_1.messages["changeVariant"],
153
- loc: variantAttr.value.loc,
154
- fix(fixer) {
155
- return fixer.replaceText(variantAttr.value, `bare`);
156
- },
157
- });
158
- }
159
- // // Remove variant attribute completely
160
- // if (variantAttr) {
161
- // context.report({
162
- // node: variantAttr,
163
- // messageId: "removeVariant",
164
- // fix(fixer) {
165
- // return fixer.remove(variantAttr);
166
- // },
167
- // });
168
- // }
169
- //Ensure size="large" is set
170
- // if (!sizeAttr) {
171
- // context.report({
172
- // node,
173
- // message: messages["ensureSizeAttribute"],
174
- // fix(fixer) {
175
- // //return fixer.insertTextAfter(node, ' size="large"');
176
- // if(variantAttr)
177
- // {
178
- // return fixer.insertTextAfterRange([variantAttr.range[1], variantAttr.range[1]], ' size="large"')
179
- // }
180
- // },
181
- // });
182
- // }
289
+ if (variantAttr && variantAttr.value && variantAttr.value.value === "bare-inverse") {
290
+ context.report({
291
+ node: variantAttr,
292
+ messageId: "changeVariant",
293
+ loc: variantAttr.value.loc,
294
+ fix(fixer) {
295
+ return fixer.replaceText(variantAttr.value, `bare`);
183
296
  }
297
+ });
184
298
  }
185
- }
186
- return {
187
- Tag: check,
299
+ }
188
300
  };
189
- },
301
+ const variantAttr = findAttr(node, "variant");
302
+ const sizeAttr = findAttr(node, "size");
303
+ const classAttr = findAttr(node, "class");
304
+ const iconClassAttr = findAttr(node, "icon-class");
305
+ validateClassAttr(classAttr, "class");
306
+ validateClassAttr(iconClassAttr, "icon-class");
307
+ }
308
+ if ((tagName === "lightning-icon" || tagName === "lightning:icon") && node.parent?.name === "button") {
309
+ const parentClassAttr = findAttr(node.parent, "class");
310
+ if (parentClassAttr && parentClassAttr.value) {
311
+ const parentClassList = parentClassAttr.value.value.split(/\s+/);
312
+ if (!parentClassList.includes("slds-modal__close")) {
313
+ return;
314
+ }
315
+ const variantAttr = findAttr(node, "variant");
316
+ const sizeAttr = findAttr(node, "size");
317
+ if (variantAttr && variantAttr.value && variantAttr.value.value === "bare-inverse") {
318
+ context.report({
319
+ node: variantAttr,
320
+ messageId: "changeVariant",
321
+ loc: variantAttr.value.loc,
322
+ fix(fixer) {
323
+ return fixer.replaceText(variantAttr.value, `bare`);
324
+ }
325
+ });
326
+ }
327
+ }
328
+ }
329
+ }
330
+ return {
331
+ Tag: check
332
+ };
333
+ }
190
334
  };
335
+ //# sourceMappingURL=modal-close-button-issue.js.map