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

Commit

Permalink
fix(rome_js_analyze): useSimpleNumberKeys #4457 handle shortand/sprea…
Browse files Browse the repository at this point in the history
…d object props (#4459)
  • Loading branch information
Conaclos authored May 11, 2023
1 parent b77547d commit 76ef67b
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ impl TryFrom<AnyJsObjectMember> for NumberLiteral {
type Error = NumberLiteralError;

fn try_from(any_member: AnyJsObjectMember) -> Result<Self, Self::Error> {
let literal_member_name_syntax = any_member
let Some(literal_member_name_syntax) = any_member
.syntax()
.children()
.find(|x| JsLiteralMemberName::can_cast(x.kind()))
.unwrap();
.find(|x| JsLiteralMemberName::can_cast(x.kind())) else {
return Err(NumberLiteralError)
};
let literal_member_name = JsLiteralMemberName::cast(literal_member_name_syntax).unwrap();

let token = literal_member_name.value().unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
({ 1_0: 1 });
({ 0.1e1_2: "ed" });
({ 11_1.11: "ee" });
({ 0x1() {} });
({ [0x1]() {} });
({ get 0x1() { return this.a } });
({ set 0x1(a) { this.a = a } });
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 96
expression: invalid.js
---
# Input
Expand All @@ -12,6 +13,10 @@ expression: invalid.js
({ 1_0: 1 });
({ 0.1e1_2: "ed" });
({ 11_1.11: "ee" });
({ 0x1() {} });
({ [0x1]() {} });
({ get 0x1() { return this.a } });
({ set 0x1(a) { this.a = a } });

```

Expand All @@ -28,10 +33,10 @@ invalid.js:1:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
i Safe fix: Replace 1n with 1
1 │ - ({·1n:·1·});
1 │ + ({·1:·1·});
2 2 │ ({ 0x1: 1 });
3 3 │ ({ 0o12: 1 });
1 │ - ({·1n:·1·});
1 │ + ({·1:·1·});
2 2 │ ({ 0x1: 1 });
3 3 │ ({ 0o12: 1 });
```
Expand All @@ -49,11 +54,11 @@ invalid.js:2:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
i Safe fix: Replace 0x1 with 1
1 1 │ ({ 1n: 1 });
2 │ - ({·0x1:·1·});
2 │ + ({·1:·1·});
3 3 │ ({ 0o12: 1 });
4 4 │ ({ 0b1: 1 });
1 1 │ ({ 1n: 1 });
2 │ - ({·0x1:·1·});
2 │ + ({·1:·1·});
3 3 │ ({ 0o12: 1 });
4 4 │ ({ 0b1: 1 });
```
Expand All @@ -72,12 +77,12 @@ invalid.js:3:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
i Safe fix: Replace 0o12 with 9
1 1 │ ({ 1n: 1 });
2 2 │ ({ 0x1: 1 });
3 │ - ({·0o12:·1·});
3 │ + ({·9:·1·});
4 4 │ ({ 0b1: 1 });
5 5 │ ({ 0o1: 1 });
1 1 │ ({ 1n: 1 });
2 2 │ ({ 0x1: 1 });
3 │ - ({·0o12:·1·});
3 │ + ({·9:·1·});
4 4 │ ({ 0b1: 1 });
5 5 │ ({ 0o1: 1 });
```
Expand All @@ -96,12 +101,12 @@ invalid.js:4:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
i Safe fix: Replace 0b1 with 1
2 2 │ ({ 0x1: 1 });
3 3 │ ({ 0o12: 1 });
4 │ - ({·0b1:·1·});
4 │ + ({·1:·1·});
5 5 │ ({ 0o1: 1 });
6 6 │ ({ 1_0: 1 });
2 2 │ ({ 0x1: 1 });
3 3 │ ({ 0o12: 1 });
4 │ - ({·0b1:·1·});
4 │ + ({·1:·1·});
5 5 │ ({ 0o1: 1 });
6 6 │ ({ 1_0: 1 });
```
Expand All @@ -120,12 +125,12 @@ invalid.js:5:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
i Safe fix: Replace 0o1 with 1
3 3 │ ({ 0o12: 1 });
4 4 │ ({ 0b1: 1 });
5 │ - ({·0o1:·1·});
5 │ + ({·1:·1·});
6 6 │ ({ 1_0: 1 });
7 7 │ ({ 0.1e1_2: "ed" });
3 3 │ ({ 0o12: 1 });
4 4 │ ({ 0b1: 1 });
5 │ - ({·0o1:·1·});
5 │ + ({·1:·1·});
6 6 │ ({ 1_0: 1 });
7 7 │ ({ 0.1e1_2: "ed" });
```
Expand All @@ -144,12 +149,12 @@ invalid.js:6:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
i Safe fix: Replace 1_0 with 10
4 4 │ ({ 0b1: 1 });
5 5 │ ({ 0o1: 1 });
6 │ - ({·1_0:·1·});
6 │ + ({·10:·1·});
7 7 │ ({ 0.1e1_2: "ed" });
8 8 │ ({ 11_1.11: "ee" });
4 4 │ ({ 0b1: 1 });
5 5 │ ({ 0o1: 1 });
6 │ - ({·1_0:·1·});
6 │ + ({·10:·1·});
7 7 │ ({ 0.1e1_2: "ed" });
8 8 │ ({ 11_1.11: "ee" });
```
Expand All @@ -164,16 +169,16 @@ invalid.js:7:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
> 7 │ ({ 0.1e1_2: "ed" });
│ ^^^^^^^
8 │ ({ 11_1.11: "ee" });
9 │
9 │ ({ 0x1() {} });
i Safe fix: Replace 0.1e1_2 with .1e12
5 5 │ ({ 0o1: 1 });
6 6 │ ({ 1_0: 1 });
7 │ - ({·0.1e1_2:·"ed"·});
7 │ + ({·.1e12:·"ed"·});
8 8 │ ({ 11_1.11: "ee" });
9 9 │
5 5 │ ({ 0o1: 1 });
6 6 │ ({ 1_0: 1 });
7 │ - ({·0.1e1_2:·"ed"·});
7 │ + ({·.1e12:·"ed"·});
8 8 │ ({ 11_1.11: "ee" });
9 9 │ ({ 0x1() {} });
```
Expand All @@ -183,19 +188,91 @@ invalid.js:8:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━
! Number literal with underscore is not allowed here.
6 │ ({ 1_0: 1 });
7 │ ({ 0.1e1_2: "ed" });
> 8 │ ({ 11_1.11: "ee" });
│ ^^^^^^^
9 │
6 │ ({ 1_0: 1 });
7 │ ({ 0.1e1_2: "ed" });
> 8 │ ({ 11_1.11: "ee" });
│ ^^^^^^^
9 │ ({ 0x1() {} });
10 │ ({ [0x1]() {} });
i Safe fix: Replace 11_1.11 with 111.11
6 6 │ ({ 1_0: 1 });
7 7 │ ({ 0.1e1_2: "ed" });
8 │ - ({·11_1.11:·"ee"·});
8 │ + ({·111.11:·"ee"·});
9 9 │
6 6 │ ({ 1_0: 1 });
7 7 │ ({ 0.1e1_2: "ed" });
8 │ - ({·11_1.11:·"ee"·});
8 │ + ({·111.11:·"ee"·});
9 9 │ ({ 0x1() {} });
10 10 │ ({ [0x1]() {} });
```

```
invalid.js:9:4 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Hexadecimal number literal is not allowed here.
7 │ ({ 0.1e1_2: "ed" });
8 │ ({ 11_1.11: "ee" });
> 9 │ ({ 0x1() {} });
│ ^^^
10 │ ({ [0x1]() {} });
11 │ ({ get 0x1() { return this.a } });
i Safe fix: Replace 0x1 with 1
7 7 │ ({ 0.1e1_2: "ed" });
8 8 │ ({ 11_1.11: "ee" });
9 │ - ({·0x1()·{}·});
9 │ + ({·1()·{}·});
10 10 │ ({ [0x1]() {} });
11 11 │ ({ get 0x1() { return this.a } });
```

```
invalid.js:11:8 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Hexadecimal number literal is not allowed here.
9 │ ({ 0x1() {} });
10 │ ({ [0x1]() {} });
> 11 │ ({ get 0x1() { return this.a } });
│ ^^^
12 │ ({ set 0x1(a) { this.a = a } });
13 │
i Safe fix: Replace 0x1 with 1
9 9 │ ({ 0x1() {} });
10 10 │ ({ [0x1]() {} });
11 │ - ({·get·0x1()·{·return·this.a·}·});
11 │ + ({·get·1()·{·return·this.a·}·});
12 12 │ ({ set 0x1(a) { this.a = a } });
13 13 │
```

```
invalid.js:12:8 lint/nursery/useSimpleNumberKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Hexadecimal number literal is not allowed here.
10 │ ({ [0x1]() {} });
11 │ ({ get 0x1() { return this.a } });
> 12 │ ({ set 0x1(a) { this.a = a } });
│ ^^^
13 │
i Safe fix: Replace 0x1 with 1
10 10 │ ({ [0x1]() {} });
11 11 │ ({ get 0x1() { return this.a } });
12 │ - ({·set·0x1(a)·{·this.a·=·a·}·});
12 │ + ({·set·1(a)·{·this.a·=·a·}·});
13 13 │
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
({ 1.2: "12" });
({ 3.1e12: "12" });
({ 0.1e12: "ee" });
({ a });
({ ...a });
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
source: crates/rome_js_analyze/tests/spec_tests.rs
assertion_line: 96
expression: valid.js
---
# Input
Expand All @@ -9,6 +10,8 @@ expression: valid.js
({ 1.2: "12" });
({ 3.1e12: "12" });
({ 0.1e12: "ee" });
({ a });
({ ...a });

```

Expand Down

0 comments on commit 76ef67b

Please sign in to comment.