@salesforce-ux/eslint-plugin-slds 1.0.2 → 1.0.3
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/index.js +113 -44
- package/build/index.js.map +3 -3
- package/build/rules/enforce-bem-usage.js +2 -2
- package/build/rules/enforce-bem-usage.js.map +2 -2
- package/build/rules/modal-close-button-issue.js +2 -2
- package/build/rules/modal-close-button-issue.js.map +2 -2
- package/build/rules/no-deprecated-classes-slds2.js +2 -2
- package/build/rules/no-deprecated-classes-slds2.js.map +2 -2
- package/build/rules/v9/enforce-bem-usage.js +2 -2
- package/build/rules/v9/enforce-bem-usage.js.map +2 -2
- package/build/rules/v9/enforce-component-hook-naming-convention.js +2 -2
- package/build/rules/v9/enforce-component-hook-naming-convention.js.map +2 -2
- package/build/rules/v9/enforce-sds-to-slds-hooks.js +2 -2
- package/build/rules/v9/enforce-sds-to-slds-hooks.js.map +2 -2
- package/build/rules/v9/lwc-token-to-slds-hook.js +45 -9
- package/build/rules/v9/lwc-token-to-slds-hook.js.map +3 -3
- package/build/rules/v9/no-deprecated-slds-classes.js +2 -2
- package/build/rules/v9/no-deprecated-slds-classes.js.map +2 -2
- package/build/rules/v9/no-deprecated-tokens-slds1.js +2 -2
- package/build/rules/v9/no-deprecated-tokens-slds1.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +2 -2
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +2 -2
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +2 -2
- package/build/rules/v9/no-slds-class-overrides.js +2 -2
- package/build/rules/v9/no-slds-class-overrides.js.map +2 -2
- package/build/rules/v9/no-slds-namespace-for-custom-hooks.js +137 -26
- package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +4 -4
- package/build/rules/v9/no-slds-private-var.js +2 -2
- package/build/rules/v9/no-slds-private-var.js.map +2 -2
- package/build/rules/v9/no-slds-var-without-fallback.js +15 -12
- package/build/rules/v9/no-slds-var-without-fallback.js.map +3 -3
- package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js +2 -2
- package/build/rules/v9/no-sldshook-fallback-for-lwctoken.js.map +2 -2
- package/build/rules/v9/no-unsupported-hooks-slds2.js +2 -2
- package/build/rules/v9/no-unsupported-hooks-slds2.js.map +2 -2
- package/build/rules/v9/reduce-annotations.js +2 -2
- package/build/rules/v9/reduce-annotations.js.map +2 -2
- package/build/src/utils/css-utils.d.ts +6 -0
- package/build/utils/css-utils.js +24 -10
- package/build/utils/css-utils.js.map +2 -2
- 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
|
|
48
|
+
// yaml-file:rule-messages.yml
|
|
49
49
|
var require_rule_messages = __commonJS({
|
|
50
|
-
"yaml-file
|
|
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
|
|
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
|
|
1075
|
+
if (!variableName) {
|
|
1076
1076
|
return null;
|
|
1077
1077
|
}
|
|
1078
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -1119,6 +1131,32 @@ function getRecommendation(lwcToken) {
|
|
|
1119
1131
|
const hasRecommendation = oldValue in lwcToSlds && replacementCategory !== "empty" /* EMPTY */;
|
|
1120
1132
|
return { hasRecommendation, recommendation, replacementCategory };
|
|
1121
1133
|
}
|
|
1134
|
+
function extractLwcVariableWithFallback(node, sourceCode) {
|
|
1135
|
+
if (!node?.children || node.type !== "Function" || node.name !== "var") {
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
const children = Array.from(node.children);
|
|
1139
|
+
const firstChild = children[0];
|
|
1140
|
+
if (!firstChild?.name?.startsWith("--lwc-") || firstChild.type !== "Identifier") {
|
|
1141
|
+
return null;
|
|
1142
|
+
}
|
|
1143
|
+
const commaIndex = children.findIndex(
|
|
1144
|
+
(child) => child.type === "Operator" && child.value === ","
|
|
1145
|
+
);
|
|
1146
|
+
let fallbackValue = null;
|
|
1147
|
+
if (commaIndex !== -1 && commaIndex + 1 < children.length) {
|
|
1148
|
+
const fallbackStart = children[commaIndex + 1];
|
|
1149
|
+
const fallbackEnd = children[children.length - 1];
|
|
1150
|
+
if (fallbackStart?.loc && fallbackEnd?.loc) {
|
|
1151
|
+
const fullText = sourceCode.getText();
|
|
1152
|
+
fallbackValue = fullText.substring(fallbackStart.loc.start.offset, fallbackEnd.loc.end.offset).trim();
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
return {
|
|
1156
|
+
lwcToken: firstChild.name,
|
|
1157
|
+
fallbackValue
|
|
1158
|
+
};
|
|
1159
|
+
}
|
|
1122
1160
|
function getReportMessage(cssVar, replacementCategory, recommendation) {
|
|
1123
1161
|
if (!recommendation) {
|
|
1124
1162
|
return {
|
|
@@ -1168,6 +1206,12 @@ var lwc_token_to_slds_hook_default = {
|
|
|
1168
1206
|
if (textAtPosition === oldValue) {
|
|
1169
1207
|
return fixer.replaceTextRange([propertyStart, propertyEnd], suggestedMatch);
|
|
1170
1208
|
}
|
|
1209
|
+
} else if (node.type === "Function" && node.name === "var") {
|
|
1210
|
+
const sourceCode = context.sourceCode;
|
|
1211
|
+
const fullText = sourceCode.getText();
|
|
1212
|
+
const nodeOffset = node.loc.start.offset;
|
|
1213
|
+
const nodeEnd = node.loc.end.offset;
|
|
1214
|
+
return fixer.replaceTextRange([nodeOffset, nodeEnd], suggestedMatch);
|
|
1171
1215
|
} else {
|
|
1172
1216
|
const sourceCode = context.sourceCode;
|
|
1173
1217
|
const fullText = sourceCode.getText();
|
|
@@ -1206,23 +1250,27 @@ var lwc_token_to_slds_hook_default = {
|
|
|
1206
1250
|
reportAndFix(node, property, suggestedMatch, messageId, data);
|
|
1207
1251
|
},
|
|
1208
1252
|
// LWC tokens inside var() functions: var(--lwc-*)
|
|
1209
|
-
"Function[name='var']
|
|
1210
|
-
const
|
|
1211
|
-
if (
|
|
1253
|
+
"Function[name='var']"(node) {
|
|
1254
|
+
const lwcVarInfo = extractLwcVariableWithFallback(node, context.sourceCode);
|
|
1255
|
+
if (!lwcVarInfo) {
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
const { lwcToken, fallbackValue } = lwcVarInfo;
|
|
1259
|
+
if (shouldIgnoreDetection(lwcToken)) {
|
|
1212
1260
|
return;
|
|
1213
1261
|
}
|
|
1214
|
-
const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(
|
|
1215
|
-
const { messageId, data } = getReportMessage(
|
|
1262
|
+
const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(lwcToken);
|
|
1263
|
+
const { messageId, data } = getReportMessage(lwcToken, replacementCategory, recommendation);
|
|
1216
1264
|
let suggestedMatch = null;
|
|
1217
1265
|
if (hasRecommendation) {
|
|
1218
1266
|
if (replacementCategory === "slds_token" /* SLDS_TOKEN */) {
|
|
1219
|
-
const originalVarCall = `var(${
|
|
1267
|
+
const originalVarCall = fallbackValue ? `var(${lwcToken}, ${fallbackValue})` : `var(${lwcToken})`;
|
|
1220
1268
|
suggestedMatch = `var(${recommendation}, ${originalVarCall})`;
|
|
1221
1269
|
} else if (replacementCategory === "raw_value" /* RAW_VALUE */) {
|
|
1222
1270
|
suggestedMatch = recommendation;
|
|
1223
1271
|
}
|
|
1224
1272
|
}
|
|
1225
|
-
reportAndFix(node,
|
|
1273
|
+
reportAndFix(node, lwcToken, suggestedMatch, messageId, data);
|
|
1226
1274
|
}
|
|
1227
1275
|
};
|
|
1228
1276
|
}
|
|
@@ -1467,7 +1515,7 @@ var import_rule_messages10 = __toESM(require_rule_messages());
|
|
|
1467
1515
|
var ruleConfig8 = import_rule_messages10.default["no-slds-namespace-for-custom-hooks"];
|
|
1468
1516
|
var { type: type9, description: description9, url: url9, messages: messages9 } = ruleConfig8;
|
|
1469
1517
|
var sldsPlusStylingHooks3 = import_sds_metadata10.default.sldsPlusStylingHooks;
|
|
1470
|
-
var allSldsHooks3 = [...sldsPlusStylingHooks3.global, ...sldsPlusStylingHooks3.component];
|
|
1518
|
+
var allSldsHooks3 = [...sldsPlusStylingHooks3.global, ...sldsPlusStylingHooks3.component, ...sldsPlusStylingHooks3.shared];
|
|
1471
1519
|
var toSldsToken2 = (sdsToken) => sdsToken.replace("--sds-", "--slds-");
|
|
1472
1520
|
function shouldIgnoreDetection4(sdsToken) {
|
|
1473
1521
|
if (sdsToken.startsWith("--sds-") || sdsToken.startsWith("--slds-")) {
|
|
@@ -1486,33 +1534,54 @@ var no_slds_namespace_for_custom_hooks_default = {
|
|
|
1486
1534
|
messages: messages9
|
|
1487
1535
|
},
|
|
1488
1536
|
create(context) {
|
|
1489
|
-
function reportViolation(node, token) {
|
|
1490
|
-
const tokenWithoutNamespace = token.replace("--slds-", "").replace("--sds-", "");
|
|
1491
|
-
context.report({
|
|
1492
|
-
node,
|
|
1493
|
-
messageId: "customHookNamespace",
|
|
1494
|
-
data: {
|
|
1495
|
-
token,
|
|
1496
|
-
tokenWithoutNamespace
|
|
1497
|
-
}
|
|
1498
|
-
});
|
|
1499
|
-
}
|
|
1500
1537
|
return {
|
|
1501
|
-
|
|
1502
|
-
"Declaration[property=/^--s(lds|ds)-/]"(node) {
|
|
1538
|
+
"Declaration"(node) {
|
|
1503
1539
|
const property = node.property;
|
|
1504
|
-
if (shouldIgnoreDetection4(property)) {
|
|
1505
|
-
|
|
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
|
+
});
|
|
1506
1552
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
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
|
+
});
|
|
1514
1584
|
}
|
|
1515
|
-
reportViolation(node, tokenName);
|
|
1516
1585
|
}
|
|
1517
1586
|
};
|
|
1518
1587
|
}
|
|
@@ -2313,7 +2382,7 @@ var rules = {
|
|
|
2313
2382
|
var plugin = {
|
|
2314
2383
|
meta: {
|
|
2315
2384
|
name: "@salesforce-ux/eslint-plugin-slds",
|
|
2316
|
-
version: "1.0.
|
|
2385
|
+
version: "1.0.3"
|
|
2317
2386
|
},
|
|
2318
2387
|
rules,
|
|
2319
2388
|
configs: {}
|