@salesforce-ux/eslint-plugin-slds
Version:
ESLint plugin provides custom linting rules specifically built for Salesforce Lightning Design System 2 (SLDS 2 beta)
58 lines (57 loc) • 2.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
const node_1 = require("./utils/node");
const sds_metadata_1 = __importDefault(require("@salesforce-ux/sds-metadata"));
const deprecatedClasses = sds_metadata_1.default.deprecatedClasses;
module.exports = {
meta: {
type: "problem", // The rule type
docs: {
category: "Best Practices",
recommended: true,
description: "Replace classes that aren’t available with SLDS 2 classes. See lightningdesignsystem.com for more info.",
url: "https://developer.salesforce.com/docs/platform/slds-linter/guide/reference-rules.html#no-deprecated-classes-slds2"
},
schema: [], // No additional options needed
},
create(context) {
function check(node) {
if ((0, node_1.isAttributesEmpty)(node)) {
return;
}
const classAttr = (0, node_1.findAttr)(node, "class");
if (classAttr && classAttr.value) {
const classNames = classAttr.value.value.split(/\s+/);
classNames.forEach((className) => {
if (className && deprecatedClasses.includes(className)) {
// Find the exact location of the problematic class name
const classNameStart = classAttr.value.value.indexOf(className) + 7; // 7 here is for `class= "`
const classNameEnd = classNameStart + className.length;
// Use the loc property to get line and column from the class attribute
const startLoc = {
line: classAttr.loc.start.line,
column: classAttr.loc.start.column + classNameStart,
};
const endLoc = {
line: classAttr.loc.start.line,
column: classAttr.loc.start.column + classNameEnd,
};
context.report({
node,
loc: { start: startLoc, end: endLoc },
data: {
className,
},
message: "The class {{className}} isn't available in SLDS 2. Update it to a class supported in SLDS 2. See lightningdesignsystem.com for more information.",
});
}
});
}
}
return {
Tag: check,
};
},
};