Use SLDS Linter with Custom Configuration Files
You can enable or disable the rules used by SLDS Linter. To do so, use the emit command to generate custom configuration files and edit them to disable the rules that you don’t want to run. Then, use the edited files to run SLDS Linter and generate reports.
(Optional) Install Recommended Extensions
To enhance your linting and error analysis experience while using custom configuration files, we recommend that you install this additional extension.
By default, the linting issues present in the code aren’t highlighted in the custom configuration files. Installing this extension makes it easier to locate these issues, as they’re highlighted with squiggly lines.
ESLint extension: Applicable for linting HTML, Component (CMP), and Cascading Style Sheet (CSS) files. The ESLint extension checks your code and highlights any violations of the ESLint rules with squiggly lines.
Set Up Custom Configuration Files
Follow these steps to set up your custom configuration files.
1. Export custom configuration files
To export the ESLint configuration file used by the SLDS Linter Command Line Interface (CLI), run the emit command.
npx @salesforce-ux/slds-linter@latest emitThis command creates or overwrites the existing .eslint.config.mjs file at the root of your project directory.
2. (Optional) Configure additional plug-ins
To use ESLint along with other plug-ins, modify the default configuration in the .eslint.config.mjs file. Import each additional plug-in that you want to use and edit the extends property to load the plug-in’s configuration.
For example, to use the CSS plug-in, add the CSS plug-in configuration to the .eslint.config.mjs file.
Before Example
This shows the .eslint.config.mjs file containing the default configuration that is emitted.
// eslint.config.mjs
import { defineConfig } from "eslint/config";
import { sldsCssPlugin } from"@salesforce-ux/eslint-plugin-slds";
export default defineConfig([
{
plugins: {
...sldsCssPlugin()
},
extends: ["@salesforce-ux/slds/recommended"] ....
},
]);After Example
This shows the .eslint.config.mjs file with the CSS plug-in configuration included.
// eslint.config.mjs
import { defineConfig } from 'eslint/config';
import css from '@eslint/css';
import { sldsCssPlugin }
from '@salesforce-ux/eslint-plugin-slds';
export default defineConfig([
{
// Define the plug-ins you are using
plugins: {
css: css,
...sldsCssPlugin()
}
// Extend plug-in configurations
extends: ["@salesforce-ux/slds/recommended", "css/recommended"]
}
]);3. Disable rules
To disable specific rules in the .eslint.config.mjs file, comment the rule entry by using //.
Before Example
"@salesforce-ux/slds/enforce-bem-class": "error"
"@salesforce-ux/slds/no-deprecated-classes-slds2": "error"
"@salesforce-ux/slds/modal-close-button-issue": "error"After Example
// "@salesforce-ux/slds/enforce-bem-class": "error"
// "@salesforce-ux/slds/no-deprecated-classes-slds2": "error"
"@salesforce-ux/slds/modal-close-button-issue": "error"4. Lint your code
To lint your code based on the modified custom configuration file, use the lint command with this argument.
--config-eslint
Supplies the .eslint.config.mjs file.
Example
Lint HTML and CMP files based on a ESLint configuration file.
npx @salesforce-ux/slds-linter@latest lint "**/{aura,lwc}/**/*.{html,cmp}" --config-eslint .eslint.config.mjs5. Generate reports
To generate reports containing all the lint issues, use the report command with the --format option.
Example
Generate a SARIF report.
npx @salesforce-ux/slds-linter@latest report --config-eslint .eslint.config.mjs --format sarifGenerate a CSV report.
npx @salesforce-ux/slds-linter@latest report --config-eslint .eslint.config.mjs --format csv