feat: track CSS custom properties on CSSSourceCode#411
Conversation
|
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
1 similar comment
|
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
…no-invalid-properties Implements the RFC for CSS custom property tracking on CSSSourceCode: - Add #customProperties map and #declarationVariables WeakMap - Populate during traverse() to track declarations, @Property definitions, and var() references - Add getDeclarationVariables(declaration) method - Add getClosestVariableValue(func) method - Add getVariableValues(func) method Refactor no-invalid-properties rule to use the new API: - Use getClosestVariableValue() for primary variable resolution - Pre-populate vars map from AST to support variable hoisting (fixes #199) - Fallback values take priority over other-block declarations per RFC Add comprehensive tests for all new CSSSourceCode methods. Agent-Logs-Url: https://github.com/eslint/css/sessions/e41fbbf4-0081-469f-8248-1e854213b08c Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
|
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
2 similar comments
|
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
|
Hi @copilot!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
src/rules/no-invalid-properties.js
Outdated
| * @param {Function} visitor The visitor function to call for each node. | ||
| * @returns {void} | ||
| */ | ||
| function walkAST(node, visitor) { |
There was a problem hiding this comment.
@copilot the rule itself is doing a depth-first traversal of the AST. Doing it again is inefficient. Remove the extra traversal and use the rule methods to do any traversing that is necessary.
There was a problem hiding this comment.
Removed the walkAST function and StyleSheet() visitor. The vars map is now populated incrementally in "Rule > Block Declaration:exit" as the rule traverses. Hoisting is handled by sourceCode.getClosestVariableValue() which has access to all declarations collected during CSSSourceCode.traverse(). Commit: 63d930c
…le visitor methods instead Agent-Logs-Url: https://github.com/eslint/css/sessions/fa674c27-bfb3-46b4-8c86-407a2fef55c5 Co-authored-by: nzakas <38546+nzakas@users.noreply.github.com>
Implements the CSS variable tracking RFC, centralizing custom property tracking on
CSSSourceCodeso rules don't duplicate this logic. Also fixes variable hoisting —var()references before their declaration now resolve correctly.CSSSourceCode— new APIThree new public methods backed by private
#customPropertiesMap and#declarationVariablesWeakMap, populated duringtraverse():getDeclarationVariables(declaration)— returnsvar()function nodes used in a declaration's valuegetClosestVariableValue(func)— returns the closest value for avar()node. Resolution priority per RFC: same-block declaration → fallback → other-block declarations (hoisted) →@propertyinitial-value →undefinedgetVariableValues(func)— returns all known values:@propertyinitial-value, then declarations in source order, then fallbackno-invalid-properties— refactored to use new APIgetClosestVariableValue()for primary resolution instead of maintaining its own variable mapgetClosestVariableValue()which has access to all declarations collected duringCSSSourceCode.traverse()var()refsvar()has a valid fallback, the fallback is now preferred over an invalid value from another selector blockTests
CSSSourceCodemethods (same-block, fallback priority, hoisting,@property, multiple declarations, cross-declaration isolation)no-invalid-properties💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.