-
Notifications
You must be signed in to change notification settings - Fork 656
fix(semantic_analyzers): style/noShoutyConstants does not recognize multiple uses of a constant. #3789
Conversation
✅ Deploy Preview for docs-rometools ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs
Outdated
Show resolved
Hide resolved
@MichaReiser Current fix doesn't change the behaviour. I am not very sure if we need to change the rule to ignore the shouty constant if it is used multiple times. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that mainly flags #3658 the issue where a constant is used more than once. Inlining is then undesired because it would result in repeated code.
crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs
Outdated
Show resolved
Hide resolved
Cool, I will update PR to include that change, Thanks |
crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/style/no_shouty_constants.rs
Outdated
Show resolved
Hide resolved
@@ -145,15 +151,36 @@ impl Rule for NoShoutyConstants { | |||
batch.remove_js_variable_declarator(ctx.query()); | |||
|
|||
for reference in state.references.iter() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to simplify the state
now that we always have exactly one reference:
Change: references
to reference: Reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MichaReiser Updated the PR as you suggested..
); | ||
|
||
batch.replace_element(node.into_syntax().into(), new_element.into_syntax().into()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last change. We must return None
if the reference is neither a IdentifierExpression
nor a ShorthandProperty
to avoid that we return an action that doesn't perform any changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaReiser 👍 , you are right. I just pushed the change. thanks
* upstream/main: (73 commits) fix(semantic_analyzers): style/noShoutyConstants does not recognize multiple uses of a constant. (rome#3789) feat(rome_js_analyze): useDefaultSwitchClauseLast (rome#3791) chore: run rustfmt and typo fix (rome#3840) feat(rome_js_analyze): use exhaustive deps support properties (rome#3581) website(docs): Fix text formatting (rome#3828) feat(rome_js_analyze): `noVoidTypeReturn` (rome#3806) feat(rome_cli): expose the `--verbose` flag to the CLI (rome#3812) fix(rome_diagnostics): allow diagnostic locations to be created without a resource (rome#3834) feat(rome_js_analyze): add noExtraNonNullAssertion rule (rome#3797) fix(rome_lsp): lsp friendly catch unwind (rome#3740) feat(rome_js_semantic): model improvements (rome#3825) feat(rome_json_parser): JSON Lexer (rome#3809) feat(rome_js_analyze): implement `noDistractingElements` (rome#3820) fix(rome_js_formatter): shothanded named import line break with default import (rome#3826) feat(rome_js_analyze): `noConstructorReturn` (rome#3805) feat(website): change enabledNurseryRules to All/Recommended select (rome#3810) feat(rome_js_analyze): noSetterReturn feat(rome_js_analyze): noConstructorReturn feat(rome_analyze): suppress rule via code actions (rome#3572) feat(rome_js_analyze): `noVar` (rome#3765) ...
Summary
This is for fixing #3658. The current implementation fires false errors on exported shouty constants, and ignore the shouty constant checking when it's used more than once.
Test Plan
added new test cased to cover the fix