Skip to content
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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
239 changes: 129 additions & 110 deletions crates/biome_configuration/src/analyzer/linter/rules.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ define_categories! {
"lint/correctness/useValidForDirection": "https://biomejs.dev/linter/rules/use-valid-for-direction",
"lint/correctness/useYield": "https://biomejs.dev/linter/rules/use-yield",
"lint/nursery/colorNoInvalidHex": "https://biomejs.dev/linter/rules/color-no-invalid-hex",
"lint/nursery/noBind": "https://biomejs.dev/linter/rules/no-bind",
"lint/nursery/noColorInvalidHex": "https://biomejs.dev/linter/rules/no-color-invalid-hex",
"lint/nursery/noCommonJs": "https://biomejs.dev/linter/rules/no-common-js",
"lint/nursery/noConsole": "https://biomejs.dev/linter/rules/no-console",
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/src/lint/nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use biome_analyze::declare_lint_group;

pub mod no_bind;
pub mod no_common_js;
pub mod no_document_cookie;
pub mod no_document_import_in_page;
Expand Down Expand Up @@ -47,6 +48,7 @@ declare_lint_group! {
pub Nursery {
name : "nursery" ,
rules : [
self :: no_bind :: NoBind ,
self :: no_common_js :: NoCommonJs ,
self :: no_document_cookie :: NoDocumentCookie ,
self :: no_document_import_in_page :: NoDocumentImportInPage ,
Expand Down
67 changes: 67 additions & 0 deletions crates/biome_js_analyze/src/lint/nursery/no_bind.rs
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",
Copy link
Contributor

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.

Copy link
Author

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.

language: "js",
thecode00 marked this conversation as resolved.
Show resolved Hide resolved
recommended: false,
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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."
}),
)
}
}
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/options.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/biome_js_analyze/tests/specs/nursery/noBind/invalid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var a = 1;
a = 2;
a = 3;
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/tests/specs/nursery/noBind/valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* should not generate diagnostics */
// var a = 1;
5 changes: 5 additions & 0 deletions packages/@biomejs/backend-jsonrpc/src/workspace.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions packages/@biomejs/biome/configuration_schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading