Align @10up/stylelint-config with 10up CSS Engineering Best Practices#468
Align @10up/stylelint-config with 10up CSS Engineering Best Practices#468fabiankaegy wants to merge 14 commits intodevelopfrom
@10up/stylelint-config with 10up CSS Engineering Best Practices#468Conversation
Disallows the use of !important in CSS declarations to maintain better CSS maintainability and reduce specificity issues. Aligns with 10up CSS best practices.
Enforces kebab-case naming for CSS animation keyframes to maintain consistent naming conventions across the codebase. Aligns with 10up CSS best practices.
Limits CSS nesting to a maximum of 2 levels (excluding pseudo-classes) to maintain low specificity and improve code readability. Aligns with 10up CSS best practices.
Prevents CSS specificity issues where a less specific selector comes after a more specific one, which can cause unexpected behavior. Aligns with 10up CSS best practices.
Enforces kebab-case naming for CSS class selectors to maintain consistent and readable naming conventions. Aligns with 10up CSS best practices.
Disallows ID selectors in CSS. IDs should be reserved for JavaScript hooks and anchor links, not for styling purposes. Aligns with 10up CSS best practices.
Limits selector specificity to a maximum of 0,2,1 (0 IDs, 2 classes/ attributes, 1 element) to maintain low specificity and improve CSS maintainability. Aligns with 10up CSS best practices.
Prevents qualifying class selectors with type selectors (e.g. a.button should be .button) to reduce specificity and improve selector efficiency. Attribute selectors are excluded from this rule. Aligns with 10up CSS best practices.
Ensures shorthand properties don't contain redundant values (e.g. margin: 10px 10px should be margin: 10px) to write more efficient CSS. Aligns with 10up CSS best practices.
Adds test cases covering all newly added rules: - Specificity limits (selector-max-specificity, selector-max-id, max-nesting-depth) - Importance rules (declaration-no-important, no-descending-specificity) - Naming conventions (selector-class-pattern, keyframes-name-pattern) - Selector quality (selector-no-qualifying-type, shorthand-property-no-redundant-values) Tests verify both valid and invalid CSS patterns to ensure rules are properly enforced.
Adds comprehensive documentation explaining how the stylelint configuration enforces 10up CSS best practices including: - Low specificity enforcement - Avoiding !important - Naming conventions (kebab-case) - Selector quality rules - How to override rules when necessary Provides clear explanations and examples for each enforced principle to help developers understand the reasoning behind the rules.
🦋 Changeset detectedLatest commit: c51c6df The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@10up/stylelint-config with 10up CSS Engineering Best Practices
dmtrmrv
left a comment
There was a problem hiding this comment.
This looks good to me! I assume that this will create some noise in existing projects but if need be the rules can be silenced.
|
(I will take a look at the tests and then we will talk about releasing strategy in the next few days / week since we are transitioning who is owning maintenance of toolkit :)) |
|
@fabiankaegy, just noting that this is still using classic tokens, and I created one recently, but they expire in 90 days. I will need to change the publishing strategy soon to avoid this issue. |
Updates test cases to use valid CSS that complies with all stylelint rules while still testing the specific rules we want to validate. Uses CSS custom properties to avoid color value violations and proper formatting to avoid stylistic rule violations.
Description
This PR updates the
@10up/stylelint-configpackage to fully enforce the 10up CSS Engineering Best Practices. The configuration now includes rules that enforce low specificity, consistent naming conventions, and code quality standards.Changes
New Rules Added
Specificity Controls:
selector-max-specificity: "0,2,1"- Limits selector specificity to maintain low complexityselector-max-id: 0- Disallows ID selectors for styling (IDs reserved for JS hooks and anchors)max-nesting-depth: 2- Limits CSS nesting to 2 levels (pseudo-classes excluded)no-descending-specificity: true- Re-enabled to prevent specificity ordering issuesCode Quality:
declaration-no-important: true- Disallows!importantdeclarationsselector-no-qualifying-type: true- Prevents type selectors qualifying class selectors (e.g.,a.button)shorthand-property-no-redundant-values: true- Ensures efficient shorthand property usageNaming Conventions:
selector-class-pattern- Enabled to enforce kebab-case for class nameskeyframes-name-pattern- Added to enforce kebab-case for animation namesAdditional Changes
Breaking Changes
Projects using this configuration may need to update existing CSS to comply with:
!importantdeclarations are disallowedMigration Guide
Projects can override specific rules if needed: