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

fix(lint/noUselessConstructor): ignore constructor with default params #71

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ The following rules are now recommended:

The rule no longer reports false positive diagnostics when accessing properties directly from a hook and calling a hook inside function arguments.

- Fix [noUselessConstructor](https://biomejs.dev/lint/rules/noUselessConstructor/) which erroneously reported constructors with default parameters [rome#4781](https://github.com/rome/tools/issues/4781)

- Fix [noUselessFragments](https://biomejs.dev/lint/rules/nouselessfragments/)'s panics when running `biome check --apply-unsafe` ([#4637](https://github.com/rome/tools/issues/4639))

This rule's code action emits an invalid AST, so I fixed using JsxString instead of JsStringLiteral
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ rome_text_size = { version = "0.0.1", path = "./crates/rome_text_si
tests_macros = { path = "./crates/tests_macros" }

# Crates needed in the workspace
atty = "0.2.14"
bitflags = "2.3.1"
bpaf = { version = "0.9.3", features = ["derive"] }
countme = "3.0.1"
Expand All @@ -83,7 +84,6 @@ serde = { version = "1.0.163", features = ["derive"], default-featur
serde_json = "1.0.96"
smallvec = { version = "1.10.0", features = ["union", "const_new"] }
tracing = { version = "0.1.37", default-features = false, features = ["std"] }
atty = "0.2.14"
# pinning to version 1.18 to avoid multiple versions of windows-sys as dependency
tokio = { version = "~1.18.5" }

Expand Down
2 changes: 1 addition & 1 deletion crates/rome_console/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ version = "0.0.1"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
atty = { workspace = true }
atty = { workspace = true }
rome_markup = { workspace = true }
rome_text_size = { workspace = true }
schemars = { workspace = true, optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,20 @@ impl Rule for NoUselessConstructor {
if is_not_public {
return None;
}
let has_parameter_property = constructor
let has_param_property_or_default_param = constructor
.parameters()
.ok()?
.parameters()
.iter()
.filter_map(|x| x.ok())
.any(|x| TsPropertyParameter::can_cast(x.syntax().kind()));
if has_parameter_property {
.any(|x| {
TsPropertyParameter::can_cast(x.syntax().kind())
|| x.as_any_js_formal_parameter()
.and_then(|x| x.as_js_formal_parameter())
.and_then(|x| x.initializer())
.is_some()
});
if has_param_property_or_default_param {
return None;
}
let has_parent_class = constructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[
"class A { }",
"class A { constructor(a, b = 0){ } }",
"class A { constructor(){ doSomething(); } }",
"class A extends B { constructor(){} }",
"class A extends B { constructor(){ super('foo'); } }",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 96
expression: valid.jsonc
---
# Input
```js
class A { }
```

# Input
```js
class A { constructor(a, b = 0){ } }
```

# Input
```js
class A { constructor(){ doSomething(); } }
Expand Down
2 changes: 2 additions & 0 deletions website/src/pages/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,8 @@ The following rules are now recommended:

The rule no longer reports false positive diagnostics when accessing properties directly from a hook and calling a hook inside function arguments.

- Fix [noUselessConstructor](https://biomejs.dev/lint/rules/noUselessConstructor/) which erroneously reported constructors with default parameters [rome#4781](https://github.com/rome/tools/issues/4781)

- Fix [noUselessFragments](https://biomejs.dev/lint/rules/nouselessfragments/)'s panics when running `biome check --apply-unsafe` ([#4637](https://github.com/rome/tools/issues/4639))

This rule's code action emits an invalid AST, so I fixed using JsxString instead of JsStringLiteral
Expand Down