feat(mint): add CSS Cascade Layers @layer structure audit - #111
Draft
nujovich wants to merge 5 commits into
Draft
Conversation
Owner
Author
|
All milestones complete. Ready for review when you are. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Card: https://github.com/nujovich/mint-radar/issues/21
What: Adds a static lint rule that detects CSS Cascade Layers (
@layer) structure. Milestone 1 introduced theCascadeLayerAudittype inlib/types.tswith layer names, declaration order, and rules-outside-layers detection, plus thelintCascadeLayers()function inlib/css-lint-rules.mjsthat scans CSS source for@layerstatements,@layerblock declarations, and identifies style rules not enclosed in any layer (unlayered styles). Milestone 2 extends the parser to group rules by layer and detect two anti-patterns:!importantinside layers and post-layer specificity. Milestone 3 adds a layer hierarchy visualization to the CLIlintoutput, with warnings when layer order is implicit rather than explicitly declared.Why: CSS Cascade Layers (
@layer) is Baseline since 2023 but no existing CLI tool audits layer ordering, detects rules outside layers, or surfaces unlayered style conflicts. Rules outside@layertake precedence over ALL layers, making them an anti-pattern in layered architectures. Mint can fill this gap with deterministic static analysis.Milestones
CascadeLayerAudittype system with detection of layer names, declaration order, and rules outside any layerMilestone 2 detail
Extended
lintCascadeLayers()inlib/css-lint-rules.mjsto:rulesByLayermap onCascadeLayerAuditrecords each named@layerblock's directly-nested style-rule selectors (anonymous@layer { }blocks are ignored).!importantinside layers: any!importantdeclaration inside a named layer emits animportant-in-layerissue (severity warning) carrying the layer name, explaining that!importantreverses layer priority and can make low-priority layers like resets win.@layerdeclaration AND carries high specificity (an ID selector or!important) is flagged aspost-layer-specificity(severity warning) instead of the genericrules-outside-layerssuggestion, since unlayered styles already override every layer regardless of specificity.CascadeLayerIssuenow supports bothsuggestionandwarningseverities plus an optionallayerfield. Seven new unit tests cover grouping, both anti-patterns, and the low-specificity / no-layer edge cases.Milestone 3 detail
Added a layer hierarchy visualization to the
mint-ds lintCLI output plus implicit/explicit ordering warnings:lib/types.ts: newLayerHierarchyEntryinterface (name,rank,order,rulesCount) and two new fields onCascadeLayerAudit--orderExplicit(boolean) andhierarchy(ordered entries, lowest priority first).lib/css-lint-rules.mjs:lintCascadeLayers()now detects whether an explicit@layer a, b, c;statement established the order, and marks each layer asexplicit(named in an order statement) orimplicit(order derived from first appearance only).bin/mint-ds.mjs:cmdLintrenders a "Cascade Layers" section listing the hierarchy lowest-priority-first, tagging each layer as explicit/implicit with its rule count, and showing unlayered styles at the top. When no explicit order statement exists, it emits a WARN suggesting an explicit order statement.Four new unit tests cover implicit vs explicit order detection, hierarchy shape (rank/order/rulesCount), and the empty-CSS case.
Milestone 4 detail
Added a real-world multi-layer test fixture and integration tests:
lib/__fixtures__/cascade-layers.css-- a design-system stylesheet with an explicit@layer reset, base, components, utilities;order statement, four named@layerblocks, legacy unlayered overrides (.legacy-clearfix::after,.footer), a high-specificity unlayered#hero { ... !important }rule declared after the layer order, and an!importantinside theresetlayer.lib/__tests__/css-lint-rules.test.mjs-- newlintCascadeLayers with the multi-layer fixturedescribe block with 5 tests asserting the explicit layer order, per-layer rule grouping (with whitespace-normalized selector matching for the multi-lineh1, h2, h3selector), unlayered / post-layer-specificity / important-in-layer issue classification, and the hierarchy shape with per-layer rule counts.How to test: