@salesforce-ux/eslint-plugin-slds 1.0.1 → 1.0.2-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 (41) hide show
  1. package/README.md +1 -0
  2. package/build/index.js +48 -11
  3. package/build/index.js.map +3 -3
  4. package/build/rules/enforce-bem-usage.js +3 -3
  5. package/build/rules/enforce-bem-usage.js.map +3 -3
  6. package/build/rules/modal-close-button-issue.js +3 -3
  7. package/build/rules/modal-close-button-issue.js.map +3 -3
  8. package/build/rules/no-deprecated-classes-slds2.js +3 -3
  9. package/build/rules/no-deprecated-classes-slds2.js.map +3 -3
  10. package/build/rules/v9/enforce-bem-usage.js +3 -3
  11. package/build/rules/v9/enforce-bem-usage.js.map +3 -3
  12. package/build/rules/v9/enforce-component-hook-naming-convention.js +3 -3
  13. package/build/rules/v9/enforce-component-hook-naming-convention.js.map +3 -3
  14. package/build/rules/v9/enforce-sds-to-slds-hooks.js +3 -3
  15. package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +3 -3
  16. package/build/rules/v9/lwc-token-to-slds-hook.js +46 -10
  17. package/build/rules/v9/lwc-token-to-slds-hook.js.map +3 -3
  18. package/build/rules/v9/no-deprecated-slds-classes.js +3 -3
  19. package/build/rules/v9/no-deprecated-slds-classes.js.map +3 -3
  20. package/build/rules/v9/no-deprecated-tokens-slds1.js +3 -3
  21. package/build/rules/v9/no-deprecated-tokens-slds1.js.map +3 -3
  22. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +3 -3
  23. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +3 -3
  24. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +3 -3
  25. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +3 -3
  26. package/build/rules/v9/no-slds-class-overrides.js +3 -3
  27. package/build/rules/v9/no-slds-class-overrides.js.map +3 -3
  28. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +3 -3
  29. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +3 -3
  30. package/build/rules/v9/no-slds-private-var.js +3 -3
  31. package/build/rules/v9/no-slds-private-var.js.map +3 -3
  32. package/build/rules/v9/no-slds-var-without-fallback.js +3 -3
  33. package/build/rules/v9/no-slds-var-without-fallback.js.map +3 -3
  34. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +3 -3
  35. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +3 -3
  36. package/build/rules/v9/no-unsupported-hooks-slds2.js +3 -3
  37. package/build/rules/v9/no-unsupported-hooks-slds2.js.map +3 -3
  38. package/build/rules/v9/reduce-annotations.js +3 -3
  39. package/build/rules/v9/reduce-annotations.js.map +3 -3
  40. package/package.json +2 -2
  41. package/src/config/rule-messages.yml +1 -1
package/README.md CHANGED
@@ -67,6 +67,7 @@ By default, the latest version of the plugin supports legacy and flat config sys
67
67
  - `enforce-component-hook-naming-convention`: Identifies --slds-c component-level styling hooks that use a deprecated naming convention.
68
68
  - `no-deprecated-slds-classes`: Please replace the deprecated classes with a modern equivalent.
69
69
  - `reduce-annotations`: Identifies annotations that must be removed from the code.
70
+ - `lwc-token-to-slds-hook`: Identifies the deprecated --lwc tokens that must be replaced with the latest --slds tokens. For more information, see lightningdesignsystem.com.
70
71
 
71
72
  ## License
72
73
 
package/build/index.js CHANGED
@@ -45,9 +45,9 @@ var init_node = __esm({
45
45
  }
46
46
  });
47
47
 
