@salesforce-ux/eslint-plugin-slds 1.0.3-internal → 1.0.4-internal

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 (48) hide show
  1. package/build/index.js +70 -37
  2. package/build/index.js.map +3 -3
  3. package/build/rules/enforce-bem-usage.js +2 -2
  4. package/build/rules/enforce-bem-usage.js.map +2 -2
  5. package/build/rules/modal-close-button-issue.js +2 -2
  6. package/build/rules/modal-close-button-issue.js.map +2 -2
  7. package/build/rules/no-deprecated-classes-slds2.js +2 -2
  8. package/build/rules/no-deprecated-classes-slds2.js.map +2 -2
  9. package/build/rules/v9/enforce-bem-usage.js +2 -2
  10. package/build/rules/v9/enforce-bem-usage.js.map +2 -2
  11. package/build/rules/v9/enforce-component-hook-naming-convention.js +2 -2
  12. package/build/rules/v9/enforce-component-hook-naming-convention.js.map +2 -2
  13. package/build/rules/v9/enforce-sds-to-slds-hooks.js +2 -2
  14. package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +2 -2
  15. package/build/rules/v9/lwc-token-to-slds-hook.js +2 -2
  16. package/build/rules/v9/lwc-token-to-slds-hook.js.map +3 -3
  17. package/build/rules/v9/no-deprecated-slds-classes.js +2 -2
  18. package/build/rules/v9/no-deprecated-slds-classes.js.map +2 -2
  19. package/build/rules/v9/no-deprecated-tokens-slds1.js +2 -2
  20. package/build/rules/v9/no-deprecated-tokens-slds1.js.map +2 -2
  21. package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +2 -2
  22. package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +2 -2
  23. package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +2 -2
  24. package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +2 -2
  25. package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +2 -2
  26. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +2 -2
  27. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +3 -3
  28. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +2 -2
  29. package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +3 -3
  30. package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +2 -2
  31. package/build/rules/v9/no-slds-class-overrides.js +2 -2
  32. package/build/rules/v9/no-slds-class-overrides.js.map +2 -2
  33. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +137 -26
  34. package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +4 -4
  35. package/build/rules/v9/no-slds-private-var.js +2 -2
  36. package/build/rules/v9/no-slds-private-var.js.map +2 -2
  37. package/build/rules/v9/no-slds-var-without-fallback.js +15 -12
  38. package/build/rules/v9/no-slds-var-without-fallback.js.map +3 -3
  39. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +2 -2
  40. package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +2 -2
  41. package/build/rules/v9/no-unsupported-hooks-slds2.js +2 -2
  42. package/build/rules/v9/no-unsupported-hooks-slds2.js.map +2 -2
  43. package/build/rules/v9/reduce-annotations.js +2 -2
  44. package/build/rules/v9/reduce-annotations.js.map +2 -2
  45. package/build/src/utils/css-utils.d.ts +6 -0
  46. package/build/utils/css-utils.js +24 -10
  47. package/build/utils/css-utils.js.map +2 -2
  48. package/package.json +2 -2
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",
@@ -1056,7 +1056,7 @@ function forEachFontValue(valueText, callback) {
1056
1056
  }
1057
1057
 
1058
1058
  // src/utils/css-utils.ts
