-
Notifications
You must be signed in to change notification settings - Fork 657
feat(rome_js_analyze): noUnusedVariable
rule
#2987
Conversation
4645324
to
c07b191
Compare
Deploying with
|
Latest commit: |
c98fcf7
|
Status: | ✅ Deploy successful! |
Preview URL: | https://a888494d.tools-8rn.pages.dev |
Branch Preview URL: | https://feature-no-unused-variable.tools-8rn.pages.dev |
!bench_analyzer |
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
Analyzer Benchmark Results
|
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.
There are few issues with functions, we have diagnostics when in reality they are valid cases.
warning[js/noUnusedVariables]: This parameter is unused. | ||
┌─ noUnusedVariables.js:21:17 | ||
│ | ||
21 │ function f42(a, b) { |
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.
Could we add a test case where we have a trailing comma? function f(a,b,){}
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.
I create more tests for the "remove_*" methods, instead of polluting this one here.
https://github.com/rome/tools/pull/2987/files#diff-0902796fee286e39e6f27f612b14a08a77e0af0dee55c59871e1a0292707c0faR110
crates/rome_js_analyze/tests/specs/js/noUnusedVariables.js.snap
Outdated
Show resolved
Hide resolved
|
||
Some(JsRuleAction { | ||
category: ActionCategory::Refactor, | ||
applicability: Applicability::Unspecified, |
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.
Considering that the applicability is Unspecified
, what does it mean for the end user? Can an user apply the change via CLI?
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.
what does it mean for the end user? Can an user apply the change via CLI?
No.
I am torn apart between Unspecified
and MaybeIncorrect
. I assumed that removing unused code is not the "best" solution.
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.
The semantics of Applicability
is something we'll need to review when we rework the diagnostics, the current version of the enum is inherited directly from rslint
and indirectly rustc
, but those tools are using text-based suggestions instead of tree-based.
In this case I think the Unspecified
applicability comes from rustc
, where the concept of "applicability" was added when the compiler already has a bunch of existing suggestions, so all those diagnostics were set to Unspecified
in the refactor to be manually reviewed later on.
In our case though we should always document if a suggestion is safe to apply or not, so in practice the only variants of Applicability
we should be using a MaybeIncorrect
and Always
(the difference is that Unspecified
can never be applied automatically, while MaybeIncorrect
can after the has the user has reviewed it)
} | ||
|
||
Some(JsRuleAction { | ||
category: ActionCategory::Refactor, |
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.
Why is this a Refactor
and not a QuickFix
? Just asking because I don't know yet the difference
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.
You are right. I think "Quickfix" makes more sense.
crates/rome_js_analyze/src/semantic_analyzers/js/no_unused_variables.rs
Outdated
Show resolved
Hide resolved
crates/rome_js_analyze/src/semantic_analyzers/js/no_unused_variables.rs
Outdated
Show resolved
Hide resolved
noUnusedVariable
rule
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.
Looks good to me. We should address the applicability of the rule.
381934d
to
c98fcf7
Compare
* no unused variables lint rule
Summary
Closes #2979.
Test Plan