@salesforce-ux/eslint-plugin-slds 1.0.0-internal-alpha.0 → 1.0.1
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/README.md +17 -1
- package/build/index.js +1072 -1016
- package/build/index.js.map +4 -4
- package/build/rules/enforce-bem-usage.js +5 -5
- package/build/rules/enforce-bem-usage.js.map +3 -3
- 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 +42 -3
- package/build/rules/v9/lwc-token-to-slds-hook.js.map +4 -4
- 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 +49 -54
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +9 -2
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +14 -3
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +14 -3
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/index.js +86 -90
- package/build/rules/v9/no-hardcoded-values/handlers/index.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js +116 -96
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +4 -4
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +116 -96
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +4 -4
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +110 -92
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +3 -3
- 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 +2 -2
- package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +2 -2
- package/build/rules/v9/no-slds-var-without-fallback.js +121 -35
- package/build/rules/v9/no-slds-var-without-fallback.js.map +4 -4
- 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/src/rules/v9/no-hardcoded-values/noHardcodedValueRule.d.ts +3 -1
- package/build/src/rules/v9/no-slds-var-without-fallback.d.ts +4 -0
- package/build/src/utils/css-utils.d.ts +19 -0
- package/build/src/utils/rule-utils.d.ts +8 -0
- package/build/src/utils/value-utils.d.ts +3 -2
- package/build/types/index.js.map +1 -1
- package/build/utils/boxShadowValueParser.js +4 -1
- package/build/utils/boxShadowValueParser.js.map +2 -2
- package/build/utils/color-lib-utils.js.map +1 -1
- package/build/utils/css-utils.js +108 -0
- package/build/utils/css-utils.js.map +4 -4
- package/build/utils/hardcoded-shared-utils.js +5 -2
- package/build/utils/hardcoded-shared-utils.js.map +3 -3
- package/build/utils/property-matcher.js +1 -1
- package/build/utils/property-matcher.js.map +2 -2
- package/build/utils/rule-utils.js +46 -0
- package/build/utils/rule-utils.js.map +7 -0
- package/build/utils/styling-hook-utils.js +4 -1
- package/build/utils/styling-hook-utils.js.map +2 -2
- package/build/utils/value-utils.js +6 -1
- package/build/utils/value-utils.js.map +2 -2
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -203,13 +203,13 @@ var require_rule_messages = __commonJS({
|
|
|
203
203
|
});
|
|
204
204
|
|
|
205
205
|
// src/rules/v9/enforce-bem-usage.ts
|
|
206
|
-
var
|
|
206
|
+
var import_sds_metadata, import_rule_messages, type, description, url, messages, bemMapping, enforce_bem_usage_default;
|
|
207
207
|
var init_enforce_bem_usage = __esm({
|
|
208
208
|
"src/rules/v9/enforce-bem-usage.ts"() {
|
|
209
|
-
|
|
209
|
+
import_sds_metadata = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
210
210
|
import_rule_messages = __toESM(require_rule_messages());
|
|
211
211
|
({ type, description, url, messages } = import_rule_messages.default["enforce-bem-usage"]);
|
|
212
|
-
bemMapping =
|
|
212
|
+
bemMapping = import_sds_metadata.default.bemNaming;
|
|
213
213
|
enforce_bem_usage_default = {
|
|
214
214
|
meta: {
|
|
215
215
|
type,
|
|
@@ -254,11 +254,11 @@ var init_enforce_bem_usage = __esm({
|
|
|
254
254
|
var require_enforce_bem_usage = __commonJS({
|
|
255
255
|
"src/rules/enforce-bem-usage.ts"(exports2, module2) {
|
|
256
256
|
init_node();
|
|
257
|
-
var
|
|
257
|
+
var import_sds_metadata14 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
258
258
|
var import_rule_messages16 = __toESM(require_rule_messages());
|
|
259
259
|
init_enforce_bem_usage();
|
|
260
|
-
var bemMapping2 =
|
|
261
|
-
var deprecatedClasses2 =
|
|
260
|
+
var bemMapping2 = import_sds_metadata14.default.bemNaming;
|
|
261
|
+
var deprecatedClasses2 = import_sds_metadata14.default.deprecatedClasses;
|
|
262
262
|
var ruleConfig14 = import_rule_messages16.default["enforce-bem-usage"];
|
|
263
263
|
var { type: type15, description: description15, url: url15, messages: messages15 } = ruleConfig14;
|
|
264
264
|
var isDeprecatedClass = (className) => {
|
|
@@ -349,9 +349,9 @@ var require_enforce_bem_usage = __commonJS({
|
|
|
349
349
|
var require_no_deprecated_classes_slds2 = __commonJS({
|
|
350
350
|
"src/rules/no-deprecated-classes-slds2.ts"(exports2, module2) {
|
|
351
351
|
init_node();
|
|
352
|
-
var
|
|
352
|
+
var import_sds_metadata14 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
353
353
|
var import_rule_messages16 = __toESM(require_rule_messages());
|
|
354
|
-
var deprecatedClasses2 =
|
|
354
|
+
var deprecatedClasses2 = import_sds_metadata14.default.deprecatedClasses;
|
|
355
355
|
var ruleConfig14 = import_rule_messages16.default["no-deprecated-classes-slds2"];
|
|
356
356
|
module2.exports = {
|
|
357
357
|
meta: {
|
|
@@ -555,10 +555,10 @@ var import_no_deprecated_classes_slds2 = __toESM(require_no_deprecated_classes_s
|
|
|
555
555
|
var import_modal_close_button_issue = __toESM(require_modal_close_button_issue());
|
|
556
556
|
|
|
557
557
|
// src/rules/v9/no-slds-class-overrides.ts
|
|
558
|
-
var
|
|
558
|
+
var import_sds_metadata2 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
559
559
|
var import_rule_messages2 = __toESM(require_rule_messages());
|
|
560
560
|
var ruleConfig = import_rule_messages2.default["no-slds-class-overrides"];
|
|
561
|
-
var sldsClasses =
|
|
561
|
+
var sldsClasses = import_sds_metadata2.default.sldsPlusClasses;
|
|
562
562
|
var sldsClassesSet = new Set(sldsClasses);
|
|
563
563
|
var no_slds_class_overrides_default = {
|
|
564
564
|
meta: {
|
|
@@ -595,10 +595,10 @@ var no_slds_class_overrides_default = {
|
|
|
595
595
|
};
|
|
596
596
|
|
|
597
597
|
// src/rules/v9/no-deprecated-slds-classes.ts
|
|
598
|
-
var
|
|
598
|
+
var import_sds_metadata3 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
599
599
|
var import_rule_messages3 = __toESM(require_rule_messages());
|
|
600
600
|
var { type: type2, description: description2, url: url2, messages: messages2 } = import_rule_messages3.default["no-deprecated-slds-classes"];
|
|
601
|
-
var deprecatedClasses =
|
|
601
|
+
var deprecatedClasses = import_sds_metadata3.default.deprecatedClasses;
|
|
602
602
|
var deprecatedClassesSet = new Set(deprecatedClasses);
|
|
603
603
|
var no_deprecated_slds_classes_default = {
|
|
604
604
|
meta: {
|
|
@@ -629,11 +629,11 @@ var no_deprecated_slds_classes_default = {
|
|
|
629
629
|
};
|
|
630
630
|
|
|
631
631
|
// src/rules/v9/no-deprecated-tokens-slds1.ts
|
|
632
|
-
var
|
|
632
|
+
var import_sds_metadata4 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
633
633
|
var import_rule_messages4 = __toESM(require_rule_messages());
|
|
634
634
|
var ruleConfig2 = import_rule_messages4.default["no-deprecated-tokens-slds1"];
|
|
635
635
|
var { type: type3, description: description3, url: url3, messages: messages3 } = ruleConfig2;
|
|
636
|
-
var tokenMapping =
|
|
636
|
+
var tokenMapping = import_sds_metadata4.default.auraToLwcTokensMapping;
|
|
637
637
|
var no_deprecated_tokens_slds1_default = {
|
|
638
638
|
meta: {
|
|
639
639
|
type: type3,
|
|
@@ -706,995 +706,1067 @@ var no_deprecated_tokens_slds1_default = {
|
|
|
706
706
|
};
|
|
707
707
|
|
|
708
708
|
// src/rules/v9/lwc-token-to-slds-hook.ts
|
|
709
|
-
var
|
|
709
|
+
var import_sds_metadata5 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
710
710
|
var import_rule_messages5 = __toESM(require_rule_messages());
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
var
|
|
714
|
-
|
|
715
|
-
|
|
711
|
+
|
|
712
|
+
// src/utils/hardcoded-shared-utils.ts
|
|
713
|
+
var import_css_tree2 = require("@eslint/css-tree");
|
|
714
|
+
|
|
715
|
+
// src/utils/value-utils.ts
|
|
716
|
+
var ALLOWED_UNITS = ["px", "em", "rem", "%", "ch"];
|
|
717
|
+
function parseUnitValue(value) {
|
|
718
|
+
if (!value) return null;
|
|
719
|
+
const unitsPattern = ALLOWED_UNITS.join("|");
|
|
720
|
+
const regex = new RegExp(`^(-?\\d*\\.?\\d+)(${unitsPattern})?$`);
|
|
721
|
+
const match = value.match(regex);
|
|
722
|
+
if (!match) return null;
|
|
723
|
+
const number = parseFloat(match[1]);
|
|
724
|
+
const unit = match[2] ? match[2] : null;
|
|
725
|
+
if (isNaN(number)) return null;
|
|
726
|
+
return { number, unit };
|
|
716
727
|
}
|
|
717
|
-
function
|
|
718
|
-
if (
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
728
|
+
function toAlternateUnitValue(numberVal, unitType) {
|
|
729
|
+
if (unitType === "px") {
|
|
730
|
+
let floatValue = parseFloat(`${numberVal / 16}`);
|
|
731
|
+
if (!isNaN(floatValue)) {
|
|
732
|
+
return {
|
|
733
|
+
unit: "rem",
|
|
734
|
+
number: parseFloat(floatValue.toFixed(4))
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
} else if (unitType === "rem") {
|
|
738
|
+
const intValue = parseInt(`${numberVal * 16}`);
|
|
739
|
+
if (!isNaN(intValue)) {
|
|
740
|
+
return {
|
|
741
|
+
unit: "px",
|
|
742
|
+
number: intValue
|
|
743
|
+
};
|
|
744
|
+
}
|
|
726
745
|
}
|
|
727
|
-
return
|
|
746
|
+
return null;
|
|
728
747
|
}
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
748
|
+
|
|
749
|
+
// src/utils/color-lib-utils.ts
|
|
750
|
+
var import_chroma_js = __toESM(require("chroma-js"));
|
|
751
|
+
var import_css_tree = require("@eslint/css-tree");
|
|
752
|
+
|
|
753
|
+
// src/utils/css-functions.ts
|
|
754
|
+
var CSS_FUNCTIONS = [
|
|
755
|
+
"attr",
|
|
756
|
+
"calc",
|
|
757
|
+
"color-mix",
|
|
758
|
+
"conic-gradient",
|
|
759
|
+
"counter",
|
|
760
|
+
"cubic-bezier",
|
|
761
|
+
"linear-gradient",
|
|
762
|
+
"max",
|
|
763
|
+
"min",
|
|
764
|
+
"radial-gradient",
|
|
765
|
+
"repeating-conic-gradient",
|
|
766
|
+
"repeating-linear-gradient",
|
|
767
|
+
"repeating-radial-gradient",
|
|
768
|
+
"var"
|
|
769
|
+
];
|
|
770
|
+
var CSS_MATH_FUNCTIONS = ["calc", "min", "max"];
|
|
771
|
+
var RGB_COLOR_FUNCTIONS = ["rgb", "rgba", "hsl", "hsla"];
|
|
772
|
+
var cssFunctionsRegex = new RegExp(`(?:${CSS_FUNCTIONS.join("|")})`);
|
|
773
|
+
var cssFunctionsExactRegex = new RegExp(`^(?:${CSS_FUNCTIONS.join("|")})$`);
|
|
774
|
+
var cssMathFunctionsRegex = new RegExp(`^(?:${CSS_MATH_FUNCTIONS.join("|")})$`);
|
|
775
|
+
function isCssFunction(value) {
|
|
776
|
+
return cssFunctionsExactRegex.test(value);
|
|
735
777
|
}
|
|
736
|
-
function
|
|
737
|
-
|
|
738
|
-
return {
|
|
739
|
-
messageId: "errorWithNoRecommendation",
|
|
740
|
-
data: { oldValue: cssVar }
|
|
741
|
-
};
|
|
742
|
-
} else if (replacementCategory === "array" /* ARRAY */) {
|
|
743
|
-
return {
|
|
744
|
-
messageId: "errorWithStyleHooks",
|
|
745
|
-
data: { oldValue: cssVar, newValue: recommendation.join(" or ") }
|
|
746
|
-
};
|
|
747
|
-
} else if (replacementCategory === "slds_token" /* SLDS_TOKEN */) {
|
|
748
|
-
return {
|
|
749
|
-
messageId: "errorWithStyleHooks",
|
|
750
|
-
data: { oldValue: cssVar, newValue: recommendation }
|
|
751
|
-
};
|
|
752
|
-
} else {
|
|
753
|
-
return {
|
|
754
|
-
messageId: "errorWithReplacement",
|
|
755
|
-
data: { oldValue: cssVar, newValue: recommendation }
|
|
756
|
-
};
|
|
757
|
-
}
|
|
778
|
+
function isCssColorFunction(value) {
|
|
779
|
+
return RGB_COLOR_FUNCTIONS.includes(value);
|
|
758
780
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
const varFunctionCall = `var(${oldValue})`;
|
|
789
|
-
const nodeOffset = node.loc.start.offset;
|
|
790
|
-
const searchStart = Math.max(0, nodeOffset - 4);
|
|
791
|
-
const searchEnd = nodeOffset + oldValue.length + 1;
|
|
792
|
-
const searchArea = fullText.substring(searchStart, searchEnd);
|
|
793
|
-
const functionCallIndex = searchArea.indexOf(varFunctionCall);
|
|
794
|
-
if (functionCallIndex !== -1) {
|
|
795
|
-
const actualStart = searchStart + functionCallIndex;
|
|
796
|
-
const actualEnd = actualStart + varFunctionCall.length;
|
|
797
|
-
return fixer.replaceTextRange([actualStart, actualEnd], suggestedMatch);
|
|
798
|
-
}
|
|
781
|
+
|
|
782
|
+
// src/utils/color-lib-utils.ts
|
|
783
|
+
var LAB_THRESHOLD = 25;
|
|
784
|
+
var isHexCode = (color) => {
|
|
785
|
+
const hexPattern = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
|
|
786
|
+
return hexPattern.test(color);
|
|
787
|
+
};
|
|
788
|
+
var convertToHex = (color) => {
|
|
789
|
+
try {
|
|
790
|
+
return (0, import_chroma_js.default)(color).hex();
|
|
791
|
+
} catch (e) {
|
|
792
|
+
return null;
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
var findClosestColorHook = (color, supportedColors, cssProperty) => {
|
|
796
|
+
const returnStylingHooks = [];
|
|
797
|
+
const closestHooksWithSameProperty = [];
|
|
798
|
+
const closestHooksWithoutSameProperty = [];
|
|
799
|
+
const closestHooksWithAllProperty = [];
|
|
800
|
+
const labColor = (0, import_chroma_js.default)(color).lab();
|
|
801
|
+
Object.entries(supportedColors).forEach(([sldsValue, data]) => {
|
|
802
|
+
if (sldsValue && isHexCode(sldsValue)) {
|
|
803
|
+
const hooks = data;
|
|
804
|
+
hooks.forEach((hook) => {
|
|
805
|
+
const labSupportedColor = (0, import_chroma_js.default)(sldsValue).lab();
|
|
806
|
+
const distance = JSON.stringify(labColor) === JSON.stringify(labSupportedColor) ? 0 : import_chroma_js.default.distance(import_chroma_js.default.lab(...labColor), import_chroma_js.default.lab(...labSupportedColor), "lab");
|
|
807
|
+
if (hook.properties.includes(cssProperty)) {
|
|
808
|
+
if (distance <= LAB_THRESHOLD) {
|
|
809
|
+
closestHooksWithSameProperty.push({ name: hook.name, distance });
|
|
799
810
|
}
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
fix: fixFunction
|
|
808
|
-
});
|
|
809
|
-
}
|
|
810
|
-
return {
|
|
811
|
-
// CSS custom property declarations: --lwc-* properties
|
|
812
|
-
"Declaration[property=/^--lwc-/]"(node) {
|
|
813
|
-
const property = node.property;
|
|
814
|
-
if (shouldIgnoreDetection(property)) {
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(property);
|
|
818
|
-
const { messageId, data } = getReportMessage(property, replacementCategory, recommendation);
|
|
819
|
-
const suggestedMatch = hasRecommendation && replacementCategory === "slds_token" /* SLDS_TOKEN */ ? recommendation : null;
|
|
820
|
-
reportAndFix(node, property, suggestedMatch, messageId, data);
|
|
821
|
-
},
|
|
822
|
-
// LWC tokens inside var() functions: var(--lwc-*)
|
|
823
|
-
"Function[name='var'] Identifier[name=/^--lwc-/]"(node) {
|
|
824
|
-
const tokenName = node.name;
|
|
825
|
-
if (shouldIgnoreDetection(tokenName)) {
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(tokenName);
|
|
829
|
-
const { messageId, data } = getReportMessage(tokenName, replacementCategory, recommendation);
|
|
830
|
-
let suggestedMatch = null;
|
|
831
|
-
if (hasRecommendation) {
|
|
832
|
-
if (replacementCategory === "slds_token" /* SLDS_TOKEN */) {
|
|
833
|
-
const originalVarCall = `var(${tokenName})`;
|
|
834
|
-
suggestedMatch = `var(${recommendation}, ${originalVarCall})`;
|
|
835
|
-
} else if (replacementCategory === "raw_value" /* RAW_VALUE */) {
|
|
836
|
-
suggestedMatch = recommendation;
|
|
811
|
+
} else if (hook.properties.includes("*")) {
|
|
812
|
+
if (distance <= LAB_THRESHOLD) {
|
|
813
|
+
closestHooksWithAllProperty.push({ name: hook.name, distance });
|
|
814
|
+
}
|
|
815
|
+
} else {
|
|
816
|
+
if (distance <= LAB_THRESHOLD) {
|
|
817
|
+
closestHooksWithoutSameProperty.push({ name: hook.name, distance });
|
|
837
818
|
}
|
|
838
819
|
}
|
|
839
|
-
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
const closesthookGroups = [
|
|
824
|
+
{ hooks: closestHooksWithSameProperty, distance: 0 },
|
|
825
|
+
{ hooks: closestHooksWithAllProperty, distance: 0 },
|
|
826
|
+
{ hooks: closestHooksWithSameProperty, distance: Infinity },
|
|
827
|
+
// For hooks with distance > 0
|
|
828
|
+
{ hooks: closestHooksWithAllProperty, distance: Infinity },
|
|
829
|
+
{ hooks: closestHooksWithoutSameProperty, distance: Infinity }
|
|
830
|
+
];
|
|
831
|
+
for (const group of closesthookGroups) {
|
|
832
|
+
const filteredHooks = group.hooks.filter(
|
|
833
|
+
(h) => group.distance === 0 ? h.distance === 0 : h.distance > 0
|
|
834
|
+
);
|
|
835
|
+
if (returnStylingHooks.length < 1 && filteredHooks.length > 0) {
|
|
836
|
+
filteredHooks.sort((a, b) => a.distance - b.distance);
|
|
837
|
+
returnStylingHooks.push(...filteredHooks.slice(0, 5).map((h) => h.name));
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return Array.from(new Set(returnStylingHooks));
|
|
841
|
+
};
|
|
842
|
+
var isValidColor = (val) => import_chroma_js.default.valid(val);
|
|
843
|
+
var extractColorValue = (node) => {
|
|
844
|
+
let colorValue = null;
|
|
845
|
+
switch (node.type) {
|
|
846
|
+
case "Hash":
|
|
847
|
+
colorValue = `#${node.value}`;
|
|
848
|
+
break;
|
|
849
|
+
case "Identifier":
|
|
850
|
+
colorValue = node.name;
|
|
851
|
+
break;
|
|
852
|
+
case "Function":
|
|
853
|
+
if (isCssColorFunction(node.name)) {
|
|
854
|
+
colorValue = (0, import_css_tree.generate)(node);
|
|
840
855
|
}
|
|
841
|
-
|
|
856
|
+
break;
|
|
842
857
|
}
|
|
858
|
+
return colorValue && isValidColor(colorValue) ? colorValue : null;
|
|
843
859
|
};
|
|
844
860
|
|
|
845
|
-
// src/
|
|
846
|
-
var
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
861
|
+
// src/utils/hardcoded-shared-utils.ts
|
|
862
|
+
var FONT_WEIGHTS = [
|
|
863
|
+
"normal",
|
|
864
|
+
"bold",
|
|
865
|
+
"bolder",
|
|
866
|
+
"lighter",
|
|
867
|
+
"100",
|
|
868
|
+
"200",
|
|
869
|
+
"300",
|
|
870
|
+
"400",
|
|
871
|
+
"500",
|
|
872
|
+
"600",
|
|
873
|
+
"700",
|
|
874
|
+
"800",
|
|
875
|
+
"900"
|
|
876
|
+
];
|
|
877
|
+
function isKnownFontWeight(value) {
|
|
878
|
+
const stringValue = value.toString();
|
|
879
|
+
return FONT_WEIGHTS.includes(stringValue.toLowerCase());
|
|
855
880
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
const fullText = sourceCode.getText();
|
|
877
|
-
const nodeOffset = node.loc.start.offset;
|
|
878
|
-
const propertyStart = nodeOffset;
|
|
879
|
-
const propertyEnd = propertyStart + oldValue.length;
|
|
880
|
-
const textAtPosition = fullText.substring(propertyStart, propertyEnd);
|
|
881
|
-
if (textAtPosition === oldValue) {
|
|
882
|
-
return fixer.replaceTextRange([propertyStart, propertyEnd], suggestedMatch);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
return fixer.replaceText(node, suggestedMatch);
|
|
886
|
-
}
|
|
887
|
-
});
|
|
888
|
-
}
|
|
889
|
-
return {
|
|
890
|
-
// CSS custom property declarations: --sds-* properties
|
|
891
|
-
"Declaration[property=/^--sds-/]"(node) {
|
|
892
|
-
const property = node.property;
|
|
893
|
-
if (shouldIgnoreDetection2(property)) {
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
const suggestedMatch = toSldsToken(property);
|
|
897
|
-
reportAndFix(node, property, suggestedMatch);
|
|
898
|
-
},
|
|
899
|
-
// SDS tokens inside var() functions: var(--sds-*)
|
|
900
|
-
"Function[name='var'] Identifier[name=/^--sds-/]"(node) {
|
|
901
|
-
const tokenName = node.name;
|
|
902
|
-
if (shouldIgnoreDetection2(tokenName)) {
|
|
903
|
-
return;
|
|
881
|
+
function handleShorthandAutoFix(declarationNode, context, valueText, replacements) {
|
|
882
|
+
const sortedReplacements = replacements.sort((a, b) => a.start - b.start);
|
|
883
|
+
const hasAnyHooks = sortedReplacements.some((r) => r.hasHook);
|
|
884
|
+
const canAutoFix = hasAnyHooks;
|
|
885
|
+
sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook }) => {
|
|
886
|
+
const originalValue = valueText.substring(start, end);
|
|
887
|
+
const valueStartColumn = declarationNode.value.loc.start.column;
|
|
888
|
+
const valueColumn = valueStartColumn + start;
|
|
889
|
+
const { loc: { start: locStart, end: locEnd } } = declarationNode.value;
|
|
890
|
+
const reportNode = {
|
|
891
|
+
...declarationNode.value,
|
|
892
|
+
loc: {
|
|
893
|
+
...declarationNode.value.loc,
|
|
894
|
+
start: {
|
|
895
|
+
...locStart,
|
|
896
|
+
column: valueColumn
|
|
897
|
+
},
|
|
898
|
+
end: {
|
|
899
|
+
...locEnd,
|
|
900
|
+
column: valueColumn + originalValue.length
|
|
904
901
|
}
|
|
905
|
-
const suggestedMatch = toSldsToken(tokenName);
|
|
906
|
-
reportAndFix(node, tokenName, suggestedMatch);
|
|
907
902
|
}
|
|
908
903
|
};
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
var ruleConfig5 = import_rule_messages7.default["no-sldshook-fallback-for-lwctoken"];
|
|
916
|
-
var { type: type6, description: description6, url: url6, messages: messages6 } = ruleConfig5;
|
|
917
|
-
var sldsPlusStylingHooks2 = import_next7.default.sldsPlusStylingHooks;
|
|
918
|
-
var allSldsHooks2 = [...sldsPlusStylingHooks2.global, ...sldsPlusStylingHooks2.component];
|
|
919
|
-
var allSldsHooksSet = new Set(allSldsHooks2);
|
|
920
|
-
function hasUnsupportedFallback(lwcToken, sldsToken) {
|
|
921
|
-
const normalizedSldsToken = sldsToken.replace("--sds-", "--slds-");
|
|
922
|
-
return lwcToken.startsWith("--lwc-") && normalizedSldsToken.startsWith("--slds-") && allSldsHooksSet.has(normalizedSldsToken);
|
|
923
|
-
}
|
|
924
|
-
var no_sldshook_fallback_for_lwctoken_default = {
|
|
925
|
-
meta: {
|
|
926
|
-
type: type6,
|
|
927
|
-
docs: {
|
|
928
|
-
description: description6,
|
|
929
|
-
recommended: true,
|
|
930
|
-
url: url6
|
|
931
|
-
},
|
|
932
|
-
messages: messages6
|
|
933
|
-
},
|
|
934
|
-
create(context) {
|
|
935
|
-
return {
|
|
936
|
-
// Handle LWC tokens inside var() functions: var(--lwc-*, ...)
|
|
937
|
-
"Function[name='var'] Identifier[name=/^--lwc-/]"(node) {
|
|
938
|
-
const lwcToken = node.name;
|
|
939
|
-
const varFunctionNode = context.sourceCode.getAncestors(node).at(-1);
|
|
940
|
-
if (!varFunctionNode) return;
|
|
941
|
-
const varFunctionChildren = varFunctionNode.children;
|
|
942
|
-
if (!varFunctionChildren) return;
|
|
943
|
-
let foundComma = false;
|
|
944
|
-
let fallbackRawNode = null;
|
|
945
|
-
for (const child of varFunctionChildren) {
|
|
946
|
-
if (child.type === "Operator" && child.value === ",") {
|
|
947
|
-
foundComma = true;
|
|
948
|
-
continue;
|
|
949
|
-
}
|
|
950
|
-
if (foundComma && child.type === "Raw") {
|
|
951
|
-
fallbackRawNode = child;
|
|
952
|
-
break;
|
|
953
|
-
}
|
|
904
|
+
if (hasHook) {
|
|
905
|
+
const fix = canAutoFix ? (fixer) => {
|
|
906
|
+
let newValue = valueText;
|
|
907
|
+
for (let i = sortedReplacements.length - 1; i >= 0; i--) {
|
|
908
|
+
const { start: rStart, end: rEnd, replacement: rReplacement } = sortedReplacements[i];
|
|
909
|
+
newValue = newValue.substring(0, rStart) + rReplacement + newValue.substring(rEnd);
|
|
954
910
|
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
911
|
+
return fixer.replaceText(declarationNode.value, newValue);
|
|
912
|
+
} : void 0;
|
|
913
|
+
context.context.report({
|
|
914
|
+
node: reportNode,
|
|
915
|
+
messageId: "hardcodedValue",
|
|
916
|
+
data: {
|
|
917
|
+
oldValue: originalValue,
|
|
918
|
+
newValue: displayValue
|
|
919
|
+
},
|
|
920
|
+
fix
|
|
921
|
+
});
|
|
922
|
+
} else {
|
|
923
|
+
context.context.report({
|
|
924
|
+
node: reportNode,
|
|
925
|
+
messageId: "noReplacement",
|
|
926
|
+
data: {
|
|
927
|
+
oldValue: originalValue
|
|
966
928
|
}
|
|
967
|
-
}
|
|
968
|
-
};
|
|
969
|
-
}
|
|
970
|
-
};
|
|
971
|
-
|
|
972
|
-
// src/rules/v9/no-unsupported-hooks-slds2.ts
|
|
973
|
-
var import_next8 = __toESM(require("@salesforce-ux/sds-metadata/next"));
|
|
974
|
-
var import_rule_messages8 = __toESM(require_rule_messages());
|
|
975
|
-
var ruleConfig6 = import_rule_messages8.default["no-unsupported-hooks-slds2"];
|
|
976
|
-
var { type: type7, description: description7, url: url7, messages: messages7 } = ruleConfig6;
|
|
977
|
-
var deprecatedHooks = new Set(import_next8.default.deprecatedStylingHooks);
|
|
978
|
-
function shouldIgnoreDetection3(sldsHook) {
|
|
979
|
-
return !deprecatedHooks.has(sldsHook);
|
|
980
|
-
}
|
|
981
|
-
var no_unsupported_hooks_slds2_default = {
|
|
982
|
-
meta: {
|
|
983
|
-
type: type7,
|
|
984
|
-
docs: {
|
|
985
|
-
description: description7,
|
|
986
|
-
recommended: true,
|
|
987
|
-
url: url7
|
|
988
|
-
},
|
|
989
|
-
messages: messages7
|
|
990
|
-
},
|
|
991
|
-
create(context) {
|
|
992
|
-
function reportDeprecatedHook(node, token) {
|
|
993
|
-
context.report({
|
|
994
|
-
node,
|
|
995
|
-
messageId: "deprecated",
|
|
996
|
-
data: { token }
|
|
997
929
|
});
|
|
998
930
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
function forEachValue(valueText, extractValue, shouldSkipNode, callback) {
|
|
934
|
+
if (!valueText || typeof valueText !== "string") {
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
try {
|
|
938
|
+
const ast = (0, import_css_tree2.parse)(valueText, { context: "value", positions: true });
|
|
939
|
+
(0, import_css_tree2.walk)(ast, {
|
|
940
|
+
enter(node) {
|
|
941
|
+
if (shouldSkipNode(node)) {
|
|
942
|
+
return this.skip;
|
|
1006
943
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
return;
|
|
944
|
+
const value = extractValue(node);
|
|
945
|
+
if (value !== null) {
|
|
946
|
+
const positionInfo = {
|
|
947
|
+
start: node.loc?.start,
|
|
948
|
+
end: node.loc?.end
|
|
949
|
+
};
|
|
950
|
+
callback(value, positionInfo);
|
|
1015
951
|
}
|
|
1016
|
-
reportDeprecatedHook(node, tokenName);
|
|
1017
952
|
}
|
|
1018
|
-
};
|
|
953
|
+
});
|
|
954
|
+
} catch (error) {
|
|
955
|
+
return;
|
|
1019
956
|
}
|
|
1020
|
-
};
|
|
1021
|
-
|
|
1022
|
-
// src/rules/v9/no-slds-var-without-fallback.ts
|
|
1023
|
-
var import_next9 = __toESM(require("@salesforce-ux/sds-metadata/next"));
|
|
1024
|
-
var import_rule_messages9 = __toESM(require_rule_messages());
|
|
1025
|
-
var ruleConfig7 = import_rule_messages9.default["no-slds-var-without-fallback"];
|
|
1026
|
-
var { type: type8, description: description8, url: url8, messages: messages8 } = ruleConfig7;
|
|
1027
|
-
var sldsVariables = import_next9.default.slds1ExcludedVars || {};
|
|
1028
|
-
function isSldsCssVariable(cssVar) {
|
|
1029
|
-
return cssVar.startsWith("--slds-");
|
|
1030
957
|
}
|
|
1031
|
-
function
|
|
1032
|
-
|
|
1033
|
-
return varFunctionNode.children.some(
|
|
1034
|
-
(child) => child.type === "Operator" && child.value === ","
|
|
1035
|
-
);
|
|
958
|
+
function shouldSkipColorNode(node) {
|
|
959
|
+
return node.type === "Function" && isCssFunction(node.name);
|
|
1036
960
|
}
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
961
|
+
function shouldSkipDimensionNode(node) {
|
|
962
|
+
return node.type === "Function";
|
|
963
|
+
}
|
|
964
|
+
function extractDimensionValue(valueNode, cssProperty) {
|
|
965
|
+
if (!valueNode) return null;
|
|
966
|
+
switch (valueNode.type) {
|
|
967
|
+
case "Dimension":
|
|
968
|
+
const numValue = Number(valueNode.value);
|
|
969
|
+
if (numValue === 0) return null;
|
|
970
|
+
const unit = valueNode.unit.toLowerCase();
|
|
971
|
+
if (!ALLOWED_UNITS.includes(unit)) return null;
|
|
972
|
+
return {
|
|
973
|
+
number: numValue,
|
|
974
|
+
unit
|
|
975
|
+
};
|
|
976
|
+
case "Number":
|
|
977
|
+
const numberValue = Number(valueNode.value);
|
|
978
|
+
if (numberValue === 0) return null;
|
|
979
|
+
return {
|
|
980
|
+
number: numberValue,
|
|
981
|
+
unit: null
|
|
982
|
+
};
|
|
983
|
+
case "Percentage":
|
|
984
|
+
const percentValue = Number(valueNode.value);
|
|
985
|
+
if (percentValue === 0) return null;
|
|
986
|
+
return {
|
|
987
|
+
number: percentValue,
|
|
988
|
+
unit: "%"
|
|
989
|
+
};
|
|
990
|
+
case "Value":
|
|
991
|
+
return valueNode.children?.[0] ? extractDimensionValue(valueNode.children[0], cssProperty) : null;
|
|
992
|
+
}
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
function forEachColorValue(valueText, callback) {
|
|
996
|
+
forEachValue(valueText, extractColorValue, shouldSkipColorNode, callback);
|
|
997
|
+
}
|
|
998
|
+
function forEachDensityValue(valueText, cssProperty, callback) {
|
|
999
|
+
forEachValue(
|
|
1000
|
+
valueText,
|
|
1001
|
+
(node) => extractDimensionValue(node, cssProperty),
|
|
1002
|
+
shouldSkipDimensionNode,
|
|
1003
|
+
callback
|
|
1004
|
+
);
|
|
1005
|
+
}
|
|
1006
|
+
function extractFontValue(node) {
|
|
1007
|
+
if (!node) return null;
|
|
1008
|
+
switch (node.type) {
|
|
1009
|
+
case "Dimension":
|
|
1010
|
+
const numValue = Number(node.value);
|
|
1011
|
+
if (numValue <= 0) return null;
|
|
1012
|
+
const unit = node.unit.toLowerCase();
|
|
1013
|
+
if (!ALLOWED_UNITS.includes(unit)) return null;
|
|
1014
|
+
return {
|
|
1015
|
+
number: numValue,
|
|
1016
|
+
unit
|
|
1017
|
+
};
|
|
1018
|
+
case "Number":
|
|
1019
|
+
const numberValue = Number(node.value);
|
|
1020
|
+
if (numberValue <= 0) {
|
|
1021
|
+
return null;
|
|
1077
1022
|
}
|
|
1078
|
-
|
|
1023
|
+
if (!isKnownFontWeight(numberValue)) {
|
|
1024
|
+
return null;
|
|
1025
|
+
}
|
|
1026
|
+
return {
|
|
1027
|
+
number: numberValue,
|
|
1028
|
+
unit: null
|
|
1029
|
+
};
|
|
1030
|
+
case "Identifier":
|
|
1031
|
+
const namedValue = node.name.toLowerCase();
|
|
1032
|
+
if (!isKnownFontWeight(namedValue)) {
|
|
1033
|
+
return null;
|
|
1034
|
+
}
|
|
1035
|
+
if (namedValue === "normal") {
|
|
1036
|
+
return { number: 400, unit: null };
|
|
1037
|
+
}
|
|
1038
|
+
return { number: namedValue, unit: null };
|
|
1039
|
+
case "Percentage":
|
|
1040
|
+
const percentValue = Number(node.value);
|
|
1041
|
+
if (percentValue === 0) return null;
|
|
1042
|
+
return {
|
|
1043
|
+
number: percentValue,
|
|
1044
|
+
unit: "%"
|
|
1045
|
+
};
|
|
1046
|
+
case "Value":
|
|
1047
|
+
return node.children?.[0] ? extractFontValue(node.children[0]) : null;
|
|
1079
1048
|
}
|
|
1080
|
-
|
|
1049
|
+
return null;
|
|
1050
|
+
}
|
|
1051
|
+
function shouldSkipFontNode(node) {
|
|
1052
|
+
return node.type === "Function";
|
|
1053
|
+
}
|
|
1054
|
+
function forEachFontValue(valueText, callback) {
|
|
1055
|
+
forEachValue(valueText, extractFontValue, shouldSkipFontNode, callback);
|
|
1056
|
+
}
|
|
1081
1057
|
|
|
1082
|
-
// src/
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
var { type: type9, description: description9, url: url9, messages: messages9 } = ruleConfig8;
|
|
1087
|
-
var sldsPlusStylingHooks3 = import_next10.default.sldsPlusStylingHooks;
|
|
1088
|
-
var allSldsHooks3 = [...sldsPlusStylingHooks3.global, ...sldsPlusStylingHooks3.component];
|
|
1089
|
-
var toSldsToken2 = (sdsToken) => sdsToken.replace("--sds-", "--slds-");
|
|
1090
|
-
function shouldIgnoreDetection4(sdsToken) {
|
|
1091
|
-
if (sdsToken.startsWith("--sds-") || sdsToken.startsWith("--slds-")) {
|
|
1092
|
-
return allSldsHooks3.includes(toSldsToken2(sdsToken));
|
|
1058
|
+
// src/utils/css-utils.ts
|
|
1059
|
+
function extractSldsVariable(node) {
|
|
1060
|
+
if (!node || node.type !== "Function" || node.name !== "var") {
|
|
1061
|
+
return null;
|
|
1093
1062
|
}
|
|
1094
|
-
|
|
1063
|
+
if (!node.children) {
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
const childrenArray = Array.from(node.children);
|
|
1067
|
+
if (childrenArray.length === 0) {
|
|
1068
|
+
return null;
|
|
1069
|
+
}
|
|
1070
|
+
const firstChild = childrenArray[0];
|
|
1071
|
+
if (!firstChild || firstChild.type !== "Identifier") {
|
|
1072
|
+
return null;
|
|
1073
|
+
}
|
|
1074
|
+
const variableName = firstChild.name;
|
|
1075
|
+
if (!variableName || !variableName.startsWith("--slds-")) {
|
|
1076
|
+
return null;
|
|
1077
|
+
}
|
|
1078
|
+
const hasFallback = childrenArray.some(
|
|
1079
|
+
(child) => child.type === "Operator" && child.value === ","
|
|
1080
|
+
);
|
|
1081
|
+
return {
|
|
1082
|
+
name: variableName,
|
|
1083
|
+
hasFallback
|
|
1084
|
+
};
|
|
1095
1085
|
}
|
|
1096
|
-
|
|
1086
|
+
function forEachSldsVariable(valueText, callback) {
|
|
1087
|
+
forEachValue(valueText, extractSldsVariable, () => false, callback);
|
|
1088
|
+
}
|
|
1089
|
+
function formatSuggestionHooks(hooks) {
|
|
1090
|
+
if (hooks.length === 1) {
|
|
1091
|
+
return `${hooks[0]}`;
|
|
1092
|
+
}
|
|
1093
|
+
return "\n" + hooks.map((hook, index) => `${index + 1}. ${hook}`).join("\n");
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
// src/rules/v9/lwc-token-to-slds-hook.ts
|
|
1097
|
+
var ruleConfig3 = import_rule_messages5.default["lwc-token-to-slds-hook"];
|
|
1098
|
+
var { type: type4, description: description4, url: url4, messages: messages4 } = ruleConfig3;
|
|
1099
|
+
var lwcToSlds = import_sds_metadata5.default.lwcToSlds;
|
|
1100
|
+
function shouldIgnoreDetection(lwcToken) {
|
|
1101
|
+
return !lwcToken.startsWith("--lwc-") || !(lwcToken in lwcToSlds) || lwcToSlds[lwcToken].continueToUse;
|
|
1102
|
+
}
|
|
1103
|
+
function categorizeReplacement(recommendation) {
|
|
1104
|
+
if (!recommendation || recommendation === "--") {
|
|
1105
|
+
return "empty" /* EMPTY */;
|
|
1106
|
+
}
|
|
1107
|
+
if (Array.isArray(recommendation)) {
|
|
1108
|
+
return "array" /* ARRAY */;
|
|
1109
|
+
}
|
|
1110
|
+
if (typeof recommendation === "string" && recommendation.startsWith("--slds-")) {
|
|
1111
|
+
return "slds_token" /* SLDS_TOKEN */;
|
|
1112
|
+
}
|
|
1113
|
+
return "raw_value" /* RAW_VALUE */;
|
|
1114
|
+
}
|
|
1115
|
+
function getRecommendation(lwcToken) {
|
|
1116
|
+
const oldValue = lwcToken;
|
|
1117
|
+
const recommendation = lwcToSlds[oldValue]?.replacement || "";
|
|
1118
|
+
const replacementCategory = categorizeReplacement(recommendation);
|
|
1119
|
+
const hasRecommendation = oldValue in lwcToSlds && replacementCategory !== "empty" /* EMPTY */;
|
|
1120
|
+
return { hasRecommendation, recommendation, replacementCategory };
|
|
1121
|
+
}
|
|
1122
|
+
function getReportMessage(cssVar, replacementCategory, recommendation) {
|
|
1123
|
+
if (!recommendation) {
|
|
1124
|
+
return {
|
|
1125
|
+
messageId: "errorWithNoRecommendation",
|
|
1126
|
+
data: { oldValue: cssVar }
|
|
1127
|
+
};
|
|
1128
|
+
} else if (replacementCategory === "array" /* ARRAY */) {
|
|
1129
|
+
return {
|
|
1130
|
+
messageId: "errorWithStyleHooks",
|
|
1131
|
+
data: { oldValue: cssVar, newValue: formatSuggestionHooks(recommendation) }
|
|
1132
|
+
};
|
|
1133
|
+
} else if (replacementCategory === "slds_token" /* SLDS_TOKEN */) {
|
|
1134
|
+
return {
|
|
1135
|
+
messageId: "errorWithStyleHooks",
|
|
1136
|
+
data: { oldValue: cssVar, newValue: recommendation }
|
|
1137
|
+
};
|
|
1138
|
+
} else {
|
|
1139
|
+
return {
|
|
1140
|
+
messageId: "errorWithReplacement",
|
|
1141
|
+
data: { oldValue: cssVar, newValue: recommendation }
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
var lwc_token_to_slds_hook_default = {
|
|
1097
1146
|
meta: {
|
|
1098
|
-
type:
|
|
1147
|
+
type: type4,
|
|
1099
1148
|
docs: {
|
|
1100
|
-
description:
|
|
1149
|
+
description: description4,
|
|
1101
1150
|
recommended: true,
|
|
1102
|
-
url:
|
|
1151
|
+
url: url4
|
|
1103
1152
|
},
|
|
1104
|
-
|
|
1153
|
+
fixable: "code",
|
|
1154
|
+
messages: messages4
|
|
1105
1155
|
},
|
|
1106
1156
|
create(context) {
|
|
1107
|
-
function
|
|
1108
|
-
|
|
1157
|
+
function reportAndFix(node, oldValue, suggestedMatch, messageId, data) {
|
|
1158
|
+
let fixFunction = null;
|
|
1159
|
+
if (suggestedMatch) {
|
|
1160
|
+
fixFunction = (fixer) => {
|
|
1161
|
+
if (node.type === "Declaration") {
|
|
1162
|
+
const sourceCode = context.sourceCode;
|
|
1163
|
+
const fullText = sourceCode.getText();
|
|
1164
|
+
const nodeOffset = node.loc.start.offset;
|
|
1165
|
+
const propertyStart = nodeOffset;
|
|
1166
|
+
const propertyEnd = propertyStart + oldValue.length;
|
|
1167
|
+
const textAtPosition = fullText.substring(propertyStart, propertyEnd);
|
|
1168
|
+
if (textAtPosition === oldValue) {
|
|
1169
|
+
return fixer.replaceTextRange([propertyStart, propertyEnd], suggestedMatch);
|
|
1170
|
+
}
|
|
1171
|
+
} else {
|
|
1172
|
+
const sourceCode = context.sourceCode;
|
|
1173
|
+
const fullText = sourceCode.getText();
|
|
1174
|
+
const varFunctionCall = `var(${oldValue})`;
|
|
1175
|
+
const nodeOffset = node.loc.start.offset;
|
|
1176
|
+
const searchStart = Math.max(0, nodeOffset - 4);
|
|
1177
|
+
const searchEnd = nodeOffset + oldValue.length + 1;
|
|
1178
|
+
const searchArea = fullText.substring(searchStart, searchEnd);
|
|
1179
|
+
const functionCallIndex = searchArea.indexOf(varFunctionCall);
|
|
1180
|
+
if (functionCallIndex !== -1) {
|
|
1181
|
+
const actualStart = searchStart + functionCallIndex;
|
|
1182
|
+
const actualEnd = actualStart + varFunctionCall.length;
|
|
1183
|
+
return fixer.replaceTextRange([actualStart, actualEnd], suggestedMatch);
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1186
|
+
return null;
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1109
1189
|
context.report({
|
|
1110
1190
|
node,
|
|
1111
|
-
messageId
|
|
1112
|
-
data
|
|
1113
|
-
|
|
1114
|
-
tokenWithoutNamespace
|
|
1115
|
-
}
|
|
1191
|
+
messageId,
|
|
1192
|
+
data,
|
|
1193
|
+
fix: fixFunction
|
|
1116
1194
|
});
|
|
1117
1195
|
}
|
|
1118
1196
|
return {
|
|
1119
|
-
// CSS custom property declarations: --
|
|
1120
|
-
"Declaration[property=/^--
|
|
1197
|
+
// CSS custom property declarations: --lwc-* properties
|
|
1198
|
+
"Declaration[property=/^--lwc-/]"(node) {
|
|
1121
1199
|
const property = node.property;
|
|
1122
|
-
if (
|
|
1200
|
+
if (shouldIgnoreDetection(property)) {
|
|
1123
1201
|
return;
|
|
1124
1202
|
}
|
|
1125
|
-
|
|
1203
|
+
const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(property);
|
|
1204
|
+
const { messageId, data } = getReportMessage(property, replacementCategory, recommendation);
|
|
1205
|
+
const suggestedMatch = hasRecommendation && replacementCategory === "slds_token" /* SLDS_TOKEN */ ? recommendation : null;
|
|
1206
|
+
reportAndFix(node, property, suggestedMatch, messageId, data);
|
|
1126
1207
|
},
|
|
1127
|
-
//
|
|
1128
|
-
"Function[name='var'] Identifier[name=/^--
|
|
1208
|
+
// LWC tokens inside var() functions: var(--lwc-*)
|
|
1209
|
+
"Function[name='var'] Identifier[name=/^--lwc-/]"(node) {
|
|
1129
1210
|
const tokenName = node.name;
|
|
1130
|
-
if (
|
|
1211
|
+
if (shouldIgnoreDetection(tokenName)) {
|
|
1131
1212
|
return;
|
|
1132
1213
|
}
|
|
1133
|
-
|
|
1214
|
+
const { hasRecommendation, recommendation, replacementCategory } = getRecommendation(tokenName);
|
|
1215
|
+
const { messageId, data } = getReportMessage(tokenName, replacementCategory, recommendation);
|
|
1216
|
+
let suggestedMatch = null;
|
|
1217
|
+
if (hasRecommendation) {
|
|
1218
|
+
if (replacementCategory === "slds_token" /* SLDS_TOKEN */) {
|
|
1219
|
+
const originalVarCall = `var(${tokenName})`;
|
|
1220
|
+
suggestedMatch = `var(${recommendation}, ${originalVarCall})`;
|
|
1221
|
+
} else if (replacementCategory === "raw_value" /* RAW_VALUE */) {
|
|
1222
|
+
suggestedMatch = recommendation;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
reportAndFix(node, tokenName, suggestedMatch, messageId, data);
|
|
1134
1226
|
}
|
|
1135
1227
|
};
|
|
1136
1228
|
}
|
|
1137
1229
|
};
|
|
1138
1230
|
|
|
1139
|
-
// src/rules/v9/enforce-
|
|
1140
|
-
var
|
|
1141
|
-
var
|
|
1142
|
-
var
|
|
1143
|
-
var { type:
|
|
1144
|
-
var
|
|
1145
|
-
|
|
1146
|
-
|
|
1231
|
+
// src/rules/v9/enforce-sds-to-slds-hooks.ts
|
|
1232
|
+
var import_sds_metadata6 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
1233
|
+
var import_rule_messages6 = __toESM(require_rule_messages());
|
|
1234
|
+
var ruleConfig4 = import_rule_messages6.default["enforce-sds-to-slds-hooks"];
|
|
1235
|
+
var { type: type5, description: description5, url: url5, messages: messages5 } = ruleConfig4;
|
|
1236
|
+
var sldsPlusStylingHooks = import_sds_metadata6.default.sldsPlusStylingHooks;
|
|
1237
|
+
var allSldsHooks = [...sldsPlusStylingHooks.global, ...sldsPlusStylingHooks.component];
|
|
1238
|
+
var toSldsToken = (sdsToken) => sdsToken.replace("--sds-", "--slds-");
|
|
1239
|
+
function shouldIgnoreDetection2(sdsToken) {
|
|
1240
|
+
return !sdsToken.startsWith("--sds-") || !allSldsHooks.includes(toSldsToken(sdsToken));
|
|
1147
1241
|
}
|
|
1148
|
-
var
|
|
1242
|
+
var enforce_sds_to_slds_hooks_default = {
|
|
1149
1243
|
meta: {
|
|
1150
|
-
type:
|
|
1244
|
+
type: type5,
|
|
1151
1245
|
docs: {
|
|
1152
|
-
description:
|
|
1246
|
+
description: description5,
|
|
1153
1247
|
recommended: true,
|
|
1154
|
-
url:
|
|
1248
|
+
url: url5
|
|
1155
1249
|
},
|
|
1156
1250
|
fixable: "code",
|
|
1157
|
-
messages:
|
|
1251
|
+
messages: messages5
|
|
1158
1252
|
},
|
|
1159
1253
|
create(context) {
|
|
1254
|
+
function reportAndFix(node, oldValue, suggestedMatch) {
|
|
1255
|
+
context.report({
|
|
1256
|
+
node,
|
|
1257
|
+
messageId: "replaceSdsWithSlds",
|
|
1258
|
+
data: { oldValue, suggestedMatch },
|
|
1259
|
+
fix(fixer) {
|
|
1260
|
+
if (node.type === "Declaration") {
|
|
1261
|
+
const sourceCode = context.sourceCode;
|
|
1262
|
+
const fullText = sourceCode.getText();
|
|
1263
|
+
const nodeOffset = node.loc.start.offset;
|
|
1264
|
+
const propertyStart = nodeOffset;
|
|
1265
|
+
const propertyEnd = propertyStart + oldValue.length;
|
|
1266
|
+
const textAtPosition = fullText.substring(propertyStart, propertyEnd);
|
|
1267
|
+
if (textAtPosition === oldValue) {
|
|
1268
|
+
return fixer.replaceTextRange([propertyStart, propertyEnd], suggestedMatch);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
return fixer.replaceText(node, suggestedMatch);
|
|
1272
|
+
}
|
|
1273
|
+
});
|
|
1274
|
+
}
|
|
1160
1275
|
return {
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
* --slds-c-accordion-section-color-background: var(--slds-c-accordion-section-color-border);
|
|
1166
|
-
* }
|
|
1167
|
-
* var in value is not detected, because eslint treats above statement as custom property assignment
|
|
1168
|
-
* and value treated as raw string, not parsed into function nodes
|
|
1169
|
-
*/
|
|
1170
|
-
"Declaration[property=/^--slds-c-/], Function[name='var'] Identifier[name=/^--slds-c-/]"(node) {
|
|
1171
|
-
let hookName;
|
|
1172
|
-
let reportNode = node;
|
|
1173
|
-
if (node.type === "Declaration") {
|
|
1174
|
-
hookName = node.property;
|
|
1175
|
-
} else if (node.type === "Identifier") {
|
|
1176
|
-
hookName = node.name;
|
|
1177
|
-
} else {
|
|
1276
|
+
// CSS custom property declarations: --sds-* properties
|
|
1277
|
+
"Declaration[property=/^--sds-/]"(node) {
|
|
1278
|
+
const property = node.property;
|
|
1279
|
+
if (shouldIgnoreDetection2(property)) {
|
|
1178
1280
|
return;
|
|
1179
1281
|
}
|
|
1180
|
-
|
|
1282
|
+
const suggestedMatch = toSldsToken(property);
|
|
1283
|
+
reportAndFix(node, property, suggestedMatch);
|
|
1284
|
+
},
|
|
1285
|
+
// SDS tokens inside var() functions: var(--sds-*)
|
|
1286
|
+
"Function[name='var'] Identifier[name=/^--sds-/]"(node) {
|
|
1287
|
+
const tokenName = node.name;
|
|
1288
|
+
if (shouldIgnoreDetection2(tokenName)) {
|
|
1181
1289
|
return;
|
|
1182
1290
|
}
|
|
1183
|
-
const suggestedMatch =
|
|
1184
|
-
|
|
1185
|
-
node: reportNode,
|
|
1186
|
-
messageId: "replace",
|
|
1187
|
-
data: {
|
|
1188
|
-
oldValue: hookName,
|
|
1189
|
-
suggestedMatch
|
|
1190
|
-
},
|
|
1191
|
-
fix(fixer) {
|
|
1192
|
-
if (node.type === "Declaration") {
|
|
1193
|
-
const originalText = context.sourceCode.getText(node);
|
|
1194
|
-
const colonIndex = originalText.indexOf(":");
|
|
1195
|
-
const valuePartWithColon = originalText.substring(colonIndex);
|
|
1196
|
-
return fixer.replaceText(node, `${suggestedMatch}${valuePartWithColon}`);
|
|
1197
|
-
} else if (node.type === "Identifier") {
|
|
1198
|
-
return fixer.replaceText(node, suggestedMatch);
|
|
1199
|
-
}
|
|
1200
|
-
return null;
|
|
1201
|
-
}
|
|
1202
|
-
});
|
|
1291
|
+
const suggestedMatch = toSldsToken(tokenName);
|
|
1292
|
+
reportAndFix(node, tokenName, suggestedMatch);
|
|
1203
1293
|
}
|
|
1204
1294
|
};
|
|
1205
1295
|
}
|
|
1206
1296
|
};
|
|
1207
1297
|
|
|
1208
|
-
// src/rules/v9/
|
|
1209
|
-
var
|
|
1210
|
-
var
|
|
1211
|
-
var
|
|
1212
|
-
var
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1298
|
+
// src/rules/v9/no-sldshook-fallback-for-lwctoken.ts
|
|
1299
|
+
var import_sds_metadata7 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
1300
|
+
var import_rule_messages7 = __toESM(require_rule_messages());
|
|
1301
|
+
var ruleConfig5 = import_rule_messages7.default["no-sldshook-fallback-for-lwctoken"];
|
|
1302
|
+
var { type: type6, description: description6, url: url6, messages: messages6 } = ruleConfig5;
|
|
1303
|
+
var sldsPlusStylingHooks2 = import_sds_metadata7.default.sldsPlusStylingHooks;
|
|
1304
|
+
var allSldsHooks2 = [...sldsPlusStylingHooks2.global, ...sldsPlusStylingHooks2.component];
|
|
1305
|
+
var allSldsHooksSet = new Set(allSldsHooks2);
|
|
1306
|
+
function hasUnsupportedFallback(lwcToken, sldsToken) {
|
|
1307
|
+
const normalizedSldsToken = sldsToken.replace("--sds-", "--slds-");
|
|
1308
|
+
return lwcToken.startsWith("--lwc-") && normalizedSldsToken.startsWith("--slds-") && allSldsHooksSet.has(normalizedSldsToken);
|
|
1309
|
+
}
|
|
1310
|
+
var no_sldshook_fallback_for_lwctoken_default = {
|
|
1218
1311
|
meta: {
|
|
1219
|
-
type:
|
|
1312
|
+
type: type6,
|
|
1220
1313
|
docs: {
|
|
1221
|
-
description:
|
|
1314
|
+
description: description6,
|
|
1222
1315
|
recommended: true,
|
|
1223
|
-
url:
|
|
1316
|
+
url: url6
|
|
1224
1317
|
},
|
|
1225
|
-
messages:
|
|
1318
|
+
messages: messages6
|
|
1226
1319
|
},
|
|
1227
1320
|
create(context) {
|
|
1228
1321
|
return {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1322
|
+
// Handle LWC tokens inside var() functions: var(--lwc-*, ...)
|
|
1323
|
+
"Function[name='var'] Identifier[name=/^--lwc-/]"(node) {
|
|
1324
|
+
const lwcToken = node.name;
|
|
1325
|
+
const varFunctionNode = context.sourceCode.getAncestors(node).at(-1);
|
|
1326
|
+
if (!varFunctionNode) return;
|
|
1327
|
+
const varFunctionChildren = varFunctionNode.children;
|
|
1328
|
+
if (!varFunctionChildren) return;
|
|
1329
|
+
let foundComma = false;
|
|
1330
|
+
let fallbackRawNode = null;
|
|
1331
|
+
for (const child of varFunctionChildren) {
|
|
1332
|
+
if (child.type === "Operator" && child.value === ",") {
|
|
1333
|
+
foundComma = true;
|
|
1334
|
+
continue;
|
|
1242
1335
|
}
|
|
1243
|
-
|
|
1336
|
+
if (foundComma && child.type === "Raw") {
|
|
1337
|
+
fallbackRawNode = child;
|
|
1338
|
+
break;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
if (!fallbackRawNode) return;
|
|
1342
|
+
const fallbackValue = fallbackRawNode.value.trim();
|
|
1343
|
+
const varMatch = fallbackValue.match(/var\(([^,)]+)/);
|
|
1344
|
+
if (!varMatch) return;
|
|
1345
|
+
const sldsToken = varMatch[1];
|
|
1346
|
+
if (hasUnsupportedFallback(lwcToken, sldsToken)) {
|
|
1347
|
+
context.report({
|
|
1348
|
+
node,
|
|
1349
|
+
messageId: "unsupportedFallback",
|
|
1350
|
+
data: { lwcToken, sldsToken }
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1244
1353
|
}
|
|
1245
1354
|
};
|
|
1246
1355
|
}
|
|
1247
1356
|
};
|
|
1248
1357
|
|
|
1249
|
-
// src/rules/v9/no-
|
|
1250
|
-
var
|
|
1251
|
-
var
|
|
1252
|
-
var
|
|
1253
|
-
var
|
|
1358
|
+
// src/rules/v9/no-unsupported-hooks-slds2.ts
|
|
1359
|
+
var import_sds_metadata8 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
1360
|
+
var import_rule_messages8 = __toESM(require_rule_messages());
|
|
1361
|
+
var ruleConfig6 = import_rule_messages8.default["no-unsupported-hooks-slds2"];
|
|
1362
|
+
var { type: type7, description: description7, url: url7, messages: messages7 } = ruleConfig6;
|
|
1363
|
+
var deprecatedHooks = new Set(import_sds_metadata8.default.deprecatedStylingHooks);
|
|
1364
|
+
function shouldIgnoreDetection3(sldsHook) {
|
|
1365
|
+
return !deprecatedHooks.has(sldsHook);
|
|
1366
|
+
}
|
|
1367
|
+
var no_unsupported_hooks_slds2_default = {
|
|
1254
1368
|
meta: {
|
|
1255
|
-
type:
|
|
1369
|
+
type: type7,
|
|
1256
1370
|
docs: {
|
|
1257
|
-
description:
|
|
1371
|
+
description: description7,
|
|
1258
1372
|
recommended: true,
|
|
1259
|
-
url:
|
|
1373
|
+
url: url7
|
|
1260
1374
|
},
|
|
1261
|
-
|
|
1262
|
-
messages: messages12
|
|
1375
|
+
messages: messages7
|
|
1263
1376
|
},
|
|
1264
1377
|
create(context) {
|
|
1378
|
+
function reportDeprecatedHook(node, token) {
|
|
1379
|
+
context.report({
|
|
1380
|
+
node,
|
|
1381
|
+
messageId: "deprecated",
|
|
1382
|
+
data: { token }
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1265
1385
|
return {
|
|
1266
|
-
// Handle CSS custom
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1386
|
+
// Handle CSS custom property declarations (left-side usage): --slds-* properties
|
|
1387
|
+
// Example: .THIS { --slds-g-link-color: #f73650; }
|
|
1388
|
+
"Declaration[property=/^--s(lds|ds)-/]"(node) {
|
|
1389
|
+
const property = node.property;
|
|
1390
|
+
if (shouldIgnoreDetection3(property)) {
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
reportDeprecatedHook(node, property);
|
|
1394
|
+
},
|
|
1395
|
+
// Handle SLDS/SDS hooks inside var() functions (right-side usage): var(--slds-*)
|
|
1396
|
+
// Example: .THIS .demo { border-top: 1px solid var(--slds-g-color-border-brand-1); }
|
|
1397
|
+
"Function[name='var'] Identifier[name=/^--s(lds|ds)-/]"(node) {
|
|
1398
|
+
const tokenName = node.name;
|
|
1399
|
+
if (shouldIgnoreDetection3(tokenName)) {
|
|
1400
|
+
return;
|
|
1280
1401
|
}
|
|
1402
|
+
reportDeprecatedHook(node, tokenName);
|
|
1281
1403
|
}
|
|
1282
1404
|
};
|
|
1283
1405
|
}
|
|
1284
1406
|
};
|
|
1285
1407
|
|
|
1286
|
-
// src/rules/v9/no-
|
|
1287
|
-
var
|
|
1288
|
-
var
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
var
|
|
1292
|
-
var
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1408
|
+
// src/rules/v9/no-slds-var-without-fallback.ts
|
|
1409
|
+
var import_sds_metadata9 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
1410
|
+
var import_rule_messages9 = __toESM(require_rule_messages());
|
|
1411
|
+
var ruleConfig7 = import_rule_messages9.default["no-slds-var-without-fallback"];
|
|
1412
|
+
var { type: type8, description: description8, url: url8, messages: messages8 } = ruleConfig7;
|
|
1413
|
+
var sldsVariables = import_sds_metadata9.default.slds1ExcludedVars || {};
|
|
1414
|
+
var no_slds_var_without_fallback_default = {
|
|
1415
|
+
meta: {
|
|
1416
|
+
type: type8,
|
|
1417
|
+
docs: {
|
|
1418
|
+
description: description8,
|
|
1419
|
+
recommended: true,
|
|
1420
|
+
url: url8
|
|
1421
|
+
},
|
|
1422
|
+
fixable: "code",
|
|
1423
|
+
messages: messages8
|
|
1424
|
+
},
|
|
1425
|
+
create(context) {
|
|
1426
|
+
return {
|
|
1427
|
+
"Declaration"(node) {
|
|
1428
|
+
const valueText = context.sourceCode.getText(node.value);
|
|
1429
|
+
if (!valueText) return;
|
|
1430
|
+
const variablesNeedingFallback = [];
|
|
1431
|
+
forEachSldsVariable(valueText, (variableInfo, positionInfo) => {
|
|
1432
|
+
const { name: cssVar, hasFallback } = variableInfo;
|
|
1433
|
+
if (hasFallback) return;
|
|
1434
|
+
const fallbackValue = sldsVariables[cssVar];
|
|
1435
|
+
if (!fallbackValue) return;
|
|
1436
|
+
variablesNeedingFallback.push({
|
|
1437
|
+
cssVar,
|
|
1438
|
+
fallbackValue,
|
|
1439
|
+
start: positionInfo.start?.offset || 0,
|
|
1440
|
+
end: positionInfo.end?.offset || 0
|
|
1441
|
+
});
|
|
1442
|
+
});
|
|
1443
|
+
if (variablesNeedingFallback.length > 0) {
|
|
1444
|
+
let newValue = valueText;
|
|
1445
|
+
const sortedVariables = variablesNeedingFallback.sort((a, b) => b.start - a.start);
|
|
1446
|
+
sortedVariables.forEach(({ cssVar, fallbackValue, start, end }) => {
|
|
1447
|
+
const replacement = `var(${cssVar}, ${fallbackValue})`;
|
|
1448
|
+
newValue = newValue.substring(0, start) + replacement + newValue.substring(end);
|
|
1449
|
+
});
|
|
1450
|
+
variablesNeedingFallback.forEach(({ cssVar, fallbackValue }) => {
|
|
1451
|
+
context.report({
|
|
1452
|
+
node,
|
|
1453
|
+
messageId: "varWithoutFallback",
|
|
1454
|
+
data: { cssVar, recommendation: fallbackValue },
|
|
1455
|
+
fix: (fixer) => fixer.replaceText(node.value, newValue)
|
|
1456
|
+
});
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1334
1461
|
}
|
|
1335
1462
|
};
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1463
|
+
|
|
1464
|
+
// src/rules/v9/no-slds-namespace-for-custom-hooks.ts
|
|
1465
|
+
var import_sds_metadata10 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
1466
|
+
var import_rule_messages10 = __toESM(require_rule_messages());
|
|
1467
|
+
var ruleConfig8 = import_rule_messages10.default["no-slds-namespace-for-custom-hooks"];
|
|
1468
|
+
var { type: type9, description: description9, url: url9, messages: messages9 } = ruleConfig8;
|
|
1469
|
+
var sldsPlusStylingHooks3 = import_sds_metadata10.default.sldsPlusStylingHooks;
|
|
1470
|
+
var allSldsHooks3 = [...sldsPlusStylingHooks3.global, ...sldsPlusStylingHooks3.component];
|
|
1471
|
+
var toSldsToken2 = (sdsToken) => sdsToken.replace("--sds-", "--slds-");
|
|
1472
|
+
function shouldIgnoreDetection4(sdsToken) {
|
|
1473
|
+
if (sdsToken.startsWith("--sds-") || sdsToken.startsWith("--slds-")) {
|
|
1474
|
+
return allSldsHooks3.includes(toSldsToken2(sdsToken));
|
|
1475
|
+
}
|
|
1476
|
+
return true;
|
|
1477
|
+
}
|
|
1478
|
+
var no_slds_namespace_for_custom_hooks_default = {
|
|
1479
|
+
meta: {
|
|
1480
|
+
type: type9,
|
|
1481
|
+
docs: {
|
|
1482
|
+
description: description9,
|
|
1483
|
+
recommended: true,
|
|
1484
|
+
url: url9
|
|
1485
|
+
},
|
|
1486
|
+
messages: messages9
|
|
1487
|
+
},
|
|
1488
|
+
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
|
|
1360
1497
|
}
|
|
1361
1498
|
});
|
|
1362
1499
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1500
|
+
return {
|
|
1501
|
+
// CSS custom property declarations: --slds-* and --sds-* properties
|
|
1502
|
+
"Declaration[property=/^--s(lds|ds)-/]"(node) {
|
|
1503
|
+
const property = node.property;
|
|
1504
|
+
if (shouldIgnoreDetection4(property)) {
|
|
1505
|
+
return;
|
|
1506
|
+
}
|
|
1507
|
+
reportViolation(node, property);
|
|
1508
|
+
},
|
|
1509
|
+
// SLDS/SDS tokens inside var() functions: var(--slds-*) or var(--sds-*)
|
|
1510
|
+
"Function[name='var'] Identifier[name=/^--s(lds|ds)-/]"(node) {
|
|
1511
|
+
const tokenName = node.name;
|
|
1512
|
+
if (shouldIgnoreDetection4(tokenName)) {
|
|
1513
|
+
return;
|
|
1514
|
+
}
|
|
1515
|
+
reportViolation(node, tokenName);
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1380
1518
|
}
|
|
1381
|
-
return Array.from(new Set(returnStylingHooks));
|
|
1382
1519
|
};
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1520
|
+
|
|
1521
|
+
// src/rules/v9/enforce-component-hook-naming-convention.ts
|
|
1522
|
+
var import_sds_metadata11 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
1523
|
+
var import_rule_messages11 = __toESM(require_rule_messages());
|
|
1524
|
+
var ruleConfig9 = import_rule_messages11.default["enforce-component-hook-naming-convention"];
|
|
1525
|
+
var { type: type10, description: description10, url: url10, messages: messages10 } = ruleConfig9;
|
|
1526
|
+
var slds1DeprecatedComponentHooks = import_sds_metadata11.default.slds1DeprecatedComponentHooks;
|
|
1527
|
+
function shouldIgnoreDetection5(hook) {
|
|
1528
|
+
return !hook.startsWith("--slds-c-") || !(hook in slds1DeprecatedComponentHooks);
|
|
1529
|
+
}
|
|
1530
|
+
var enforce_component_hook_naming_convention_default = {
|
|
1531
|
+
meta: {
|
|
1532
|
+
type: type10,
|
|
1533
|
+
docs: {
|
|
1534
|
+
description: description10,
|
|
1535
|
+
recommended: true,
|
|
1536
|
+
url: url10
|
|
1537
|
+
},
|
|
1538
|
+
fixable: "code",
|
|
1539
|
+
messages: messages10
|
|
1540
|
+
},
|
|
1541
|
+
create(context) {
|
|
1542
|
+
return {
|
|
1543
|
+
/*
|
|
1544
|
+
* Handle component hooks in CSS declarations
|
|
1545
|
+
* Limitation: For example:
|
|
1546
|
+
* .testClass{
|
|
1547
|
+
* --slds-c-accordion-section-color-background: var(--slds-c-accordion-section-color-border);
|
|
1548
|
+
* }
|
|
1549
|
+
* var in value is not detected, because eslint treats above statement as custom property assignment
|
|
1550
|
+
* and value treated as raw string, not parsed into function nodes
|
|
1551
|
+
*/
|
|
1552
|
+
"Declaration[property=/^--slds-c-/], Function[name='var'] Identifier[name=/^--slds-c-/]"(node) {
|
|
1553
|
+
let hookName;
|
|
1554
|
+
let reportNode = node;
|
|
1555
|
+
if (node.type === "Declaration") {
|
|
1556
|
+
hookName = node.property;
|
|
1557
|
+
} else if (node.type === "Identifier") {
|
|
1558
|
+
hookName = node.name;
|
|
1559
|
+
} else {
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
if (shouldIgnoreDetection5(hookName)) {
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
const suggestedMatch = slds1DeprecatedComponentHooks[hookName];
|
|
1566
|
+
context.report({
|
|
1567
|
+
node: reportNode,
|
|
1568
|
+
messageId: "replace",
|
|
1569
|
+
data: {
|
|
1570
|
+
oldValue: hookName,
|
|
1571
|
+
suggestedMatch
|
|
1572
|
+
},
|
|
1573
|
+
fix(fixer) {
|
|
1574
|
+
if (node.type === "Declaration") {
|
|
1575
|
+
const originalText = context.sourceCode.getText(node);
|
|
1576
|
+
const colonIndex = originalText.indexOf(":");
|
|
1577
|
+
const valuePartWithColon = originalText.substring(colonIndex);
|
|
1578
|
+
return fixer.replaceText(node, `${suggestedMatch}${valuePartWithColon}`);
|
|
1579
|
+
} else if (node.type === "Identifier") {
|
|
1580
|
+
return fixer.replaceText(node, suggestedMatch);
|
|
1581
|
+
}
|
|
1582
|
+
return null;
|
|
1583
|
+
}
|
|
1584
|
+
});
|
|
1396
1585
|
}
|
|
1397
|
-
|
|
1586
|
+
};
|
|
1398
1587
|
}
|
|
1399
|
-
return colorValue && isValidColor(colorValue) ? colorValue : null;
|
|
1400
1588
|
};
|
|
1401
1589
|
|
|
1402
|
-
// src/
|
|
1403
|
-
var
|
|
1404
|
-
var
|
|
1405
|
-
var
|
|
1406
|
-
var
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
var BORDER_RADIUS_REGEX = new RegExp(`^border(?:-${CORNER_VALUES})?-radius$`);
|
|
1411
|
-
var INSET_REGEX = new RegExp(`^inset(?:-${INSET_VALUES})?$`);
|
|
1412
|
-
function isBorderColorProperty(cssProperty) {
|
|
1413
|
-
return BORDER_COLOR_REGEX.test(cssProperty);
|
|
1414
|
-
}
|
|
1415
|
-
function isBorderWidthProperty(cssProperty) {
|
|
1416
|
-
return BORDER_WIDTH_REGEX.test(cssProperty);
|
|
1417
|
-
}
|
|
1418
|
-
function isMarginProperty(cssProperty) {
|
|
1419
|
-
return MARGIN_REGEX.test(cssProperty);
|
|
1420
|
-
}
|
|
1421
|
-
function isPaddingProperty(cssProperty) {
|
|
1422
|
-
return PADDING_REGEX.test(cssProperty);
|
|
1423
|
-
}
|
|
1424
|
-
function isBorderRadius(cssProperty) {
|
|
1425
|
-
return BORDER_RADIUS_REGEX.test(cssProperty);
|
|
1426
|
-
}
|
|
1427
|
-
function isDimensionProperty(cssProperty) {
|
|
1428
|
-
return ["width", "height", "min-width", "max-width", "min-height", "max-height"].includes(cssProperty);
|
|
1429
|
-
}
|
|
1430
|
-
function isInsetProperty(cssProperty) {
|
|
1431
|
-
return INSET_REGEX.test(cssProperty);
|
|
1432
|
-
}
|
|
1433
|
-
var fontProperties = [
|
|
1434
|
-
"font",
|
|
1435
|
-
"font-size",
|
|
1436
|
-
"font-weight"
|
|
1437
|
-
];
|
|
1438
|
-
var colorProperties = [
|
|
1439
|
-
"color",
|
|
1440
|
-
"fill",
|
|
1441
|
-
"background",
|
|
1442
|
-
"background-color",
|
|
1443
|
-
"stroke",
|
|
1444
|
-
"border",
|
|
1445
|
-
"border*",
|
|
1446
|
-
"border*-color",
|
|
1447
|
-
"outline",
|
|
1448
|
-
"outline-color"
|
|
1449
|
-
];
|
|
1450
|
-
var densificationProperties = [
|
|
1451
|
-
"border*",
|
|
1452
|
-
"margin*",
|
|
1453
|
-
"padding*",
|
|
1454
|
-
"width",
|
|
1455
|
-
"height",
|
|
1456
|
-
"min-width",
|
|
1457
|
-
"max-width",
|
|
1458
|
-
"min-height",
|
|
1459
|
-
"max-height",
|
|
1460
|
-
"inset",
|
|
1461
|
-
"top",
|
|
1462
|
-
"right",
|
|
1463
|
-
"left",
|
|
1464
|
-
"bottom",
|
|
1465
|
-
"outline",
|
|
1466
|
-
"outline-width",
|
|
1467
|
-
"line-height"
|
|
1468
|
-
];
|
|
1469
|
-
function toSelector(properties) {
|
|
1470
|
-
const selectorParts = properties.map((prop) => {
|
|
1471
|
-
if (prop.includes("*")) {
|
|
1472
|
-
const regexPattern = prop.replace(/\*/g, ".*");
|
|
1473
|
-
return `Declaration[property=/${regexPattern}$/]`;
|
|
1474
|
-
} else {
|
|
1475
|
-
return `Declaration[property='${prop}']`;
|
|
1476
|
-
}
|
|
1477
|
-
});
|
|
1478
|
-
return selectorParts.join(", ");
|
|
1479
|
-
}
|
|
1480
|
-
function resolvePropertyToMatch(cssProperty) {
|
|
1481
|
-
const propertyToMatch = cssProperty.toLowerCase();
|
|
1482
|
-
if (propertyToMatch === "outline" || propertyToMatch === "outline-width" || isBorderWidthProperty(propertyToMatch)) {
|
|
1483
|
-
return "border-width";
|
|
1484
|
-
} else if (isMarginProperty(propertyToMatch)) {
|
|
1485
|
-
return "margin";
|
|
1486
|
-
} else if (isPaddingProperty(propertyToMatch)) {
|
|
1487
|
-
return "padding";
|
|
1488
|
-
} else if (isBorderRadius(propertyToMatch)) {
|
|
1489
|
-
return "border-radius";
|
|
1490
|
-
} else if (isDimensionProperty(propertyToMatch)) {
|
|
1491
|
-
return "width";
|
|
1492
|
-
} else if (isInsetProperty(propertyToMatch)) {
|
|
1493
|
-
return "top";
|
|
1494
|
-
} else if (cssProperty === "background" || cssProperty === "background-color") {
|
|
1495
|
-
return "background-color";
|
|
1496
|
-
} else if (cssProperty === "outline" || cssProperty === "outline-color" || isBorderColorProperty(cssProperty)) {
|
|
1497
|
-
return "border-color";
|
|
1498
|
-
}
|
|
1499
|
-
return propertyToMatch;
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
// src/utils/hardcoded-shared-utils.ts
|
|
1503
|
-
var import_css_tree2 = require("@eslint/css-tree");
|
|
1504
|
-
var FONT_WEIGHTS = [
|
|
1505
|
-
"normal",
|
|
1506
|
-
"bold",
|
|
1507
|
-
"bolder",
|
|
1508
|
-
"lighter",
|
|
1509
|
-
"100",
|
|
1510
|
-
"200",
|
|
1511
|
-
"300",
|
|
1512
|
-
"400",
|
|
1513
|
-
"500",
|
|
1514
|
-
"600",
|
|
1515
|
-
"700",
|
|
1516
|
-
"800",
|
|
1517
|
-
"900"
|
|
1590
|
+
// src/rules/v9/reduce-annotations.ts
|
|
1591
|
+
var import_rule_messages12 = __toESM(require_rule_messages());
|
|
1592
|
+
var ruleConfig10 = import_rule_messages12.default["reduce-annotations"];
|
|
1593
|
+
var { type: type11, description: description11, url: url11, messages: messages11 } = ruleConfig10;
|
|
1594
|
+
var SLDS_ANNOTATIONS = [
|
|
1595
|
+
"@sldsValidatorIgnoreNextLine",
|
|
1596
|
+
"@sldsValidatorAllow",
|
|
1597
|
+
"@sldsValidatorIgnore"
|
|
1518
1598
|
];
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1599
|
+
var reduce_annotations_default = {
|
|
1600
|
+
meta: {
|
|
1601
|
+
type: type11,
|
|
1602
|
+
docs: {
|
|
1603
|
+
description: description11,
|
|
1604
|
+
recommended: true,
|
|
1605
|
+
url: url11
|
|
1606
|
+
},
|
|
1607
|
+
messages: messages11
|
|
1608
|
+
},
|
|
1609
|
+
create(context) {
|
|
1610
|
+
return {
|
|
1611
|
+
StyleSheet(node) {
|
|
1612
|
+
const sourceCode = context.sourceCode;
|
|
1613
|
+
let comments = sourceCode?.comments || [];
|
|
1614
|
+
comments.forEach((comment) => {
|
|
1615
|
+
const commentContent = comment.value.trim();
|
|
1616
|
+
const matchingAnnotation = SLDS_ANNOTATIONS.find(
|
|
1617
|
+
(annotation) => commentContent.startsWith(annotation)
|
|
1618
|
+
);
|
|
1619
|
+
if (matchingAnnotation) {
|
|
1620
|
+
context.report({
|
|
1621
|
+
node: comment,
|
|
1622
|
+
messageId: "removeAnnotation"
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
});
|
|
1544
1626
|
}
|
|
1545
1627
|
};
|
|
1546
|
-
if (hasHook) {
|
|
1547
|
-
const fix = canAutoFix ? (fixer) => {
|
|
1548
|
-
let newValue = valueText;
|
|
1549
|
-
for (let i = sortedReplacements.length - 1; i >= 0; i--) {
|
|
1550
|
-
const { start: rStart, end: rEnd, replacement: rReplacement } = sortedReplacements[i];
|
|
1551
|
-
newValue = newValue.substring(0, rStart) + rReplacement + newValue.substring(rEnd);
|
|
1552
|
-
}
|
|
1553
|
-
return fixer.replaceText(declarationNode.value, newValue);
|
|
1554
|
-
} : void 0;
|
|
1555
|
-
context.context.report({
|
|
1556
|
-
node: reportNode,
|
|
1557
|
-
messageId: "hardcodedValue",
|
|
1558
|
-
data: {
|
|
1559
|
-
oldValue: originalValue,
|
|
1560
|
-
newValue: displayValue
|
|
1561
|
-
},
|
|
1562
|
-
fix
|
|
1563
|
-
});
|
|
1564
|
-
} else {
|
|
1565
|
-
context.context.report({
|
|
1566
|
-
node: reportNode,
|
|
1567
|
-
messageId: "noReplacement",
|
|
1568
|
-
data: {
|
|
1569
|
-
oldValue: originalValue
|
|
1570
|
-
}
|
|
1571
|
-
});
|
|
1572
|
-
}
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
function forEachValue(valueText, extractValue, shouldSkipNode, callback) {
|
|
1576
|
-
if (!valueText || typeof valueText !== "string") {
|
|
1577
|
-
return;
|
|
1578
|
-
}
|
|
1579
|
-
try {
|
|
1580
|
-
const ast = (0, import_css_tree2.parse)(valueText, { context: "value", positions: true });
|
|
1581
|
-
(0, import_css_tree2.walk)(ast, {
|
|
1582
|
-
enter(node) {
|
|
1583
|
-
if (shouldSkipNode(node)) {
|
|
1584
|
-
return this.skip;
|
|
1585
|
-
}
|
|
1586
|
-
const value = extractValue(node);
|
|
1587
|
-
if (value !== null) {
|
|
1588
|
-
const positionInfo = {
|
|
1589
|
-
start: node.loc?.start,
|
|
1590
|
-
end: node.loc?.end
|
|
1591
|
-
};
|
|
1592
|
-
callback(value, positionInfo);
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
});
|
|
1596
|
-
} catch (error) {
|
|
1597
|
-
return;
|
|
1598
1628
|
}
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1629
|
+
};
|
|
1630
|
+
|
|
1631
|
+
// src/rules/v9/no-slds-private-var.ts
|
|
1632
|
+
var import_rule_messages13 = __toESM(require_rule_messages());
|
|
1633
|
+
var ruleConfig11 = import_rule_messages13.default["no-slds-private-var"];
|
|
1634
|
+
var { type: type12, description: description12, url: url12, messages: messages12 } = ruleConfig11;
|
|
1635
|
+
var no_slds_private_var_default = {
|
|
1636
|
+
meta: {
|
|
1637
|
+
type: type12,
|
|
1638
|
+
docs: {
|
|
1639
|
+
description: description12,
|
|
1640
|
+
recommended: true,
|
|
1641
|
+
url: url12
|
|
1642
|
+
},
|
|
1643
|
+
fixable: "code",
|
|
1644
|
+
messages: messages12
|
|
1645
|
+
},
|
|
1646
|
+
create(context) {
|
|
1647
|
+
return {
|
|
1648
|
+
// Handle CSS custom properties (declarations starting with --)
|
|
1649
|
+
"Declaration"(node) {
|
|
1650
|
+
if (node.property && typeof node.property === "string" && node.property.startsWith("--_slds-")) {
|
|
1651
|
+
context.report({
|
|
1652
|
+
node,
|
|
1653
|
+
messageId: "privateVar",
|
|
1654
|
+
data: { prop: node.property },
|
|
1655
|
+
fix(fixer) {
|
|
1656
|
+
const newProperty = node.property.replace("--_slds-", "--slds-");
|
|
1657
|
+
const sourceCode = context.sourceCode.getText(node);
|
|
1658
|
+
const fixedCode = sourceCode.replace(node.property, newProperty);
|
|
1659
|
+
return fixer.replaceText(node, fixedCode);
|
|
1660
|
+
}
|
|
1661
|
+
});
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1634
1665
|
}
|
|
1635
|
-
|
|
1666
|
+
};
|
|
1667
|
+
|
|
1668
|
+
// src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.ts
|
|
1669
|
+
var import_sds_metadata12 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
1670
|
+
var import_rule_messages14 = __toESM(require_rule_messages());
|
|
1671
|
+
|
|
1672
|
+
// src/utils/property-matcher.ts
|
|
1673
|
+
var DIRECTION_VALUES = "(?:top|right|bottom|left|inline|block|inline-start|inline-end|start|end|block-start|block-end)";
|
|
1674
|
+
var CORNER_VALUES = "(?:top-left|top-right|bottom-right|bottom-left|start-start|start-end|end-start|end-end)";
|
|
1675
|
+
var INSET_VALUES = "(?:inline|block|inline-start|inline-end|block-start|block-end)";
|
|
1676
|
+
var BORDER_COLOR_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-color$`);
|
|
1677
|
+
var BORDER_WIDTH_REGEX = new RegExp(`^border(?:-${DIRECTION_VALUES})?-width$`);
|
|
1678
|
+
var MARGIN_REGEX = new RegExp(`^margin(?:-${DIRECTION_VALUES})?$`);
|
|
1679
|
+
var PADDING_REGEX = new RegExp(`^padding(?:-${DIRECTION_VALUES})?$`);
|
|
1680
|
+
var BORDER_RADIUS_REGEX = new RegExp(`^border(?:-${CORNER_VALUES})?-radius$`);
|
|
1681
|
+
var INSET_REGEX = new RegExp(`^inset(?:-${INSET_VALUES})?$`);
|
|
1682
|
+
function isBorderColorProperty(cssProperty) {
|
|
1683
|
+
return BORDER_COLOR_REGEX.test(cssProperty);
|
|
1636
1684
|
}
|
|
1637
|
-
function
|
|
1638
|
-
|
|
1685
|
+
function isBorderWidthProperty(cssProperty) {
|
|
1686
|
+
return BORDER_WIDTH_REGEX.test(cssProperty);
|
|
1639
1687
|
}
|
|
1640
|
-
function
|
|
1641
|
-
|
|
1642
|
-
valueText,
|
|
1643
|
-
(node) => extractDimensionValue(node, cssProperty),
|
|
1644
|
-
shouldSkipDimensionNode,
|
|
1645
|
-
callback
|
|
1646
|
-
);
|
|
1688
|
+
function isMarginProperty(cssProperty) {
|
|
1689
|
+
return MARGIN_REGEX.test(cssProperty);
|
|
1647
1690
|
}
|
|
1648
|
-
function
|
|
1649
|
-
|
|
1650
|
-
switch (node.type) {
|
|
1651
|
-
case "Dimension":
|
|
1652
|
-
const numValue = Number(node.value);
|
|
1653
|
-
if (numValue <= 0) return null;
|
|
1654
|
-
const unit = node.unit.toLowerCase();
|
|
1655
|
-
if (unit !== "px" && unit !== "rem" && unit !== "%") return null;
|
|
1656
|
-
return {
|
|
1657
|
-
number: numValue,
|
|
1658
|
-
unit
|
|
1659
|
-
};
|
|
1660
|
-
case "Number":
|
|
1661
|
-
const numberValue = Number(node.value);
|
|
1662
|
-
if (numberValue <= 0) {
|
|
1663
|
-
return null;
|
|
1664
|
-
}
|
|
1665
|
-
if (!isKnownFontWeight(numberValue)) {
|
|
1666
|
-
return null;
|
|
1667
|
-
}
|
|
1668
|
-
return {
|
|
1669
|
-
number: numberValue,
|
|
1670
|
-
unit: null
|
|
1671
|
-
};
|
|
1672
|
-
case "Identifier":
|
|
1673
|
-
const namedValue = node.name.toLowerCase();
|
|
1674
|
-
if (!isKnownFontWeight(namedValue)) {
|
|
1675
|
-
return null;
|
|
1676
|
-
}
|
|
1677
|
-
if (namedValue === "normal") {
|
|
1678
|
-
return { number: 400, unit: null };
|
|
1679
|
-
}
|
|
1680
|
-
return { number: namedValue, unit: null };
|
|
1681
|
-
case "Percentage":
|
|
1682
|
-
const percentValue = Number(node.value);
|
|
1683
|
-
if (percentValue === 0) return null;
|
|
1684
|
-
return {
|
|
1685
|
-
number: percentValue,
|
|
1686
|
-
unit: "%"
|
|
1687
|
-
};
|
|
1688
|
-
case "Value":
|
|
1689
|
-
return node.children?.[0] ? extractFontValue(node.children[0]) : null;
|
|
1690
|
-
}
|
|
1691
|
-
return null;
|
|
1691
|
+
function isPaddingProperty(cssProperty) {
|
|
1692
|
+
return PADDING_REGEX.test(cssProperty);
|
|
1692
1693
|
}
|
|
1693
|
-
function
|
|
1694
|
-
return
|
|
1694
|
+
function isBorderRadius(cssProperty) {
|
|
1695
|
+
return BORDER_RADIUS_REGEX.test(cssProperty);
|
|
1695
1696
|
}
|
|
1696
|
-
function
|
|
1697
|
-
|
|
1697
|
+
function isDimensionProperty(cssProperty) {
|
|
1698
|
+
return ["width", "height", "min-width", "max-width", "min-height", "max-height"].includes(cssProperty);
|
|
1699
|
+
}
|
|
1700
|
+
function isInsetProperty(cssProperty) {
|
|
1701
|
+
return INSET_REGEX.test(cssProperty);
|
|
1702
|
+
}
|
|
1703
|
+
var fontProperties = [
|
|
1704
|
+
"font",
|
|
1705
|
+
"font-size",
|
|
1706
|
+
"font-weight"
|
|
1707
|
+
];
|
|
1708
|
+
var colorProperties = [
|
|
1709
|
+
"color",
|
|
1710
|
+
"fill",
|
|
1711
|
+
"background",
|
|
1712
|
+
"background-color",
|
|
1713
|
+
"stroke",
|
|
1714
|
+
"border",
|
|
1715
|
+
"border*",
|
|
1716
|
+
"border*-color",
|
|
1717
|
+
"outline",
|
|
1718
|
+
"outline-color"
|
|
1719
|
+
];
|
|
1720
|
+
var densificationProperties = [
|
|
1721
|
+
"border*",
|
|
1722
|
+
"margin*",
|
|
1723
|
+
"padding*",
|
|
1724
|
+
"width",
|
|
1725
|
+
"height",
|
|
1726
|
+
"min-width",
|
|
1727
|
+
"max-width",
|
|
1728
|
+
"min-height",
|
|
1729
|
+
"max-height",
|
|
1730
|
+
"inset",
|
|
1731
|
+
"top",
|
|
1732
|
+
"right",
|
|
1733
|
+
"left",
|
|
1734
|
+
"bottom",
|
|
1735
|
+
"outline",
|
|
1736
|
+
"outline-width",
|
|
1737
|
+
"line-height"
|
|
1738
|
+
];
|
|
1739
|
+
function toSelector(properties) {
|
|
1740
|
+
const selectorParts = properties.map((prop) => {
|
|
1741
|
+
if (prop.includes("*")) {
|
|
1742
|
+
const regexPattern = prop.replace(/\*/g, ".*");
|
|
1743
|
+
return `Declaration[property=/^${regexPattern}$/]`;
|
|
1744
|
+
} else {
|
|
1745
|
+
return `Declaration[property='${prop}']`;
|
|
1746
|
+
}
|
|
1747
|
+
});
|
|
1748
|
+
return selectorParts.join(", ");
|
|
1749
|
+
}
|
|
1750
|
+
function resolvePropertyToMatch(cssProperty) {
|
|
1751
|
+
const propertyToMatch = cssProperty.toLowerCase();
|
|
1752
|
+
if (propertyToMatch === "outline" || propertyToMatch === "outline-width" || isBorderWidthProperty(propertyToMatch)) {
|
|
1753
|
+
return "border-width";
|
|
1754
|
+
} else if (isMarginProperty(propertyToMatch)) {
|
|
1755
|
+
return "margin";
|
|
1756
|
+
} else if (isPaddingProperty(propertyToMatch)) {
|
|
1757
|
+
return "padding";
|
|
1758
|
+
} else if (isBorderRadius(propertyToMatch)) {
|
|
1759
|
+
return "border-radius";
|
|
1760
|
+
} else if (isDimensionProperty(propertyToMatch)) {
|
|
1761
|
+
return "width";
|
|
1762
|
+
} else if (isInsetProperty(propertyToMatch)) {
|
|
1763
|
+
return "top";
|
|
1764
|
+
} else if (cssProperty === "background" || cssProperty === "background-color") {
|
|
1765
|
+
return "background-color";
|
|
1766
|
+
} else if (cssProperty === "outline" || cssProperty === "outline-color" || isBorderColorProperty(cssProperty)) {
|
|
1767
|
+
return "border-color";
|
|
1768
|
+
}
|
|
1769
|
+
return propertyToMatch;
|
|
1698
1770
|
}
|
|
1699
1771
|
|
|
1700
1772
|
// src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts
|
|
@@ -1739,9 +1811,8 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
1739
1811
|
end,
|
|
1740
1812
|
replacement: originalValue,
|
|
1741
1813
|
// Use original value to preserve spacing
|
|
1742
|
-
displayValue: closestHooks
|
|
1814
|
+
displayValue: formatSuggestionHooks(closestHooks),
|
|
1743
1815
|
hasHook: true
|
|
1744
|
-
// ← THE FIX: Multiple hooks still means "has hooks"
|
|
1745
1816
|
};
|
|
1746
1817
|
} else {
|
|
1747
1818
|
return {
|
|
@@ -1755,37 +1826,6 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
1755
1826
|
}
|
|
1756
1827
|
}
|
|
1757
1828
|
|
|
1758
|
-
// src/utils/value-utils.ts
|
|
1759
|
-
function parseUnitValue(value) {
|
|
1760
|
-
if (!value) return null;
|
|
1761
|
-
const match = value.match(/^(-?\d*\.?\d+)(px|rem|%)?$/);
|
|
1762
|
-
if (!match) return null;
|
|
1763
|
-
const number = parseFloat(match[1]);
|
|
1764
|
-
const unit = match[2] ? match[2] : null;
|
|
1765
|
-
if (isNaN(number)) return null;
|
|
1766
|
-
return { number, unit };
|
|
1767
|
-
}
|
|
1768
|
-
function toAlternateUnitValue(numberVal, unitType) {
|
|
1769
|
-
if (unitType === "px") {
|
|
1770
|
-
let floatValue = parseFloat(`${numberVal / 16}`);
|
|
1771
|
-
if (!isNaN(floatValue)) {
|
|
1772
|
-
return {
|
|
1773
|
-
unit: "rem",
|
|
1774
|
-
number: parseFloat(floatValue.toFixed(4))
|
|
1775
|
-
};
|
|
1776
|
-
}
|
|
1777
|
-
} else if (unitType === "rem") {
|
|
1778
|
-
const intValue = parseInt(`${numberVal * 16}`);
|
|
1779
|
-
if (!isNaN(intValue)) {
|
|
1780
|
-
return {
|
|
1781
|
-
unit: "px",
|
|
1782
|
-
number: intValue
|
|
1783
|
-
};
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
return null;
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
1829
|
// src/utils/styling-hook-utils.ts
|
|
1790
1830
|
function isValueMatch(valueToMatch, sldsValue) {
|
|
1791
1831
|
if (!valueToMatch || !sldsValue) {
|
|
@@ -1843,7 +1883,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
1843
1883
|
start,
|
|
1844
1884
|
end,
|
|
1845
1885
|
replacement: rawValue,
|
|
1846
|
-
displayValue: closestHooks
|
|
1886
|
+
displayValue: formatSuggestionHooks(closestHooks),
|
|
1847
1887
|
hasHook: true
|
|
1848
1888
|
};
|
|
1849
1889
|
} else {
|
|
@@ -1910,7 +1950,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
1910
1950
|
start,
|
|
1911
1951
|
end,
|
|
1912
1952
|
replacement: rawValue,
|
|
1913
|
-
displayValue: closestHooks
|
|
1953
|
+
displayValue: formatSuggestionHooks(closestHooks),
|
|
1914
1954
|
hasHook: true
|
|
1915
1955
|
};
|
|
1916
1956
|
} else {
|
|
@@ -2037,59 +2077,51 @@ function isBoxShadowMatch(parsedCssValue, parsedValueHook) {
|
|
|
2037
2077
|
}
|
|
2038
2078
|
|
|
2039
2079
|
// src/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.ts
|
|
2040
|
-
function
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
const cssProperty = node.property.toLowerCase();
|
|
2045
|
-
const valueText = context.sourceCode.getText(node.value);
|
|
2046
|
-
if (containsCssVariable(valueText)) {
|
|
2047
|
-
return;
|
|
2048
|
-
}
|
|
2049
|
-
const replacements = [];
|
|
2050
|
-
const parsedCssValue = parseAndValidateBoxShadow(valueText);
|
|
2051
|
-
if (parsedCssValue) {
|
|
2052
|
-
const shadowHooks = getBoxShadowHooks(context.valueToStylinghook);
|
|
2053
|
-
const closestHooks = findMatchingBoxShadowHooks(parsedCssValue, shadowHooks);
|
|
2054
|
-
const positionInfo = {
|
|
2055
|
-
start: { offset: 0, line: 1, column: 1 },
|
|
2056
|
-
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
2057
|
-
};
|
|
2058
|
-
const replacement = createBoxShadowReplacement(
|
|
2059
|
-
valueText,
|
|
2060
|
-
closestHooks,
|
|
2061
|
-
context,
|
|
2062
|
-
positionInfo
|
|
2063
|
-
);
|
|
2064
|
-
if (replacement) {
|
|
2065
|
-
replacements.push(replacement);
|
|
2066
|
-
}
|
|
2080
|
+
function toBoxShadowValue(cssValue) {
|
|
2081
|
+
const parsedCssValue = parseBoxShadowValue(cssValue).filter((shadow) => Object.keys(shadow).length > 0);
|
|
2082
|
+
if (parsedCssValue.length === 0) {
|
|
2083
|
+
return null;
|
|
2067
2084
|
}
|
|
2068
|
-
|
|
2069
|
-
}
|
|
2070
|
-
function
|
|
2085
|
+
return parsedCssValue;
|
|
2086
|
+
}
|
|
2087
|
+
function shadowValueToHookEntries(supportedStylinghooks) {
|
|
2071
2088
|
return Object.entries(supportedStylinghooks).filter(([key, value]) => {
|
|
2072
2089
|
return value.some((hook) => hook.properties.includes("box-shadow"));
|
|
2073
2090
|
}).map(([key, value]) => {
|
|
2074
2091
|
return [key, value.map((hook) => hook.name)];
|
|
2075
2092
|
});
|
|
2076
2093
|
}
|
|
2077
|
-
|
|
2078
|
-
const
|
|
2079
|
-
|
|
2080
|
-
|
|
2094
|
+
var handleBoxShadowDeclaration = (node, context) => {
|
|
2095
|
+
const cssProperty = node.property.toLowerCase();
|
|
2096
|
+
const valueText = context.sourceCode.getText(node.value);
|
|
2097
|
+
const shadowHooks = shadowValueToHookEntries(context.valueToStylinghook);
|
|
2098
|
+
const parsedCssValue = toBoxShadowValue(valueText);
|
|
2099
|
+
if (!parsedCssValue) {
|
|
2100
|
+
return;
|
|
2081
2101
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2102
|
+
for (const [shadow, closestHooks] of shadowHooks) {
|
|
2103
|
+
const parsedValueHook = toBoxShadowValue(shadow);
|
|
2104
|
+
if (parsedValueHook && isBoxShadowMatch(parsedCssValue, parsedValueHook)) {
|
|
2105
|
+
if (closestHooks.length > 0) {
|
|
2106
|
+
const positionInfo = {
|
|
2107
|
+
start: { offset: 0, line: 1, column: 1 },
|
|
2108
|
+
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
2109
|
+
};
|
|
2110
|
+
const replacement = createBoxShadowReplacement(
|
|
2111
|
+
valueText,
|
|
2112
|
+
closestHooks,
|
|
2113
|
+
context,
|
|
2114
|
+
positionInfo
|
|
2115
|
+
);
|
|
2116
|
+
if (replacement) {
|
|
2117
|
+
const replacements = [replacement];
|
|
2118
|
+
handleShorthandAutoFix(node, context, valueText, replacements);
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
return;
|
|
2089
2122
|
}
|
|
2090
2123
|
}
|
|
2091
|
-
|
|
2092
|
-
}
|
|
2124
|
+
};
|
|
2093
2125
|
function createBoxShadowReplacement(originalValue, hooks, context, positionInfo) {
|
|
2094
2126
|
if (!positionInfo?.start) {
|
|
2095
2127
|
return null;
|
|
@@ -2104,28 +2136,39 @@ function createBoxShadowReplacement(originalValue, hooks, context, positionInfo)
|
|
|
2104
2136
|
displayValue: hooks[0],
|
|
2105
2137
|
hasHook: true
|
|
2106
2138
|
};
|
|
2107
|
-
} else if (hooks.length > 1) {
|
|
2108
|
-
return {
|
|
2109
|
-
start,
|
|
2110
|
-
end,
|
|
2111
|
-
replacement: originalValue,
|
|
2112
|
-
displayValue: hooks.join(", "),
|
|
2113
|
-
hasHook: true
|
|
2114
|
-
};
|
|
2115
2139
|
} else {
|
|
2116
2140
|
return {
|
|
2117
2141
|
start,
|
|
2118
2142
|
end,
|
|
2119
2143
|
replacement: originalValue,
|
|
2120
|
-
displayValue:
|
|
2121
|
-
hasHook:
|
|
2144
|
+
displayValue: formatSuggestionHooks(hooks),
|
|
2145
|
+
hasHook: true
|
|
2122
2146
|
};
|
|
2123
2147
|
}
|
|
2124
2148
|
}
|
|
2125
2149
|
|
|
2150
|
+
// src/utils/rule-utils.ts
|
|
2151
|
+
function isRuleEnabled(context, ruleName3) {
|
|
2152
|
+
try {
|
|
2153
|
+
const rules2 = context.settings?.sldsRules || {};
|
|
2154
|
+
if (ruleName3 in rules2) {
|
|
2155
|
+
const ruleConfig14 = rules2[ruleName3];
|
|
2156
|
+
if (Array.isArray(ruleConfig14)) {
|
|
2157
|
+
return ruleConfig14[0] === true;
|
|
2158
|
+
} else if (ruleConfig14 !== void 0 && ruleConfig14 !== null) {
|
|
2159
|
+
return true;
|
|
2160
|
+
} else if (ruleConfig14 === false) {
|
|
2161
|
+
return false;
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
} catch (error) {
|
|
2165
|
+
return false;
|
|
2166
|
+
}
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2126
2169
|
// src/rules/v9/no-hardcoded-values/noHardcodedValueRule.ts
|
|
2127
2170
|
function defineNoHardcodedValueRule(config) {
|
|
2128
|
-
const { ruleConfig: ruleConfig14 } = config;
|
|
2171
|
+
const { ruleConfig: ruleConfig14, ruleName: ruleName3 } = config;
|
|
2129
2172
|
const { type: type15, description: description15, url: url15, messages: messages15 } = ruleConfig14;
|
|
2130
2173
|
return {
|
|
2131
2174
|
meta: {
|
|
@@ -2139,6 +2182,9 @@ function defineNoHardcodedValueRule(config) {
|
|
|
2139
2182
|
messages: messages15
|
|
2140
2183
|
},
|
|
2141
2184
|
create(context) {
|
|
2185
|
+
if (ruleName3 === "no-hardcoded-values-slds1" && isRuleEnabled(context, "@salesforce-ux/slds/no-hardcoded-values-slds2")) {
|
|
2186
|
+
return {};
|
|
2187
|
+
}
|
|
2142
2188
|
const handlerContext = {
|
|
2143
2189
|
valueToStylinghook: config.valueToStylinghook,
|
|
2144
2190
|
context,
|
|
@@ -2194,36 +2240,38 @@ function defineNoHardcodedValueRule(config) {
|
|
|
2194
2240
|
}
|
|
2195
2241
|
|
|
2196
2242
|
// src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.ts
|
|
2197
|
-
var
|
|
2243
|
+
var ruleName = "no-hardcoded-values-slds1";
|
|
2244
|
+
var ruleConfig12 = import_rule_messages14.default[ruleName];
|
|
2198
2245
|
var { type: type13, description: description13, url: url13, messages: messages13 } = ruleConfig12;
|
|
2199
|
-
var valueToStylinghook =
|
|
2246
|
+
var valueToStylinghook = import_sds_metadata12.default.valueToStylingHooksSlds;
|
|
2200
2247
|
var no_hardcoded_values_slds1_default = defineNoHardcodedValueRule({
|
|
2201
2248
|
ruleConfig: ruleConfig12,
|
|
2202
|
-
valueToStylinghook
|
|
2249
|
+
valueToStylinghook,
|
|
2250
|
+
ruleName
|
|
2203
2251
|
});
|
|
2204
2252
|
|
|
2205
2253
|
// src/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.ts
|
|
2206
|
-
var
|
|
2254
|
+
var import_sds_metadata13 = __toESM(require("@salesforce-ux/sds-metadata"));
|
|
2207
2255
|
var import_rule_messages15 = __toESM(require_rule_messages());
|
|
2208
|
-
var
|
|
2256
|
+
var ruleName2 = "no-hardcoded-values-slds2";
|
|
2257
|
+
var ruleConfig13 = import_rule_messages15.default[ruleName2];
|
|
2209
2258
|
var { type: type14, description: description14, url: url14, messages: messages14 } = ruleConfig13;
|
|
2210
|
-
var valueToStylinghook2 =
|
|
2259
|
+
var valueToStylinghook2 = import_sds_metadata13.default.valueToStylingHooksCosmos;
|
|
2211
2260
|
var no_hardcoded_values_slds2_default = defineNoHardcodedValueRule({
|
|
2212
2261
|
ruleConfig: ruleConfig13,
|
|
2213
|
-
valueToStylinghook: valueToStylinghook2
|
|
2262
|
+
valueToStylinghook: valueToStylinghook2,
|
|
2263
|
+
ruleName: ruleName2
|
|
2214
2264
|
});
|
|
2215
2265
|
|
|
2216
2266
|
// src/index.ts
|
|
2217
2267
|
var import_parser2 = __toESM(require("@html-eslint/parser"));
|
|
2218
2268
|
var import_css = __toESM(require("@eslint/css"));
|
|
2219
2269
|
|
|
2220
|
-
// eslint.rules.
|
|
2221
|
-
var
|
|
2270
|
+
// eslint.rules.json
|
|
2271
|
+
var eslint_rules_default = {
|
|
2222
2272
|
css: {
|
|
2223
2273
|
"@salesforce-ux/slds/no-slds-class-overrides": "warn",
|
|
2224
2274
|
"@salesforce-ux/slds/no-deprecated-slds-classes": "warn",
|
|
2225
|
-
"@salesforce-ux/slds/no-deprecated-tokens-slds1": "error",
|
|
2226
|
-
"@salesforce-ux/slds/lwc-token-to-slds-hook": "error",
|
|
2227
2275
|
"@salesforce-ux/slds/enforce-sds-to-slds-hooks": "warn",
|
|
2228
2276
|
"@salesforce-ux/slds/no-sldshook-fallback-for-lwctoken": "warn",
|
|
2229
2277
|
"@salesforce-ux/slds/no-unsupported-hooks-slds2": "warn",
|
|
@@ -2231,7 +2279,6 @@ var eslint_rules_internal_default = {
|
|
|
2231
2279
|
"@salesforce-ux/slds/no-slds-namespace-for-custom-hooks": "warn",
|
|
2232
2280
|
"@salesforce-ux/slds/enforce-component-hook-naming-convention": "error",
|
|
2233
2281
|
"@salesforce-ux/slds/no-slds-private-var": "warn",
|
|
2234
|
-
"@salesforce-ux/slds/no-hardcoded-values-slds1": "error",
|
|
2235
2282
|
"@salesforce-ux/slds/no-hardcoded-values-slds2": "warn",
|
|
2236
2283
|
"@salesforce-ux/slds/reduce-annotations": "warn"
|
|
2237
2284
|
},
|
|
@@ -2265,47 +2312,56 @@ var rules = {
|
|
|
2265
2312
|
var plugin = {
|
|
2266
2313
|
meta: {
|
|
2267
2314
|
name: "@salesforce-ux/eslint-plugin-slds",
|
|
2268
|
-
version: "1.0.
|
|
2315
|
+
version: "1.0.1"
|
|
2269
2316
|
},
|
|
2270
2317
|
rules,
|
|
2271
2318
|
configs: {}
|
|
2272
2319
|
};
|
|
2273
|
-
|
|
2274
|
-
//
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
sourceType: "module"
|
|
2283
|
-
},
|
|
2284
|
-
plugins: {
|
|
2285
|
-
"@salesforce-ux/slds": plugin
|
|
2286
|
-
},
|
|
2287
|
-
rules: eslint_rules_internal_default.html
|
|
2320
|
+
var cssConfigArray = [
|
|
2321
|
+
// CSS config - Standard CSS files
|
|
2322
|
+
{
|
|
2323
|
+
files: ["**/*.{css,scss}"],
|
|
2324
|
+
language: "css/css",
|
|
2325
|
+
...import_css.default.configs.recommended,
|
|
2326
|
+
languageOptions: {
|
|
2327
|
+
tolerant: true
|
|
2328
|
+
// Allow recoverable parsing errors for SCSS syntax
|
|
2288
2329
|
},
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
},
|
|
2298
|
-
plugins: {
|
|
2299
|
-
css: import_css.default,
|
|
2300
|
-
"@salesforce-ux/slds": plugin
|
|
2301
|
-
},
|
|
2302
|
-
rules: eslint_rules_internal_default.css
|
|
2330
|
+
plugins: {
|
|
2331
|
+
css: import_css.default,
|
|
2332
|
+
"@salesforce-ux/slds": plugin
|
|
2333
|
+
},
|
|
2334
|
+
rules: eslint_rules_default.css,
|
|
2335
|
+
settings: {
|
|
2336
|
+
// Pass rules configuration to context for runtime access
|
|
2337
|
+
sldsRules: { ...eslint_rules_default.css }
|
|
2303
2338
|
}
|
|
2304
|
-
|
|
2339
|
+
}
|
|
2340
|
+
];
|
|
2341
|
+
var htmlConfigArray = [
|
|
2342
|
+
// HTML/Component config
|
|
2343
|
+
{
|
|
2344
|
+
files: ["**/*.html", "**/*.cmp"],
|
|
2345
|
+
languageOptions: {
|
|
2346
|
+
parser: import_parser2.default,
|
|
2347
|
+
ecmaVersion: 2021,
|
|
2348
|
+
sourceType: "module"
|
|
2349
|
+
},
|
|
2350
|
+
plugins: {
|
|
2351
|
+
"@salesforce-ux/slds": plugin
|
|
2352
|
+
},
|
|
2353
|
+
rules: eslint_rules_default.html
|
|
2354
|
+
}
|
|
2355
|
+
];
|
|
2356
|
+
Object.assign(plugin.configs, {
|
|
2357
|
+
// Flat config for ESLint v9+
|
|
2358
|
+
"flat/recommended-css": cssConfigArray,
|
|
2359
|
+
"flat/recommended-html": htmlConfigArray,
|
|
2360
|
+
"flat/recommended": [...cssConfigArray, ...htmlConfigArray],
|
|
2305
2361
|
// legacy config for ESLint v8-
|
|
2306
2362
|
recommended: {
|
|
2307
2363
|
plugins: ["@salesforce-ux/slds"],
|
|
2308
|
-
rules:
|
|
2364
|
+
rules: eslint_rules_default.html,
|
|
2309
2365
|
parser: import_parser2.default,
|
|
2310
2366
|
parserOptions: {
|
|
2311
2367
|
ecmaVersion: 2021,
|