Rules
SLDS Linter rules validate your code against a series of SLDS 2 best practices and, where possible, provide suggestions for you to improve your code. By default, all rules validate all CSS properties unless otherwise specified. Each rule has a different severity level. The options are listed here.
- Error - The code won’t work and causes issues. Fix the errors.
- Warning - The code works, but it can be deprecated. We recommend addressing it.
This table lists all supported rules, their severity levels, and whether they are enabled by default.
Rule | Severity Level | Enabled by Default |
---|---|---|
enforce-bem-usage | Error | Yes |
modal-close-button-issue | Error | Yes |
no-deprecated-classes-slds2 | Error | Yes |
enforce-component-hook-naming-convention | Error | Yes |
enforce-sds-to-slds-hooks | Warning | Yes |
no-hardcoded-values-slds2 | Warning | Yes |
no-slds-class-overrides | Warning | Yes |
no-slds-private-var | Warning | Yes |
no-unsupported-hooks-slds2 | Warning | Yes |
no-slds-var-without-fallback | Warning | Yes |
reduce-annotations | Warning | Yes |
no-slds-namespace-for-custom-hooks | Warning | Yes |
no-sldshook-fallback-for-lwctoken | Warning | Yes |
no-important-tag | Warning | No |
Identifies instances that use the double-dash (--
) syntax for block-element-modifier (BEM) in classes. Replace these instances with the single underscore (_
) syntax.
Error
Existing code:
Recommended code:
The --
syntax is replaced with the _
syntax.
Identifies instances where the CSS classes or component attributes for the modal close button must be changed to follow the modal component blueprint.
- Remove classes that contain the
slds-button_icon-inverse
attribute within the close button. - Change the variant value for the
lightning-button-icon
attribute from bare-inverse to bare. - Change the variant value for the
lightning-icon
attribute from bare-inverse to bare.
For more information, see the Modal close button is not visible with the new white background topic.
Error
Existing code:
Recommended code:
To fix the issues, these changes are made.
- The variant attribute value for the
lightning-button-icon
attribute is changed from bare-inverse to bare. - The
slds-button–icon-inverse
class is removed.
Identifies classes that aren’t available in SLDS 2. Update these classes to a class that’s supported in SLDS 2.
Error
Existing code:
The slds-icon_left
class is deprecated in SLDS 2 and must be updated to a class that is supported in SLDS 2.
Identifies --slds-c
component-level styling hooks that use a deprecated naming convention. To align with the prescribed styling hooks naming convention, replace with styling hooks that SLDS Linter recommends.
Error
Existing code:
Recommended code:
The --slds-c-breadcrumbs-spacing-inlineend
styling hook is replaced with the --slds-c-breadcrumbs-spacing-inline-end
styling hook.
Existing code:
Recommended code:
The --slds-c-accordion-heading-color
and --slds-c-accordion-heading-font-lineheight
styling hooks are replaced with the --slds-c-accordion-heading-text-color
and --slds-c-accordion-heading-font-line-height
styling hooks.
Identifies Salesforce Design System (SDS) styling hooks that must be replaced with the suggested SLDS 2 styling hooks.
Warning
Existing code:
Recommended code:
The --sds-g-color-brand-base-100
styling hook is replaced with the --slds-g-color-brand-base-100
SLDS 2 styling hook.
Identifies static or hard-coded values that must be replaced with SLDS 2 styling hooks. Include the SLDS 2 styling hook and retain the hard-coded value as the fallback value. This rule validates only these CSS properties.
- color
- fill
- background
- background-color
- stroke
- border*-color
- outline*
- border*
- margin*
- padding*
- width
- height
- max-height
- min-height
- line-height
- max-width
- min-width
- top
- right
- left
- bottom
- box-shadow
- font
- font-weight
Warning
Existing code:
Recommended code:
The --slds-g-sizing-9
styling hook is included.
Identifies existing class names that must be replaced with new custom CSS classes, instead of overriding SLDS selectors. This rule only reports classes located at the end of an SLDS selector.
Warning
Here, the .slds-box_border
SLDS class is located at the end of the selector. Only such instances are identified as an issue.
Here, overriding the .slds-box_border
class isn’t supported. So a new my-app-box_border
CSS class is created to replace it.
Existing code:
Recommended code:
Identifies SLDS styling hooks that are reserved only for internal Salesforce use. You must remove these styling hooks.
Warning
Existing code:
Recommended code:
The --_slds-deprecated-var
styling hook is meant for internal Salesforce use and is removed.
Identifies styling hooks that aren’t present in SLDS 2. They must be replaced with styling hooks that have a similar effect, or they must be removed.
Warning
Existing code:
Recommended code:
The –-slds-c-card-body-spacing-block-end
styling hook is removed because it doesn’t have a suitable SLDS 2 replacement.
Identifies SLDS styling hooks that are specified without fallback values and recommends suitable fallback values based on the SLDS metadata.
Each var()
function’s arguments must contain a styling hook and a hard-coded value or branded design token as a fallback value. The fallback value is used in environments in which styling hooks aren’t supported.
Error
Existing code:
Recommended code:
The --slds-g-link-color-focus, --slds-g-color-brand-base-20,
and --slds-c-card-spacing-block
styling hooks are used with hard-coded values as fallback values.
Identifies annotations that must be removed from the code.
Warning
Existing code:
The @sldsValidatorAllow
annotation must be removed.
Identifies custom styling hooks that use the --slds
or --sds
namespaces, which are reserved for SLDS styling hooks. To differentiate them from SLDS styling hooks, create the identified custom styling hooks within your own namespace.
Warning
Existing code:
Recommended code:
The --slds-color-999
custom styling hook is replaced with --myapp-color-999
.
Identifies instances where --slds
styling hooks are provided as fallback values for --lwc
tokens. Replace the --lwc
token with a suitable --slds
styling hook and retain the --lwc
token as the fallback value.
Warning
Existing code:
Recommended code:
The --lwc-color-background-1
token is replaced with the --slds-g-color-border-1
styling hook. The --lwc
token is mentioned as the fallback value.
Indicates that the !important
tag must be used only if it’s necessary. The tag functions by overriding all other attributes.
Warning
Existing code:
Recommended code:
The !important
tag is removed.