-
-
Notifications
You must be signed in to change notification settings - Fork 486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lint): add rule noJsxPropsBind #4639
base: main
Are you sure you want to change the base?
Changes from 1 commit
21a7e79
358c790
3e376fa
4496ba2
989fbb1
60b8eba
6aa5dd6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use biome_analyze::{context::RuleContext, declare_lint_rule, Ast, Rule, RuleDiagnostic}; | ||
use biome_console::markup; | ||
use biome_js_syntax::JsIdentifierBinding; | ||
use biome_rowan::AstNode; | ||
|
||
declare_lint_rule! { | ||
/// Succinct description of the rule. | ||
/// | ||
/// Put context and details about the rule. | ||
/// As a starting point, you can take the description of the corresponding _ESLint_ rule (if any). | ||
/// | ||
/// Try to stay consistent with the descriptions of implemented rules. | ||
/// | ||
/// ## Examples | ||
/// | ||
/// ### Invalid | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// var a = 1; | ||
/// a = 2; | ||
/// ``` | ||
/// | ||
/// ### Valid | ||
/// | ||
/// ```js | ||
/// // var a = 1; | ||
/// ``` | ||
/// | ||
pub NoBind { | ||
version: "next", | ||
name: "noBind", | ||
language: "js", | ||
thecode00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
recommended: false, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't have a rule source |
||
} | ||
|
||
impl Rule for NoBind { | ||
type Query = Ast<JsIdentifierBinding>; | ||
type State = (); | ||
type Signals = Option<Self::State>; | ||
type Options = (); | ||
|
||
fn run(ctx: &RuleContext<Self>) -> Self::Signals { | ||
let _binding = ctx.query(); | ||
Some(()) | ||
} | ||
|
||
fn diagnostic(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<RuleDiagnostic> { | ||
// | ||
// Read our guidelines to write great diagnostics: | ||
// https://docs.rs/biome_analyze/latest/biome_analyze/#what-a-rule-should-say-to-the-user | ||
// | ||
let node = ctx.query(); | ||
Some( | ||
RuleDiagnostic::new( | ||
rule_category!(), | ||
node.range(), | ||
markup! { | ||
"Variable is read here." | ||
}, | ||
) | ||
.note(markup! { | ||
"This note will give you more information." | ||
}), | ||
) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var a = 1; | ||
a = 2; | ||
a = 3; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/* should not generate diagnostics */ | ||
// var a = 1; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 feel like we can come up with a better name than
noBind
. At the very least, it should mention "Jsx" since this rule should only apply to Jsx.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.
Oh, I see😅.
However, I've noticed that some existing JSX rules include "jsx" in their names while others do not. Maybe need to standardize "Jsx" naming convention.