@salesforce-ux/eslint-plugin-slds 1.0.6-internal → 1.0.7-internal
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -62
- package/build/index.js +128 -258
- package/build/index.js.map +4 -4
- package/build/rules/v9/lwc-token-to-slds-hook.js.map +2 -2
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js +30 -86
- package/build/rules/v9/no-hardcoded-values/handlers/boxShadowHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js +104 -116
- package/build/rules/v9/no-hardcoded-values/handlers/colorHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js +30 -83
- package/build/rules/v9/no-hardcoded-values/handlers/densityHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js +74 -78
- package/build/rules/v9/no-hardcoded-values/handlers/fontHandler.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/handlers/index.js +99 -175
- 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 +101 -221
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds1.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js +101 -221
- package/build/rules/v9/no-hardcoded-values/no-hardcoded-values-slds2.js.map +3 -3
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js +101 -221
- package/build/rules/v9/no-hardcoded-values/noHardcodedValueRule.js.map +3 -3
- package/build/rules/v9/no-slds-namespace-for-custom-hooks.js.map +2 -2
- package/build/rules/v9/no-slds-var-without-fallback.js.map +2 -2
- package/build/src/types/index.d.ts +0 -31
- package/build/src/utils/color-lib-utils.d.ts +9 -16
- package/build/src/utils/hardcoded-shared-utils.d.ts +0 -1
- package/build/src/utils/property-matcher.d.ts +1 -3
- package/build/types/index.js.map +1 -1
- package/build/utils/boxShadowValueParser.js.map +2 -2
- package/build/utils/color-lib-utils.js +50 -26
- package/build/utils/color-lib-utils.js.map +2 -2
- package/build/utils/css-utils.js.map +2 -2
- package/build/utils/hardcoded-shared-utils.js +16 -29
- package/build/utils/hardcoded-shared-utils.js.map +2 -2
- package/build/utils/property-matcher.js +6 -20
- package/build/utils/property-matcher.js.map +2 -2
- package/eslint.config.mjs +2 -5
- package/package.json +2 -2
- package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js +0 -63
- package/build/rules/v9/no-hardcoded-values/ruleOptionsSchema.js.map +0 -7
- package/build/src/rules/v9/no-hardcoded-values/ruleOptionsSchema.d.ts +0 -40
- package/build/src/utils/custom-mapping-utils.d.ts +0 -9
- package/build/utils/custom-mapping-utils.js +0 -62
- package/build/utils/custom-mapping-utils.js.map +0 -7
package/build/index.js
CHANGED
|
@@ -780,7 +780,11 @@ function isCssColorFunction(value) {
|
|
|
780
780
|
}
|
|
781
781
|
|
|
782
782
|
// src/utils/color-lib-utils.ts
|
|
783
|
-
var
|
|
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
|
+
};
|
|
784
788
|
var convertToHex = (color) => {
|
|
785
789
|
try {
|
|
786
790
|
return (0, import_chroma_js.default)(color).hex();
|
|
@@ -788,40 +792,52 @@ var convertToHex = (color) => {
|
|
|
788
792
|
return null;
|
|
789
793
|
}
|
|
790
794
|
};
|
|
791
|
-
var isHookPropertyMatch = (hook, cssProperty) => {
|
|
792
|
-
return hook.properties.includes(cssProperty) || hook.properties.includes("*");
|
|
793
|
-
};
|
|
794
|
-
function getOrderByCssProp(cssProperty) {
|
|
795
|
-
if (cssProperty === "color" || cssProperty === "fill") {
|
|
796
|
-
return ["surface", "theme", "feedback", "reference"];
|
|
797
|
-
} else if (cssProperty.match(/background/)) {
|
|
798
|
-
return ["surface", "surface-inverse", "theme", "feedback", "reference"];
|
|
799
|
-
} else if (cssProperty.match(/border/) || cssProperty.match(/outline/) || cssProperty.match(/stroke/)) {
|
|
800
|
-
return ["borders", "borders-inverse", "feedback", "theme", "reference"];
|
|
801
|
-
}
|
|
802
|
-
return ["surface", "surface-inverse", "borders", "borders-inverse", "theme", "feedback", "reference"];
|
|
803
|
-
}
|
|
804
795
|
var findClosestColorHook = (color, supportedColors, cssProperty) => {
|
|
805
|
-
const
|
|
796
|
+
const returnStylingHooks = [];
|
|
797
|
+
const closestHooksWithSameProperty = [];
|
|
798
|
+
const closestHooksWithoutSameProperty = [];
|
|
799
|
+
const closestHooksWithAllProperty = [];
|
|
800
|
+
const labColor = (0, import_chroma_js.default)(color).lab();
|
|
806
801
|
Object.entries(supportedColors).forEach(([sldsValue, data]) => {
|
|
807
|
-
if (sldsValue &&
|
|
802
|
+
if (sldsValue && isHexCode(sldsValue)) {
|
|
808
803
|
const hooks = data;
|
|
809
804
|
hooks.forEach((hook) => {
|
|
810
|
-
const
|
|
811
|
-
|
|
812
|
-
|
|
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 });
|
|
810
|
+
}
|
|
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 });
|
|
818
|
+
}
|
|
813
819
|
}
|
|
814
820
|
});
|
|
815
821
|
}
|
|
816
822
|
});
|
|
817
|
-
const
|
|
818
|
-
|
|
819
|
-
|
|
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));
|
|
820
838
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
}, {});
|
|
824
|
-
return getOrderByCssProp(cssProperty).map((group) => hooksByGroupMap[group] || []).flat().slice(0, 5);
|
|
839
|
+
}
|
|
840
|
+
return Array.from(new Set(returnStylingHooks));
|
|
825
841
|
};
|
|
826
842
|
var isValidColor = (val) => import_chroma_js.default.valid(val);
|
|
827
843
|
var extractColorValue = (node) => {
|
|
@@ -863,33 +879,13 @@ function isKnownFontWeight(value) {
|
|
|
863
879
|
return FONT_WEIGHTS.includes(stringValue.toLowerCase());
|
|
864
880
|
}
|
|
865
881
|
function handleShorthandAutoFix(declarationNode, context, valueText, replacements) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
const reportNumericValue = context.options?.reportNumericValue || "always";
|
|
871
|
-
const fixCallback = (start, originalValue, replacement) => {
|
|
872
|
-
let newValue = valueText;
|
|
873
|
-
newValue = newValue.substring(0, start) + replacement + newValue.substring(start + originalValue.length);
|
|
874
|
-
if (newValue !== valueText) {
|
|
875
|
-
return (fixer) => {
|
|
876
|
-
return fixer.replaceText(declarationNode.value, newValue);
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
sortedReplacements.forEach(({ start, end, replacement, displayValue, hasHook, isNumeric }) => {
|
|
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 }) => {
|
|
881
886
|
const originalValue = valueText.substring(start, end);
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
|
-
if (reportNumericValue === "hasReplacement" && !hasHook) {
|
|
887
|
-
return;
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
const valueColumnStart = declarationNode.value.loc.start.column + start;
|
|
891
|
-
const valueColumnEnd = valueColumnStart + originalValue.length;
|
|
892
|
-
const canAutoFix = originalValue !== replacement;
|
|
887
|
+
const valueStartColumn = declarationNode.value.loc.start.column;
|
|
888
|
+
const valueColumn = valueStartColumn + start;
|
|
893
889
|
const { loc: { start: locStart, end: locEnd } } = declarationNode.value;
|
|
894
890
|
const reportNode = {
|
|
895
891
|
...declarationNode.value,
|
|
@@ -897,16 +893,23 @@ function handleShorthandAutoFix(declarationNode, context, valueText, replacement
|
|
|
897
893
|
...declarationNode.value.loc,
|
|
898
894
|
start: {
|
|
899
895
|
...locStart,
|
|
900
|
-
column:
|
|
896
|
+
column: valueColumn
|
|
901
897
|
},
|
|
902
898
|
end: {
|
|
903
899
|
...locEnd,
|
|
904
|
-
column:
|
|
900
|
+
column: valueColumn + originalValue.length
|
|
905
901
|
}
|
|
906
902
|
}
|
|
907
903
|
};
|
|
908
904
|
if (hasHook) {
|
|
909
|
-
const fix = canAutoFix ?
|
|
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);
|
|
910
|
+
}
|
|
911
|
+
return fixer.replaceText(declarationNode.value, newValue);
|
|
912
|
+
} : void 0;
|
|
910
913
|
context.context.report({
|
|
911
914
|
node: reportNode,
|
|
912
915
|
messageId: "hardcodedValue",
|
|
@@ -1787,9 +1790,9 @@ function toSelector(properties) {
|
|
|
1787
1790
|
});
|
|
1788
1791
|
return selectorParts.join(", ");
|
|
1789
1792
|
}
|
|
1790
|
-
function
|
|
1793
|
+
function resolvePropertyToMatch(cssProperty) {
|
|
1791
1794
|
const propertyToMatch = cssProperty.toLowerCase();
|
|
1792
|
-
if (
|
|
1795
|
+
if (propertyToMatch === "outline" || propertyToMatch === "outline-width" || isBorderWidthProperty(propertyToMatch)) {
|
|
1793
1796
|
return "border-width";
|
|
1794
1797
|
} else if (isMarginProperty(propertyToMatch)) {
|
|
1795
1798
|
return "margin";
|
|
@@ -1801,58 +1804,13 @@ function resolveDensityPropertyToMatch(cssProperty) {
|
|
|
1801
1804
|
return "width";
|
|
1802
1805
|
} else if (isInsetProperty(propertyToMatch)) {
|
|
1803
1806
|
return "top";
|
|
1804
|
-
}
|
|
1805
|
-
return propertyToMatch;
|
|
1806
|
-
}
|
|
1807
|
-
function resolveColorPropertyToMatch(cssProperty) {
|
|
1808
|
-
const propertyToMatch = cssProperty.toLowerCase();
|
|
1809
|
-
if (propertyToMatch === "outline" || propertyToMatch === "outline-color") {
|
|
1810
|
-
return "border-color";
|
|
1811
|
-
} else if (propertyToMatch === "background" || propertyToMatch === "background-color") {
|
|
1807
|
+
} else if (cssProperty === "background" || cssProperty === "background-color") {
|
|
1812
1808
|
return "background-color";
|
|
1813
|
-
} else if (isBorderColorProperty(
|
|
1809
|
+
} else if (cssProperty === "outline" || cssProperty === "outline-color" || isBorderColorProperty(cssProperty)) {
|
|
1814
1810
|
return "border-color";
|
|
1815
1811
|
}
|
|
1816
1812
|
return propertyToMatch;
|
|
1817
1813
|
}
|
|
1818
|
-
function isOutlineWidthProperty(propertyToMatch) {
|
|
1819
|
-
return propertyToMatch === "outline" || propertyToMatch === "outline-width";
|
|
1820
|
-
}
|
|
1821
|
-
|
|
1822
|
-
// src/utils/custom-mapping-utils.ts
|
|
1823
|
-
function matchesPropertyPattern(cssProperty, pattern) {
|
|
1824
|
-
const normalizedProperty = cssProperty.toLowerCase();
|
|
1825
|
-
const normalizedPattern = pattern.toLowerCase();
|
|
1826
|
-
if (normalizedProperty === normalizedPattern) {
|
|
1827
|
-
return true;
|
|
1828
|
-
}
|
|
1829
|
-
if (normalizedPattern.endsWith("*")) {
|
|
1830
|
-
const prefix = normalizedPattern.slice(0, -1);
|
|
1831
|
-
return normalizedProperty.startsWith(prefix);
|
|
1832
|
-
}
|
|
1833
|
-
return false;
|
|
1834
|
-
}
|
|
1835
|
-
function getCustomMapping(cssProperty, value, customMapping) {
|
|
1836
|
-
if (!customMapping) {
|
|
1837
|
-
return null;
|
|
1838
|
-
}
|
|
1839
|
-
const normalizedValue = value.toLowerCase().trim();
|
|
1840
|
-
for (const [hookName, config] of Object.entries(customMapping)) {
|
|
1841
|
-
const propertyMatches = config.properties.some(
|
|
1842
|
-
(pattern) => matchesPropertyPattern(cssProperty, pattern)
|
|
1843
|
-
);
|
|
1844
|
-
if (!propertyMatches) {
|
|
1845
|
-
continue;
|
|
1846
|
-
}
|
|
1847
|
-
const valueMatches = config.values.some(
|
|
1848
|
-
(configValue) => configValue.toLowerCase().trim() === normalizedValue
|
|
1849
|
-
);
|
|
1850
|
-
if (valueMatches) {
|
|
1851
|
-
return hookName;
|
|
1852
|
-
}
|
|
1853
|
-
}
|
|
1854
|
-
return null;
|
|
1855
|
-
}
|
|
1856
1814
|
|
|
1857
1815
|
// src/rules/v9/no-hardcoded-values/handlers/colorHandler.ts
|
|
1858
1816
|
var handleColorDeclaration = (node, context) => {
|
|
@@ -1877,32 +1835,24 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
1877
1835
|
if (!hexValue) {
|
|
1878
1836
|
return null;
|
|
1879
1837
|
}
|
|
1838
|
+
const propToMatch = resolvePropertyToMatch(cssProperty);
|
|
1839
|
+
const closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);
|
|
1880
1840
|
const start = positionInfo.start.offset;
|
|
1881
1841
|
const end = positionInfo.end.offset;
|
|
1882
1842
|
const originalValue = originalValueText ? originalValueText.substring(start, end) : colorValue;
|
|
1883
|
-
|
|
1884
|
-
let closestHooks = [];
|
|
1885
|
-
if (customHook) {
|
|
1886
|
-
closestHooks = [customHook];
|
|
1887
|
-
} else {
|
|
1888
|
-
const propToMatch = resolveColorPropertyToMatch(cssProperty);
|
|
1889
|
-
closestHooks = findClosestColorHook(hexValue, context.valueToStylinghook, propToMatch);
|
|
1890
|
-
}
|
|
1891
|
-
let replacement = originalValue;
|
|
1892
|
-
let paletteHook = null;
|
|
1893
|
-
if (context.options?.preferPaletteHook && closestHooks.length > 1) {
|
|
1894
|
-
paletteHook = closestHooks.filter((hook) => hook.includes("-palette-"))[0];
|
|
1895
|
-
}
|
|
1896
|
-
if (paletteHook) {
|
|
1897
|
-
replacement = `var(${paletteHook}, ${colorValue})`;
|
|
1898
|
-
} else if (closestHooks.length === 1) {
|
|
1899
|
-
replacement = `var(${closestHooks[0]}, ${colorValue})`;
|
|
1900
|
-
}
|
|
1901
|
-
if (closestHooks.length > 0) {
|
|
1843
|
+
if (closestHooks.length === 1) {
|
|
1902
1844
|
return {
|
|
1903
1845
|
start,
|
|
1904
1846
|
end,
|
|
1905
|
-
replacement,
|
|
1847
|
+
replacement: `var(${closestHooks[0]}, ${colorValue})`,
|
|
1848
|
+
displayValue: closestHooks[0],
|
|
1849
|
+
hasHook: true
|
|
1850
|
+
};
|
|
1851
|
+
} else if (closestHooks.length > 1) {
|
|
1852
|
+
return {
|
|
1853
|
+
start,
|
|
1854
|
+
end,
|
|
1855
|
+
replacement: originalValue,
|
|
1906
1856
|
// Use original value to preserve spacing
|
|
1907
1857
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
1908
1858
|
hasHook: true
|
|
@@ -1911,7 +1861,7 @@ function createColorReplacement(colorValue, cssProperty, context, positionInfo,
|
|
|
1911
1861
|
return {
|
|
1912
1862
|
start,
|
|
1913
1863
|
end,
|
|
1914
|
-
replacement,
|
|
1864
|
+
replacement: originalValue,
|
|
1915
1865
|
// Use original value to preserve spacing
|
|
1916
1866
|
displayValue: originalValue,
|
|
1917
1867
|
hasHook: false
|
|
@@ -1959,14 +1909,8 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
1959
1909
|
return null;
|
|
1960
1910
|
}
|
|
1961
1911
|
const rawValue = parsedDimension.unit ? `${parsedDimension.number}${parsedDimension.unit}` : parsedDimension.number.toString();
|
|
1962
|
-
const
|
|
1963
|
-
|
|
1964
|
-
if (customHook) {
|
|
1965
|
-
closestHooks = [customHook];
|
|
1966
|
-
} else {
|
|
1967
|
-
const propToMatch = resolveDensityPropertyToMatch(cssProperty);
|
|
1968
|
-
closestHooks = getStylingHooksForDensityValue(parsedDimension, context.valueToStylinghook, propToMatch);
|
|
1969
|
-
}
|
|
1912
|
+
const propToMatch = resolvePropertyToMatch(cssProperty);
|
|
1913
|
+
const closestHooks = getStylingHooksForDensityValue(parsedDimension, context.valueToStylinghook, propToMatch);
|
|
1970
1914
|
const start = positionInfo.start.offset;
|
|
1971
1915
|
const end = positionInfo.end.offset;
|
|
1972
1916
|
if (closestHooks.length === 1) {
|
|
@@ -1975,8 +1919,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
1975
1919
|
end,
|
|
1976
1920
|
replacement: `var(${closestHooks[0]}, ${rawValue})`,
|
|
1977
1921
|
displayValue: closestHooks[0],
|
|
1978
|
-
hasHook: true
|
|
1979
|
-
isNumeric: true
|
|
1922
|
+
hasHook: true
|
|
1980
1923
|
};
|
|
1981
1924
|
} else if (closestHooks.length > 1) {
|
|
1982
1925
|
return {
|
|
@@ -1984,8 +1927,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
1984
1927
|
end,
|
|
1985
1928
|
replacement: rawValue,
|
|
1986
1929
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
1987
|
-
hasHook: true
|
|
1988
|
-
isNumeric: true
|
|
1930
|
+
hasHook: true
|
|
1989
1931
|
};
|
|
1990
1932
|
} else {
|
|
1991
1933
|
return {
|
|
@@ -1993,8 +1935,7 @@ function createDimensionReplacement(parsedDimension, cssProperty, context, posit
|
|
|
1993
1935
|
end,
|
|
1994
1936
|
replacement: rawValue,
|
|
1995
1937
|
displayValue: rawValue,
|
|
1996
|
-
hasHook: false
|
|
1997
|
-
isNumeric: true
|
|
1938
|
+
hasHook: false
|
|
1998
1939
|
};
|
|
1999
1940
|
}
|
|
2000
1941
|
}
|
|
@@ -2035,14 +1976,8 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
2035
1976
|
return null;
|
|
2036
1977
|
}
|
|
2037
1978
|
const rawValue = fontValue.unit ? `${fontValue.number}${fontValue.unit}` : fontValue.number.toString();
|
|
2038
|
-
const propToMatch = !fontValue.unit && isKnownFontWeight(fontValue.number) ? "font-weight" : "font-size";
|
|
2039
|
-
const
|
|
2040
|
-
let closestHooks = [];
|
|
2041
|
-
if (customHook) {
|
|
2042
|
-
closestHooks = [customHook];
|
|
2043
|
-
} else {
|
|
2044
|
-
closestHooks = getStylingHooksForDensityValue(fontValue, context.valueToStylinghook, propToMatch);
|
|
2045
|
-
}
|
|
1979
|
+
const propToMatch = !fontValue.unit && isKnownFontWeight(fontValue.number) ? resolvePropertyToMatch("font-weight") : resolvePropertyToMatch("font-size");
|
|
1980
|
+
const closestHooks = getStylingHooksForDensityValue(fontValue, context.valueToStylinghook, propToMatch);
|
|
2046
1981
|
const start = positionInfo.start.offset;
|
|
2047
1982
|
const end = positionInfo.end.offset;
|
|
2048
1983
|
if (closestHooks.length === 1) {
|
|
@@ -2051,8 +1986,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
2051
1986
|
end,
|
|
2052
1987
|
replacement: `var(${closestHooks[0]}, ${rawValue})`,
|
|
2053
1988
|
displayValue: closestHooks[0],
|
|
2054
|
-
hasHook: true
|
|
2055
|
-
isNumeric: true
|
|
1989
|
+
hasHook: true
|
|
2056
1990
|
};
|
|
2057
1991
|
} else if (closestHooks.length > 1) {
|
|
2058
1992
|
return {
|
|
@@ -2060,8 +1994,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
2060
1994
|
end,
|
|
2061
1995
|
replacement: rawValue,
|
|
2062
1996
|
displayValue: formatSuggestionHooks(closestHooks),
|
|
2063
|
-
hasHook: true
|
|
2064
|
-
isNumeric: true
|
|
1997
|
+
hasHook: true
|
|
2065
1998
|
};
|
|
2066
1999
|
} else {
|
|
2067
2000
|
return {
|
|
@@ -2069,8 +2002,7 @@ function createFontReplacement(fontValue, cssProperty, context, positionInfo) {
|
|
|
2069
2002
|
end,
|
|
2070
2003
|
replacement: rawValue,
|
|
2071
2004
|
displayValue: rawValue,
|
|
2072
|
-
hasHook: false
|
|
2073
|
-
isNumeric: true
|
|
2005
|
+
hasHook: false
|
|
2074
2006
|
};
|
|
2075
2007
|
}
|
|
2076
2008
|
}
|
|
@@ -2202,30 +2134,9 @@ function shadowValueToHookEntries(supportedStylinghooks) {
|
|
|
2202
2134
|
return [key, value.map((hook) => hook.name)];
|
|
2203
2135
|
});
|
|
2204
2136
|
}
|
|
2205
|
-
function reportBoxShadowViolation(node, context, valueText, hooks) {
|
|
2206
|
-
const positionInfo = {
|
|
2207
|
-
start: { offset: 0, line: 1, column: 1 },
|
|
2208
|
-
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
2209
|
-
};
|
|
2210
|
-
const replacement = createBoxShadowReplacement(
|
|
2211
|
-
valueText,
|
|
2212
|
-
hooks,
|
|
2213
|
-
context,
|
|
2214
|
-
positionInfo
|
|
2215
|
-
);
|
|
2216
|
-
if (replacement) {
|
|
2217
|
-
const replacements = [replacement];
|
|
2218
|
-
handleShorthandAutoFix(node, context, valueText, replacements);
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
2137
|
var handleBoxShadowDeclaration = (node, context) => {
|
|
2222
2138
|
const cssProperty = node.property.toLowerCase();
|
|
2223
2139
|
const valueText = context.sourceCode.getText(node.value);
|
|
2224
|
-
const customHook = getCustomMapping(cssProperty, valueText, context.options?.customMapping);
|
|
2225
|
-
if (customHook) {
|
|
2226
|
-
reportBoxShadowViolation(node, context, valueText, [customHook]);
|
|
2227
|
-
return;
|
|
2228
|
-
}
|
|
2229
2140
|
const shadowHooks = shadowValueToHookEntries(context.valueToStylinghook);
|
|
2230
2141
|
const parsedCssValue = toBoxShadowValue(valueText);
|
|
2231
2142
|
if (!parsedCssValue) {
|
|
@@ -2235,7 +2146,20 @@ var handleBoxShadowDeclaration = (node, context) => {
|
|
|
2235
2146
|
const parsedValueHook = toBoxShadowValue(shadow);
|
|
2236
2147
|
if (parsedValueHook && isBoxShadowMatch(parsedCssValue, parsedValueHook)) {
|
|
2237
2148
|
if (closestHooks.length > 0) {
|
|
2238
|
-
|
|
2149
|
+
const positionInfo = {
|
|
2150
|
+
start: { offset: 0, line: 1, column: 1 },
|
|
2151
|
+
end: { offset: valueText.length, line: 1, column: valueText.length + 1 }
|
|
2152
|
+
};
|
|
2153
|
+
const replacement = createBoxShadowReplacement(
|
|
2154
|
+
valueText,
|
|
2155
|
+
closestHooks,
|
|
2156
|
+
context,
|
|
2157
|
+
positionInfo
|
|
2158
|
+
);
|
|
2159
|
+
if (replacement) {
|
|
2160
|
+
const replacements = [replacement];
|
|
2161
|
+
handleShorthandAutoFix(node, context, valueText, replacements);
|
|
2162
|
+
}
|
|
2239
2163
|
}
|
|
2240
2164
|
return;
|
|
2241
2165
|
}
|
|
@@ -2285,42 +2209,6 @@ function isRuleEnabled(context, ruleName3) {
|
|
|
2285
2209
|
}
|
|
2286
2210
|
}
|
|
2287
2211
|
|
|
2288
|
-
// src/rules/v9/no-hardcoded-values/ruleOptionsSchema.ts
|
|
2289
|
-
var ruleOptionsSchema = [
|
|
2290
|
-
{
|
|
2291
|
-
type: "object",
|
|
2292
|
-
properties: {
|
|
2293
|
-
reportNumericValue: {
|
|
2294
|
-
type: "string",
|
|
2295
|
-
enum: ["never", "always", "hasReplacement"],
|
|
2296
|
-
default: "always"
|
|
2297
|
-
},
|
|
2298
|
-
customMapping: {
|
|
2299
|
-
type: "object",
|
|
2300
|
-
additionalProperties: {
|
|
2301
|
-
type: "object",
|
|
2302
|
-
properties: {
|
|
2303
|
-
properties: {
|
|
2304
|
-
type: "array",
|
|
2305
|
-
items: { type: "string" }
|
|
2306
|
-
},
|
|
2307
|
-
values: {
|
|
2308
|
-
type: "array",
|
|
2309
|
-
items: { type: "string" }
|
|
2310
|
-
}
|
|
2311
|
-
},
|
|
2312
|
-
required: ["properties", "values"]
|
|
2313
|
-
}
|
|
2314
|
-
},
|
|
2315
|
-
preferPaletteHook: {
|
|
2316
|
-
type: "boolean",
|
|
2317
|
-
default: false
|
|
2318
|
-
}
|
|
2319
|
-
},
|
|
2320
|
-
additionalProperties: false
|
|
2321
|
-
}
|
|
2322
|
-
];
|
|
2323
|
-
|
|
2324
2212
|
// src/rules/v9/no-hardcoded-values/noHardcodedValueRule.ts
|
|
2325
2213
|
function defineNoHardcodedValueRule(config) {
|
|
2326
2214
|
const { ruleConfig: ruleConfig14, ruleName: ruleName3 } = config;
|
|
@@ -2334,24 +2222,16 @@ function defineNoHardcodedValueRule(config) {
|
|
|
2334
2222
|
url: url15
|
|
2335
2223
|
},
|
|
2336
2224
|
fixable: "code",
|
|
2337
|
-
messages: messages15
|
|
2338
|
-
schema: ruleOptionsSchema
|
|
2225
|
+
messages: messages15
|
|
2339
2226
|
},
|
|
2340
2227
|
create(context) {
|
|
2341
2228
|
if (ruleName3 === "no-hardcoded-values-slds1" && isRuleEnabled(context, "@salesforce-ux/slds/no-hardcoded-values-slds2")) {
|
|
2342
2229
|
return {};
|
|
2343
2230
|
}
|
|
2344
|
-
const options = context.options[0] || {};
|
|
2345
|
-
const ruleOptions = {
|
|
2346
|
-
reportNumericValue: options.reportNumericValue || "always",
|
|
2347
|
-
customMapping: options.customMapping || {},
|
|
2348
|
-
preferPaletteHook: options.preferPaletteHook || false
|
|
2349
|
-
};
|
|
2350
2231
|
const handlerContext = {
|
|
2351
2232
|
valueToStylinghook: config.valueToStylinghook,
|
|
2352
2233
|
context,
|
|
2353
|
-
sourceCode: context.sourceCode
|
|
2354
|
-
options: ruleOptions
|
|
2234
|
+
sourceCode: context.sourceCode
|
|
2355
2235
|
};
|
|
2356
2236
|
const colorOnlySelector = toSelector(colorProperties);
|
|
2357
2237
|
const densityOnlySelector = toSelector(densificationProperties);
|
|
@@ -2428,6 +2308,7 @@ var no_hardcoded_values_slds2_default = defineNoHardcodedValueRule({
|
|
|
2428
2308
|
|
|
2429
2309
|
// src/index.ts
|
|
2430
2310
|
var import_parser2 = __toESM(require("@html-eslint/parser"));
|
|
2311
|
+
var import_css = __toESM(require("@eslint/css"));
|
|
2431
2312
|
|
|
2432
2313
|
// eslint.rules.internal.json
|
|
2433
2314
|
var eslint_rules_internal_default = {
|
|
@@ -2444,24 +2325,8 @@ var eslint_rules_internal_default = {
|
|
|
2444
2325
|
"@salesforce-ux/slds/no-slds-namespace-for-custom-hooks": "warn",
|
|
2445
2326
|
"@salesforce-ux/slds/enforce-component-hook-naming-convention": "error",
|
|
2446
2327
|
"@salesforce-ux/slds/no-slds-private-var": "warn",
|
|
2447
|
-
"@salesforce-ux/slds/no-hardcoded-values-
|
|
2448
|
-
|
|
2449
|
-
preferPaletteHook: true,
|
|
2450
|
-
customMapping: {
|
|
2451
|
-
"--slds-g-font-line-height-4": {
|
|
2452
|
-
properties: ["line-height"],
|
|
2453
|
-
values: ["1.5"]
|
|
2454
|
-
},
|
|
2455
|
-
"--slds-g-sizing-5": {
|
|
2456
|
-
properties: ["width", "height", "max-width", "max-height", "border*"],
|
|
2457
|
-
values: ["1rem", "16px"]
|
|
2458
|
-
},
|
|
2459
|
-
"--slds-g-sizing-content-1": {
|
|
2460
|
-
properties: ["width", "height", "max-width", "max-height", "border*"],
|
|
2461
|
-
values: ["20ch"]
|
|
2462
|
-
}
|
|
2463
|
-
}
|
|
2464
|
-
}],
|
|
2328
|
+
"@salesforce-ux/slds/no-hardcoded-values-slds1": "error",
|
|
2329
|
+
"@salesforce-ux/slds/no-hardcoded-values-slds2": "warn",
|
|
2465
2330
|
"@salesforce-ux/slds/reduce-annotations": "warn"
|
|
2466
2331
|
},
|
|
2467
2332
|
html: {
|
|
@@ -2494,30 +2359,29 @@ var rules = {
|
|
|
2494
2359
|
var plugin = {
|
|
2495
2360
|
meta: {
|
|
2496
2361
|
name: "@salesforce-ux/eslint-plugin-slds",
|
|
2497
|
-
version: "1.0.
|
|
2362
|
+
version: "1.0.7-internal"
|
|
2498
2363
|
},
|
|
2499
2364
|
rules,
|
|
2500
2365
|
configs: {}
|
|
2501
2366
|
};
|
|
2502
|
-
var
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
sldsRules: { ...eslint_rules_internal_default.css }
|
|
2518
|
-
}
|
|
2367
|
+
var baseCssConfigWithPlugin = {
|
|
2368
|
+
files: ["**/*.{css,scss}"],
|
|
2369
|
+
language: "css/css",
|
|
2370
|
+
languageOptions: {
|
|
2371
|
+
tolerant: true
|
|
2372
|
+
// Allow recoverable parsing errors for SCSS syntax
|
|
2373
|
+
},
|
|
2374
|
+
plugins: {
|
|
2375
|
+
css: import_css.default,
|
|
2376
|
+
"@salesforce-ux/slds": plugin
|
|
2377
|
+
},
|
|
2378
|
+
rules: eslint_rules_internal_default.css,
|
|
2379
|
+
settings: {
|
|
2380
|
+
// Pass rules configuration to context for runtime access
|
|
2381
|
+
sldsRules: { ...eslint_rules_internal_default.css }
|
|
2519
2382
|
}
|
|
2520
|
-
|
|
2383
|
+
};
|
|
2384
|
+
var cssConfigArray = [baseCssConfigWithPlugin];
|
|
2521
2385
|
var htmlConfigArray = [
|
|
2522
2386
|
// HTML/Component config
|
|
2523
2387
|
{
|
|
@@ -2549,5 +2413,11 @@ Object.assign(plugin.configs, {
|
|
|
2549
2413
|
}
|
|
2550
2414
|
}
|
|
2551
2415
|
});
|
|
2416
|
+
function sldsCssPlugin() {
|
|
2417
|
+
return {
|
|
2418
|
+
...baseCssConfigWithPlugin.plugins
|
|
2419
|
+
};
|
|
2420
|
+
}
|
|
2552
2421
|
module.exports = plugin;
|
|
2422
|
+
module.exports.sldsCssPlugin = sldsCssPlugin;
|
|
2553
2423
|
//# sourceMappingURL=index.js.map
|