-
Notifications
You must be signed in to change notification settings - Fork 656
feat(rome_js_analyze): no unused starting with underscore; small hack for React and removing suggested fix #3124
Conversation
Deploying with Cloudflare Pages
|
FYI for parameters, eslint has the
|
@@ -198,43 +211,4 @@ impl Rule for NoUnusedVariables { | |||
|
|||
Some(diag) | |||
} | |||
|
|||
fn action(ctx: &RuleContext<Self>, _: &Self::State) -> Option<JsRuleAction> { |
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 think we could still keep the code action for variables, but instead of removing the whole declaration it could suggest to prefix the name with an underscore ?
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 would prefer to remove it for now. And we can return it after it is a little bit more mature.
|
||
// Old code import React but do not used directly | ||
// only indirectly after transpiling JSX. | ||
if name.starts_with('_') || name == "React" { |
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 check for React
should only apply to JSX files, although at the moment I don't think we have access to the SourceType
for the file in the RuleContext
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.
To add more, we were discussing about implementing JSX parsing to JS files. If that happens in the future, we would need access to that information too.
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.
No, we don´t.
It is a little bit hacky now. I expect this to be turned into an option in the future.
hum... Honestly not sure about this. One of the reasons I like noUnusedVariables is to get typos. So, for example, the code below would not flag Now... today we only have two ways to suppress these: 1 - Suppression lines; Are these fine and enough? const server = http.createServer(function(req, res) {
console.log(re); //try to use req but typo
console.log(res); // correctly uses res
}); |
Summary
This improves noUnusedVariables in three ways and removes the suggestion of removing the unused variables:
1 - It does not flag variables starting with "_";
2 - It does not flag React because some old codebases import React and use it only after JSX transpiling;
3 - It ignores function and class expressions (we are going to deal with these in another rule);
The suggestion was removed, because it suggested removing the first parameter of a function, and of course, completely changing the meaning of the other parameters. We need to think a little bit about what we want to suggest.
Test Plan