48
- // yaml-file:/Users/ritesh.kumar2/Documents/projects/stylelint-sds/packages/eslint-plugin-slds/src/config/rule-messages.yml
48
+ // yaml-file:rule-messages.yml
49
49
  var require_rule_messages = __commonJS({
50
- "yaml-file:/Users/ritesh.kumar2/Documents/projects/stylelint-sds/packages/eslint-plugin-slds/src/config/rule-messages.yml"(exports2, module2) {
50
+ "yaml-file:rule-messages.yml"(exports2, module2) {
51
51
  module2.exports = {
52
52
  "no-slds-class-overrides": {
53
53
  "description": "Create new custom CSS classes instead of overriding SLDS selectors",
@@ -183,7 +183,7 @@ var require_rule_messages = __commonJS({
183
183
  },
184
184
  "no-hardcoded-values-slds2": {
185
185
  "description": "Replace static values with SLDS 2 styling hooks. For more information, look up design tokens on lightningdesignsystem.com.",
186
- "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-value",
186
+ "url": "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-hardcoded-values-slds2",
187
187
  "type": "suggestion",
188
188
  "messages": {
189
189
  "hardcodedValue": "Consider replacing the {{oldValue}} static value with an SLDS 2 styling hook that has a similar value: {{newValue}}.",
@@ -1119,6 +1119,32 @@ function getRecommendation(lwcToken) {
1119
1119
  const hasRecommendation = oldValue in lwcToSlds && replacementCategory !== "empty" /* EMPTY */;
1120
1120
  return { hasRecommendation, recommendation, replacementCategory };
1121
1121
  }
1122
+ function extractLwcVariableWithFallback(node, sourceCode) {
1123
+ if (!node?.children || node.type !== "Function" || node.name !== "var") {
1124
+ return null;
1125
+ }
1126
+ const children = Array.from(node.children);
1127
+ const firstChild = children[0];
1128
+ if (!firstChild?.name?.startsWith("--lwc-") || firstChild.type !== "Identifier") {
1129
+ return null;
1130
+ }
1131
+ const commaIndex = children.findIndex(
1132
+ (child) => child.type === "Operator" && child.value === ","
1133
+ );
1134
+ let fallbackValue = null;
1135
+ if (commaIndex !== -1 && commaIndex + 1 < children.length) {
1136
+ const fallbackStart = children[commaIndex + 1];
1137
+ const fallbackEnd = children[children.length - 1];
1138
+ if (fallbackStart?.loc && fallbackEnd?.loc) {
1139
+ const fullText = sourceCode.getText();
1140
+ fallbackValue = fullText.substring(fallbackStart.loc.start.offset, fallbackEnd.loc.end.offset).trim();
1141
+ }
1142
+ }
1143
+ return {
1144
+ lwcToken: firstChild.name,
1145
+ fallbackValue
1146
+ };
1147
+ }
1122
1148
  function getReportMessage(cssVar, replacementCategory, recommendation) {
1123
1149
  if (!recommendation) {
1124
1150
  return {
@@ -1168,6 +1194,12 @@ var lwc_token_to_slds_hook_default = {
1168
1194
  if (textAtPosition === oldValue) {
1169
1195
  return fixer.replaceTextRange([propertyStart, propertyEnd], suggestedMatch);
1170
1196
  }
1197
+ } else if (node.type === "Function" && node.name === "var") {
1198
+ const sourceCode = context.sourceCode;
1199
+ const fullText = sourceCode.getText();
1200
+ const nodeOffset = node.loc.start.offset;
1201
+ const nodeEnd = node.loc.end.offset;
1202
+ return fixer.replaceTextRange([nodeOffset, nodeEnd], suggestedMatch);
1171
1203
  } else {
1172
1204
  const sourceCode = context.sourceCode;
1173
1205
  const fullText = sourceCode.getText();
@@ -1206,23 +1238,27 @@ var lwc_token_to_slds_hook_default = {
1206
1238
  reportAndFix(node, property, suggestedMatch, messageId, data);
1207
1239
  },
1208
1240
  // LWC tokens inside var() functions: var(--lwc-*)
1209
- "Function[name='var'] Identifier[name=/^--lwc-/]"(node) {
1210
- const tokenName = node.name;
1211
- if (shouldIgnoreDetection(tokenName)) {
1241
+ "Function[name='var']"(node) {
1242
+ const lwcVarInfo = extractLwcVariableWithFallback(node, context.sourceCode);
1243
+ if (!lwcVarInfo) {
1244
+ return;
1245
+ }
1246
+ const { lwcToken, fallbackValue } = lwcVarInfo;
1247
+ if (shouldIgnoreDetection(lwcToken)) {
1212
1248
  return;
1213
1249
  }
1214
- const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(tokenName);
1215
- const { messageId, data } = getReportMessage(tokenName, replacementCategory, recommendation);
1250
+ const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(lwcToken);
1251
+ const { messageId, data } = getReportMessage(lwcToken, replacementCategory, recommendation);
1216
1252
  let suggestedMatch = null;
1217
1253
  if (hasRecommendation) {
1218
1254
  if (replacementCategory === "slds_token" /* SLDS_TOKEN */) {
1219
- const originalVarCall = `var(${tokenName})`;
1255
+ const originalVarCall = fallbackValue ? `var(${lwcToken}, ${fallbackValue})` : `var(${lwcToken})`;
1220
1256
  suggestedMatch = `var(${recommendation}, ${originalVarCall})`;
1221
1257
  } else if (replacementCategory === "raw_value" /* RAW_VALUE */) {
1222
1258
  suggestedMatch = recommendation;
1223
1259
  }
1224
1260
  }
1225
- reportAndFix(node, tokenName, suggestedMatch, messageId, data);
1261
+ reportAndFix(node, lwcToken, suggestedMatch, messageId, data);
1226
1262
  }
1227
1263
  };
1228
1264
  }
@@ -2272,6 +2308,7 @@ var eslint_rules_default = {
2272
2308
  css: {
2273
2309
  "@salesforce-ux/slds/no-slds-class-overrides": "warn",
2274
2310
  "@salesforce-ux/slds/no-deprecated-slds-classes": "warn",
2311
+ "@salesforce-ux/slds/lwc-token-to-slds-hook": "error",
2275
2312
  "@salesforce-ux/slds/enforce-sds-to-slds-hooks": "warn",
2276
2313
  "@salesforce-ux/slds/no-sldshook-fallback-for-lwctoken": "warn",
2277
2314
  "@salesforce-ux/slds/no-unsupported-hooks-slds2": "warn",
@@ -2312,7 +2349,7 @@ var rules = {
2312
2349
  var plugin = {
2313
2350
  meta: {
2314
2351
  name: "@salesforce-ux/eslint-plugin-slds",
2315
- version: "1.0.1"
2352
+ version: "1.0.2-alpha.0"
2316
2353
  },
2317
2354
  rules,
2318
2355
  configs: {}