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

fix(rome_js_analyze): fix noShoutyConstants with lowercase and being exported #3081

Merged
merged 2 commits into from
Aug 19, 2022

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Aug 17, 2022

Summary

Closes #3077.

Test Plan

> cargo test -p rome_js_analyze -- shouty

with two new cases

let foo = "foo";

const A = "A";
export default A;

@xunilrj xunilrj requested a review from leops as a code owner August 17, 2022 21:17
@xunilrj xunilrj requested a review from a team August 17, 2022 21:17
@xunilrj xunilrj temporarily deployed to aws August 17, 2022 21:17 Inactive
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 17, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 50c3ef7
Status: ✅  Deploy successful!
Preview URL: https://344729b1.tools-8rn.pages.dev
Branch Preview URL: https://fix-no-shouty-constants-lowe.tools-8rn.pages.dev

View logs

@github-actions
Copy link

github-actions bot commented Aug 17, 2022

@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45878 45878 0
Passed 44938 44938 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 396 396 0
Failed 5550 5550 0
Panics 0 0 0
Coverage 6.66% 6.66% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12397 12397 0
Failed 3860 3860 0
Panics 0 0 0
Coverage 76.26% 76.26% 0.00%

@xunilrj
Copy link
Contributor Author

xunilrj commented Aug 17, 2022

!bench_analyzer

@github-actions
Copy link

Analyzer Benchmark Results

group                     main                                   pr
-----                     ----                                   --
analyzer/css.js           1.03      2.7±0.11ms     4.3 MB/sec    1.00      2.6±0.16ms     4.5 MB/sec
analyzer/index.js         1.00      6.9±0.34ms     4.7 MB/sec    1.00      6.9±0.37ms     4.7 MB/sec
analyzer/lint.ts          1.02      3.6±0.21ms    11.5 MB/sec    1.00      3.6±0.20ms    11.6 MB/sec
analyzer/parser.ts        1.01      8.5±0.47ms     5.7 MB/sec    1.00      8.5±0.41ms     5.8 MB/sec
analyzer/router.ts        1.02      5.9±0.22ms    10.4 MB/sec    1.00      5.8±0.28ms    10.5 MB/sec
analyzer/statement.ts     1.00      7.9±0.36ms     4.5 MB/sec    1.00      7.9±0.37ms     4.5 MB/sec
analyzer/typescript.ts    1.00     11.8±0.53ms     4.6 MB/sec    1.00     11.8±0.54ms     4.6 MB/sec

@IWANABETHATGUY
Copy link
Contributor

A few suggestions:

  1. Would you mind adding some valid cases in our generated markdown? https://github.com/rome/tools/pull/3078/files#diff-fdf4fb740794b3a765f8604dee5b3939df2fa9a5bf566e910c31b7db591373bcR26-R31

Some((id.clone(), literal.clone()))
} else {
None
for (from_id, from_literal) in id_text.chars().zip(literal_text.chars()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically both id_text and literal_text only ever cover a single token (IDENT and JS_STRING_LITERAL), so I think it would be possible to run this check over two &str directly rather than having to implement these helpers for SyntaxNodeText

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
But I have mixed feelings about this:

  • On one side is probably faster.
  • But we are also not using the typed AST here. So I have to take care around quotes.

if from_id != from_literal {
return None;
}
if from_id.is_lowercase() || from_literal.is_lowercase() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the exit condition for the loop is correct here, from the description of the rule I would expect it to raise a diagnostic for const foo = "FOO"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question. It is my understanding that the rule is only for uppercase bindings. const foo = "FOO" seems fine for me because it correctly gives a camel case name to a constant.

Copy link
Contributor

@ematipico ematipico Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the rule should work only for uppercase cases. That was its initial intention

@leops
Copy link
Contributor

leops commented Aug 18, 2022

A few suggestions:

1. Would you mind adding some valid cases in our generated markdown? https://github.com/rome/tools/pull/3078/files#diff-fdf4fb740794b3a765f8604dee5b3939df2fa9a5bf566e910c31b7db591373bcR26-R31

We can also pull the valid cases from the original rule in Rome JS: https://github.com/rome/tools/blob/archived-js/website/src/docs/lint/rules/js/noShoutyConstants.md

@xunilrj xunilrj temporarily deployed to aws August 18, 2022 12:53 Inactive
@xunilrj
Copy link
Contributor Author

xunilrj commented Aug 19, 2022

A few suggestions:

Done.

@xunilrj xunilrj merged commit 871d28e into main Aug 19, 2022
@xunilrj xunilrj deleted the fix/no-shouty-constants-lowercase-export branch August 19, 2022 09:29
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
…exported (rome#3081)

* fix noShoutyConstants with lowercase and being exported
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 false positive noShoutyConstants
4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载