feat: split no-static-styles-assignment messages#160
Open
saberzero1 wants to merge 1 commit into
Open
Conversation
liamcain
reviewed
Jun 9, 2026
| node, | ||
| messageId: "avoidStyleAssignment", | ||
| data: { property: "el.setCssStyles" }, | ||
| messageId: "avoidCustomPropertyInSetCssStyles", |
Collaborator
There was a problem hiding this comment.
I'm not sure that this is necessary. Isn't this already a linting error since setCssStyles expects CSSStyleDeclaration as the key
Collaborator
There was a problem hiding this comment.
This distinction isn't that significant so it's probably not really worth a custom linter rule for the setCssStyles case.
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
Fixes false positive where
no-static-styles-assignmentflaggedel.setCssProps({ 'padding-bottom': 'unset' }). The rule now enforces the intended API contract:setCssPropsis for CSS custom properties (--*) only, andsetCssStylesis for standard CSS properties only.Problem
The rule had a single
avoidStyleAssignmentmessage that told users "Use thesetCssPropsfunction if the CSS properties need to change dynamically.", but then flaggedsetCssPropsitself when called with standard property names. This was contradictory: the error message recommended the exact API it was reporting on.Additionally,
setCssStyles(Case 4) had identical logic tosetCssProps(Case 3); it flagged non---*keys. SincesetCssStylesis the correct API for standard CSS properties, this was backwards.Changes
New message IDs (
lib/rules/noStaticStylesAssignment.ts)avoidNonCustomPropertyInSetCssProps: reported whensetCssPropsreceives a standard property key. Tells the user to usesetCssStylesor CSS classes instead.avoidCustomPropertyInSetCssStyles: reported whensetCssStylesreceives a--*key. Tells the user to usesetCssPropsinstead.avoidStyleAssignment: now mentions bothsetCssPropsandsetCssStylesas alternatives for the genericel.style.*cases.Fixed
setCssStyleslogic (Case 4)--(custom properties don't belong in setCssStyles) instead of keys that don't start with--.Tests (
tests/noStaticStylesAssignment.test.ts)setCssStyleswith standard property,setCssStyleswith computed keysetCssPropscase to expectavoidNonCustomPropertyInSetCssPropssetCssStylescase: now tests{ '--my-var': 'blue' }expectingavoidCustomPropertyInSetCssStylesWhat changes for consumers
el.setCssProps({ '--my-var': 'value' })-> no error (correct usage)el.setCssProps({ 'color': 'blue' })-> error with a message directing tosetCssStylesor CSS classesel.setCssStyles({ 'color': 'blue' })-> no error (correct usage, previously flagged)el.setCssStyles({ '--my-var': 'value' })-> error with a message directing tosetCssPropsel.style.*direct assignments -> unchanged behavior, updated message text