1059
- function extractSldsVariable(node) {
1059
+ function extractCssVariable(node, filter) {
1060
1060
  if (!node || node.type !== "Function" || node.name !== "var") {
1061
1061
  return null;
1062
1062
  }
@@ -1072,19 +1072,31 @@ function extractSldsVariable(node) {
1072
1072
  return null;
1073
1073
  }
1074
1074
  const variableName = firstChild.name;
1075
- if (!variableName || !variableName.startsWith("--slds-")) {
1075
+ if (!variableName) {
1076
1076
  return null;
1077
1077
  }
1078
- const hasFallback = childrenArray.some(
1079
- (child) => child.type === "Operator" && child.value === ","
1080
- );
1081
- return {
1082
- name: variableName,
1083
- hasFallback
1084
- };
1078
+ return filter(variableName, childrenArray);
1085
1079
  }
1086
1080
  function forEachSldsVariable(valueText, callback) {
1087
- forEachValue(valueText, extractSldsVariable, () => false, callback);
1081
+ const extractor = (node) => extractCssVariable(node, (variableName, childrenArray) => {
1082
+ if (!variableName.startsWith("--slds-")) {
1083
+ return null;
1084
+ }
1085
+ const hasFallback = childrenArray.some(
1086
+ (child) => child.type === "Operator" && child.value === ","
1087
+ );
1088
+ return { name: variableName, hasFallback };
1089
+ });
1090
+ forEachValue(valueText, extractor, () => false, callback);
1091
+ }
1092
+ function forEachNamespacedVariable(valueText, callback) {
1093
+ const extractor = (node) => extractCssVariable(node, (variableName) => {
1094
+ if (variableName.startsWith("--slds-") || variableName.startsWith("--sds-")) {
1095
+ return { name: variableName, hasFallback: false };
1096
+ }
1097
+ return null;
1098
+ });
1099
+ forEachValue(valueText, extractor, () => false, callback);
1088
1100
  }
1089
1101
  function formatSuggestionHooks(hooks) {
1090
1102
  if (hooks.length === 1) {
@@ -1503,7 +1515,7 @@ var import_rule_messages10 = __toESM(require_rule_messages());
1503
1515
  var ruleConfig8 = import_rule_messages10.default["no-slds-namespace-for-custom-hooks"];
1504
1516
  var { type: type9, description: description9, url: url9, messages: messages9 } = ruleConfig8;
1505
1517
  var sldsPlusStylingHooks3 = import_next10.default.sldsPlusStylingHooks;
1506
- var allSldsHooks3 = [...sldsPlusStylingHooks3.global, ...sldsPlusStylingHooks3.component];
1518
+ var allSldsHooks3 = [...sldsPlusStylingHooks3.global, ...sldsPlusStylingHooks3.component, ...sldsPlusStylingHooks3.shared];
1507
1519
  var toSldsToken2 = (sdsToken) => sdsToken.replace("--sds-", "--slds-");
1508
1520
  function shouldIgnoreDetection4(sdsToken) {
1509
1521
  if (sdsToken.startsWith("--sds-") || sdsToken.startsWith("--slds-")) {
@@ -1522,33 +1534,54 @@ var no_slds_namespace_for_custom_hooks_default = {
1522
1534
  messages: messages9
1523
1535
  },
1524
1536
  create(context) {
1525
- function reportViolation(node, token) {
1526
- const tokenWithoutNamespace = token.replace("--slds-", "").replace("--sds-", "");
1527
- context.report({
1528
- node,
1529
- messageId: "customHookNamespace",
1530
- data: {
1531
- token,
1532
- tokenWithoutNamespace
1533
- }
1534
- });
1535
- }
1536
1537
  return {
1537
- // CSS custom property declarations: --slds-* and --sds-* properties
1538
- "Declaration[property=/^--s(lds|ds)-/]"(node) {
1538
+ "Declaration"(node) {
1539
1539
  const property = node.property;
1540
- if (shouldIgnoreDetection4(property)) {
1541
- return;
1540
+ if (property && (property.startsWith("--slds-") || property.startsWith("--sds-")) && !shouldIgnoreDetection4(property)) {
1541
+ const tokenWithoutNamespace = property.replace("--slds-", "").replace("--sds-", "");
1542
+ context.report({
1543
+ node,
1544
+ loc: node.loc,
1545
+ // Use full declaration loc which includes the property
1546
+ messageId: "customHookNamespace",
1547
+ data: {
1548
+ token: property,
1549
+ tokenWithoutNamespace
1550
+ }
1551
+ });
1542
1552
  }
1543
- reportViolation(node, property);
1544
- },
1545
- // SLDS/SDS tokens inside var() functions: var(--slds-*) or var(--sds-*)
1546
- "Function[name='var'] Identifier[name=/^--s(lds|ds)-/]"(node) {
1547
- const tokenName = node.name;
1548
- if (shouldIgnoreDetection4(tokenName)) {
1549
- return;
1553
+ const valueText = context.sourceCode.getText(node.value);
1554
+ if (valueText) {
1555
+ forEachNamespacedVariable(valueText, (variableInfo, positionInfo) => {
1556
+ const { name: tokenName } = variableInfo;
1557
+ if (!shouldIgnoreDetection4(tokenName)) {
1558
+ const tokenWithoutNamespace = tokenName.replace("--slds-", "").replace("--sds-", "");
1559
+ if (positionInfo.start && positionInfo.end && node.value.loc) {
1560
+ context.report({
1561
+ node,
1562
+ loc: {
1563
+ start: {
1564
+ line: node.value.loc.start.line + positionInfo.start.line - 1,
1565
+ column: node.value.loc.start.column + positionInfo.start.column - 1
1566
+ },
1567
+ end: {
1568
+ line: node.value.loc.start.line + positionInfo.end.line - 1,
1569
+ column: node.value.loc.start.column + positionInfo.end.column - 1
1570
+ }
1571
+ },
1572
+ messageId: "customHookNamespace",
1573
+ data: { token: tokenName, tokenWithoutNamespace }
1574
+ });
1575
+ } else {
1576
+ context.report({
1577
+ node,
1578
+ messageId: "customHookNamespace",
1579
+ data: { token: tokenName, tokenWithoutNamespace }
1580
+ });
1581
+ }
1582
+ }
1583
+ });
1550
1584
  }
1551
- reportViolation(node, tokenName);
1552
1585
  }
1553
1586
  };
1554
1587
  }
@@ -2352,7 +2385,7 @@ var rules = {
2352
2385
  var plugin = {
2353
2386
  meta: {
2354
2387
  name: "@salesforce-ux/eslint-plugin-slds",
2355
- version: "1.0.3-internal"
2388
+ version: "1.0.4-internal"
2356
2389
  },
2357
2390
  rules,
2358
2391
  configs: {}