-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b7ef04
commit 31adde6
Showing
9 changed files
with
328 additions
and
85 deletions.
There are no files selected for viewing
183 changes: 101 additions & 82 deletions
183
crates/biome_configuration/src/analyzer/linter/rules.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
crates/biome_js_analyze/src/lint/nursery/no_react_deps.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
use biome_analyze::{context::RuleContext, declare_lint_rule, Ast, Rule, RuleDiagnostic, RuleDomain, RuleSource, RuleSourceKind}; | ||
use biome_console::markup; | ||
use biome_js_syntax::{JsCallExpression, JsIdentifierBinding}; | ||
use biome_rowan::AstNode; | ||
|
||
declare_lint_rule! { | ||
/// Disallow usage of dependency arrays in `createEffect` and `createMemo`. | ||
/// | ||
/// In Solid, `createEffect` and `createMemo` track dependencies automatically, it's no need to add dependency arrays. | ||
/// | ||
/// ## Examples | ||
/// | ||
/// ### Invalid | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createEffect } from "solid-js"; | ||
/// createEffect(() => { | ||
/// console.log(signal()); | ||
/// }, [signal()]); | ||
/// ``` | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createEffect } from "solid-js"; | ||
/// createEffect(() => { | ||
/// console.log(signal()); | ||
/// }, [signal]); | ||
/// ``` | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createEffect } from "solid-js"; | ||
/// const deps = [signal]; | ||
/// createEffect(() => { | ||
/// console.log(signal()); | ||
/// }, deps) | ||
/// ``` | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createMemo } from "solid-js"; | ||
/// const value = createMemo(() => computeExpensiveValue(a(), b()), [a(), b()]); | ||
/// ``` | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createMemo } from "solid-js"; | ||
/// const value = createMemo(() => computeExpensiveValue(a(), b()), [a, b]); | ||
/// ``` | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createMemo } from "solid-js"; | ||
/// const value = createMemo(() => computeExpensiveValue(a(), b()), [a, b()]); | ||
/// ``` | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createMemo } from "solid-js"; | ||
/// const deps = [a, b]; | ||
/// const value = createMemo(() => computeExpensiveValue(a(), b()), deps); | ||
/// ``` | ||
/// | ||
/// ```js,expect_diagnostic | ||
/// import { createMemo } from "solid-js"; | ||
/// const deps = [a, b]; | ||
/// const memoFn = () => computeExpensiveValue(a(), b()); | ||
/// const value = createMemo(memoFn, deps); | ||
/// ``` | ||
/// | ||
/// ### Valid | ||
/// | ||
/// ```js | ||
/// import { createEffect } from "solid-js"; | ||
/// createEffect(() => { | ||
/// console.log(signal()); | ||
/// }); | ||
/// ``` | ||
/// | ||
/// ```js | ||
/// import { createEffect } from "solid-js"; | ||
/// createEffect((prev) => { | ||
/// console.log(signal()); | ||
/// return prev + 1; | ||
/// }, 0); | ||
/// ``` | ||
/// | ||
/// ```js | ||
/// import { createEffect } from "solid-js"; | ||
/// createEffect((prev) => { | ||
/// console.log(signal()); | ||
/// return (prev || 0) + 1; | ||
/// }); | ||
/// ``` | ||
/// | ||
/// ```js | ||
/// import { createEffect } from "solid-js"; | ||
/// createEffect((prev) => { | ||
/// console.log(signal()); | ||
/// return prev ? prev + 1 : 1; | ||
/// }, undefined); | ||
/// ``` | ||
/// | ||
/// ```js | ||
/// import { createMemo } from "solid-js"; | ||
/// const value = createMemo(() => computeExpensiveValue(a(), b())); | ||
/// ``` | ||
/// | ||
/// ```js | ||
/// import { createMemo } from "solid-js"; | ||
/// const sum = createMemo((prev) => input() + prev, 0); | ||
/// ``` | ||
/// | ||
/// ```js | ||
/// import { createEffect } from "solid-js"; | ||
/// const args = [ | ||
/// () => { | ||
/// console.log(signal()); | ||
/// }, | ||
/// [signal()], | ||
/// ]; | ||
/// createEffect(...args); | ||
/// ``` | ||
pub NoReactDeps { | ||
version: "next", | ||
name: "noReactDeps", | ||
language: "js", | ||
domains: &[RuleDomain::Solid], | ||
recommended: false, | ||
sources: &[RuleSource::EslintSolid("no-react-deps")], | ||
source_kind: RuleSourceKind::Inspired, | ||
} | ||
} | ||
|
||
impl Rule for NoReactDeps { | ||
type Query = Ast<JsCallExpression>; | ||
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> { | ||
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.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
crates/biome_js_analyze/tests/specs/nursery/noReactDeps/invalid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createEffect, createMemo } from "solid-js"; | ||
|
||
createEffect(() => { | ||
console.log(signal()); | ||
}, [signal()]); | ||
|
||
createEffect(() => { | ||
console.log(signal()); | ||
}, [signal]); | ||
|
||
const deps = [signal]; | ||
createEffect(() => { | ||
console.log(signal()); | ||
}, deps); | ||
|
||
const value = createMemo(() => computeExpensiveValue(a(), b()), [a(), b()]); | ||
|
||
const value = createMemo(() => computeExpensiveValue(a(), b()), [a, b]); | ||
|
||
const value = createMemo(() => computeExpensiveValue(a(), b()), [a, b()]); | ||
|
||
const deps = [a, b]; | ||
const value = createMemo(() => computeExpensiveValue(a(), b()), deps); | ||
|
||
const deps = [a, b]; | ||
const memoFn = () => computeExpensiveValue(a(), b()); | ||
const value = createMemo(memoFn, deps); |
27 changes: 27 additions & 0 deletions
27
crates/biome_js_analyze/tests/specs/nursery/noReactDeps/valid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { createEffect, createMemo } from "solid-js"; | ||
|
||
createEffect(() => { | ||
console.log(signal()); | ||
}); | ||
|
||
createEffect((prev) => { | ||
console.log(signal()); | ||
return prev + 1; | ||
}, 0); | ||
|
||
createEffect((prev) => { | ||
console.log(signal()); | ||
return (prev || 0) + 1; | ||
}); | ||
|
||
createEffect((prev) => { | ||
console.log(signal()); | ||
return prev ? prev + 1 : 1; | ||
}, undefined); | ||
|
||
const value = createMemo(() => computeExpensiveValue(a(), b())); | ||
|
||
const sum = createMemo((prev) => input() + prev, 0); | ||
|
||
const args = [() => { console.log(signal()); }, [signal()]]; | ||
createEffect(...args); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.