feat: add CSS custom property tracking to CSSSourceCode#377
Draft
wingding12 wants to merge 1 commit intoeslint:mainfrom
Draft
feat: add CSS custom property tracking to CSSSourceCode#377wingding12 wants to merge 1 commit intoeslint:mainfrom
wingding12 wants to merge 1 commit intoeslint:mainfrom
Conversation
|
|
1 task
Implements RFC eslint/rfcs#136 to centralize CSS variable tracking on CSSSourceCode, making it available to all rules. Adds: - `#customProperties` map populated during AST traversal - `getDeclarationVariables(declaration)` to get var() functions in a declaration - `getClosestVariableValue(func)` to resolve closest value for a var() call - `getVariableValues(func)` to get all possible values across the file Refactors `no-invalid-properties` to use the new API instead of maintaining its own variable tracking. This naturally fixes variable hoisting (eslint#199) since the new API sees all declarations in the file regardless of source position. Refs eslint#160 Fixes eslint#199
c9c73f2 to
a8a01db
Compare
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.
Summary
Implements RFC eslint/rfcs#136 to centralize CSS custom property (variable) tracking on CSSSourceCode, making it available to all rules.
Changes
CSSSourceCode (src/languages/css-source-code.js):
#customPropertiesprivate map, populated during AST traversal, tracking declarations,@propertydefinitions, andvar()references for each custom property name#declarationVariablesWeakMap to track whichvar()functions appear in each declarationgetDeclarationVariables(declaration)to return var() function nodes used in a declaration valuegetClosestVariableValue(funcOrName)to resolve the closest value for a var() function (same-block, fallback, previous rules, @Property initial-value), also accepts a string name for chain resolutiongetVariableValues(func)to return all possible values for a var() function across the entire file (hoisting-aware)no-invalid-properties rule (src/rules/no-invalid-properties.js):
sourceCode.getClosestVariableValue()andsourceCode.getVariableValues()instead of maintaining its own vars MapTests
Refs #160
Fixes #199