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

feat(rome_analyze): noDebugger #2643

Merged
merged 15 commits into from
Jun 13, 2022
Merged

Conversation

IWANABETHATGUY
Copy link
Contributor

@IWANABETHATGUY IWANABETHATGUY commented Jun 2, 2022

Summary

  1. Add new analyze rule noDebugger , part of ☂️ First batch of Linter Rules #2642
  2. Resolved 📎 noDebugger #2651

Test Plan

  1. should pass noDebugger.js
  2. the test case is stole from ESlint , https://github.com/eslint/eslint/blob/main/tests/lib/rules/no-debugger.js

@MichaReiser MichaReiser requested a review from leops June 2, 2022 15:17
@NicholasLYang
Copy link
Contributor

We should probably have a guide on proper error message style and conventions. For now, how about we imitate ESLint?

Unexpected 'debugger' statement.

@IWANABETHATGUY
Copy link
Contributor Author

I copy from here, https://github.com/rome/tools/blob/archived-js/website/src/docs/lint/rules/js/noDebugger.md

This is an unexpected use of the debugger statement.

Copy link
Contributor

@leops leops left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution. For the Rome linter we aim to have as many rules as possible coming with automated fixes, Could you add a code action to the rule along with the diagnostic ?
Unfortunately the analyzer is still in a very early stage and it's missing many helpers around mutating syntax trees, in this case the fix means removing the debugger statement from it's parent node but I think that might need to be handled through a new helper function to either splice it out from the parent statement list or replace it with an empty statement in the if(cond) debugger case for instance

@IWANABETHATGUY
Copy link
Contributor Author

Thanks for this contribution. For the Rome linter we aim to have as many rules as possible coming with automated fixes, Could you add a code action to the rule along with the diagnostic ? Unfortunately the analyzer is still in a very early stage and it's missing many helpers around mutating syntax trees, in this case the fix means removing the debugger statement from it's parent node but I think that might need to be handled through a new helper function to either splice it out from the parent statement list or replace it with an empty statement in the if(cond) debugger case for instance

I just found ESlint doesn't have a code action, so I keep the code action as is, which a None. If we want to port other rule, how could I know if it has a code action or not?

@leops
Copy link
Contributor

leops commented Jun 2, 2022

I just found ESlint doesn't have a code action, so I keep the code action as is, which a None. If we want to port other rule, how could I know if it has a code action or not?

In #2642 I tried to reference rules that have an auto-fix available when possible, so for instance the source for the noDebugger rule there is Rome JS since it has a fixable diagnostic

@IWANABETHATGUY
Copy link
Contributor Author

Thanks for this contribution. For the Rome linter we aim to have as many rules as possible coming with automated fixes, Could you add a code action to the rule along with the diagnostic ? Unfortunately the analyzer is still in a very early stage and it's missing many helpers around mutating syntax trees, in this case the fix means removing the debugger statement from it's parent node but I think that might need to be handled through a new helper function to either splice it out from the parent statement list or replace it with an empty statement in the if(cond) debugger case for instance

It seems root.replace_node can't replace a DebuggerStatement with a EmptyStatement due to they have different type.

pub fn replace_node<N>(self, prev_node: N, next_node: N) -> Option<Self>
where
    N: AstNode<Language = Self::Language>,
    Self: Sized,

@leops
Copy link
Contributor

leops commented Jun 3, 2022

It seems root.replace_node can't replace a DebuggerStatement with a EmptyStatement due to they have different type.

You can use the JsAnyStatement union to replace statements with a different type: .replace_node(JsAnyStatement::JsDebuggerStatement(prev), JsAnyStatement::JsEmptyStatement(next))

@IWANABETHATGUY IWANABETHATGUY changed the title feat: 🎸 feat/(rome_analyze):no-debugger feat: 🎸 (rome_analyze):no-debugger Jun 3, 2022
@IWANABETHATGUY IWANABETHATGUY requested a review from leops June 3, 2022 09:38
crates/rome_analyze/src/analyzers/no_debugger.rs Outdated Show resolved Hide resolved
crates/rome_analyze/src/analyzers/no_debugger.rs Outdated Show resolved Hide resolved
crates/rome_analyze/tests/specs/noDebugger.js Outdated Show resolved Hide resolved
@IWANABETHATGUY IWANABETHATGUY requested a review from leops June 3, 2022 11:37
@ematipico
Copy link
Contributor

ematipico commented Jun 3, 2022

We should probably have a guide on proper error message style and conventions. For now, how about we imitate ESLint?

Unexpected 'debugger' statement.

ESlint messages are one of the reasons why we pledge to have better error messages. (https://rome.tools/#technical, first bullet point).

The Rome classic linter was the most stable feature we had and its messages were reviewed by many people, Sebastian included. I think we should just port the old messages to this new linter rewrite.

@ematipico ematipico changed the title feat: 🎸 (rome_analyze):no-debugger feat(rome_analyze): noDebugger Jun 3, 2022
@NicholasLYang
Copy link
Contributor

I'm not really clear on why the error message is better. From my perspective it's a little more verbose, but honestly a minor difference. I can go either way.

A bigger issue I have is that there's no explanation or context around why this rule exists. With linting, I think it should be pretty important to have an explanation of why we are not allowing something.

@ematipico
Copy link
Contributor

I'm not really clear on why the error message is better. From my perspective it's a little more verbose, but honestly a minor difference. I can go either way.

A bigger issue I have is that there's no explanation or context around why this rule exists. With linting, I think it should be pretty important to have an explanation of why we are not allowing something.

This is a good point! We should always try to explain why we deny something. Care to venture a suggestion?

@leops
Copy link
Contributor

leops commented Jun 7, 2022

A bigger issue I have is that there's no explanation or context around why this rule exists. With linting, I think it should be pretty important to have an explanation of why we are not allowing something.

This is a good point! We should always try to explain why we deny something. Care to venture a suggestion?

This is probably not the best place to discuss this, but besides improving to RuleDiagnostic to bring it inline with rome_diagnostic (and probably merge all diagnostics into a single unified system eventually) which will allow for richer diagnostics with more and better information, for the release of the analyzer rules will need to come with their documentation. Initially I think this will simply be in the form of documentation pages for each rule on the website, with a Hyperlink markup in the diagnostic header to make the code of the lint rule clickable (in terminal clients that support it), but we could also introduce a rome explain <lint rule> (similar to the rustc --explain command) to let users read the documentation for a rule directly through the command line (in offline usage scenarios for instance)

@NicholasLYang
Copy link
Contributor

@leops @ematipico Think it's okay to make a discussion for this? I agree there should be a page for each rule with documentation. I'm also a fan of Rust's error index.

@IWANABETHATGUY
Copy link
Contributor Author

This pull request is ready to merge @ematipico

@IWANABETHATGUY
Copy link
Contributor Author

@ematipico , what about this one, both of you have been approved this pull request

@leops leops merged commit d329b1b into rome:main Jun 13, 2022
IWANABETHATGUY added a commit to IWANABETHATGUY/tools that referenced this pull request Jun 15, 2022
* feat: 🎸 feat/(rome_analyze):no-debugger

* feat: 🎸 add code action

* chore: 🤖 tweak action tetxt

* test: 💍 add extra test

* test: 💍 should remove debugger statement

* style: 💄 fmt

* test: 💍 debugger

* chore: 🤖 change test

* chore: 🤖 fix diff issue

* chore: 🤖 merge main

* chore: 🤖 fix snapshot
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.

📎 noDebugger
4 participants