Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fix(semantic_analyzers): style/noShoutyConstants does not recognize multiple uses of a constant. #3789

Merged
merged 20 commits into from
Nov 24, 2022
Merged

fix(semantic_analyzers): style/noShoutyConstants does not recognize multiple uses of a constant. #3789

merged 20 commits into from
Nov 24, 2022

Conversation

mzbac
Copy link
Contributor

@mzbac mzbac commented Nov 18, 2022

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

@netlify
Copy link

netlify bot commented Nov 18, 2022

Deploy Preview for docs-rometools ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 583b260
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/637f48848e59fe000834fb69
😎 Deploy Preview https://deploy-preview-3789--docs-rometools.netlify.app/playground
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@mzbac
Copy link
Contributor Author

mzbac commented Nov 18, 2022

@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.

Copy link
Contributor

@MichaReiser MichaReiser left a 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.

@mzbac
Copy link
Contributor Author

mzbac commented Nov 18, 2022

Cool, I will update PR to include that change, Thanks

@mzbac mzbac changed the title fix(semantic_analyzers): fix style/noShoutyConstants false error on exported object property fix(semantic_analyzers): fix style/noShoutyConstants does not recognize multiple uses of a constant. Nov 18, 2022
@ematipico ematipico changed the title fix(semantic_analyzers): fix style/noShoutyConstants does not recognize multiple uses of a constant. fix(semantic_analyzers): style/noShoutyConstants does not recognize multiple uses of a constant. Nov 18, 2022
@@ -145,15 +151,36 @@ impl Rule for NoShoutyConstants {
batch.remove_js_variable_declarator(ctx.query());

for reference in state.references.iter() {
Copy link
Contributor

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

Copy link
Contributor Author

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());
}
Copy link
Contributor

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.

Copy link
Contributor Author

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

@MichaReiser MichaReiser added the A-Linter Area: linter label Nov 24, 2022
@MichaReiser MichaReiser added this to the 11.0.0 milestone Nov 24, 2022
@MichaReiser MichaReiser merged commit f1df39c into rome:main Nov 24, 2022
jeysal added a commit to jeysal/rometools that referenced this pull request Nov 24, 2022
* 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)
  ...
@mzbac mzbac deleted the fix-no-shouty-constants branch December 16, 2022 14:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants