Skip to content

Commit

Permalink
test: add test cases for empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
ssssota committed Sep 9, 2023
1 parent c73ec67 commit 0409107
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ a = {
}
a = {
[`1+1`]: 2
}
}
a = {
[""]: 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ a = {
a = {
[`1+1`]: 2
}
a = {
[""]: 2
}

```

# Diagnostics
Expand Down Expand Up @@ -610,6 +614,7 @@ invalid.js:34:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━
> 34 │ [`1+1`]: 2
│ ^^^^^
35 │ }
36 │ a = {
i Suggested fix: Use a literal key instead.
Expand All @@ -618,7 +623,27 @@ invalid.js:34:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━
34 │ - → [`1+1`]:·2
34 │ + → "1+1":·2
35 35 │ }
36 36 │ a = {
```

```
invalid.js:37:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
35 │ }
36 │ a = {
> 37 │ [""]: 2
│ ^^
38 │ }
39 │
i Suggested fix: Use a literal key instead.
37 │ → [""]:·2
│ - -
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface I {
["m1"](): void

"m2"(): void

[""]: number
}

export type T = {
Expand All @@ -32,4 +34,6 @@ export type T = {
["m1"](): void

"m2"(): void

[""]: number
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface I {
["m1"](): void

"m2"(): void

[""]: number
}

export type T = {
Expand All @@ -38,6 +40,8 @@ export type T = {
["m1"](): void

"m2"(): void

[""]: number
}

```
Expand Down Expand Up @@ -184,8 +188,8 @@ invalid.ts:16:2 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━
15 │
> 16 │ "m2"(): void
│ ^^^^
17 │ }
18 │
17 │
18 │ [""]: number
i Suggested fix: Use a literal key instead.
Expand All @@ -195,152 +199,190 @@ invalid.ts:16:2 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━
```

```
invalid.ts:20:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:18:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
19 │ export type T = {
> 20 │ ["p1"]: number
16 │ "m2"(): void
17 │
> 18 │ [""]: number
│ ^^
19 │ }
20 │
i Suggested fix: Use a literal key instead.
18 │ → [""]:·number
│ - -
```

```
invalid.ts:22:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
21 │ export type T = {
> 22 │ ["p1"]: number
│ ^^^^
21
22 │ "p2": number
23
24 │ "p2": number
i Suggested fix: Use a literal key instead.
20 │ → ["p1"]:·number
22 │ → ["p1"]:·number
│ -- --
```

```
invalid.ts:22:2 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:24:2 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
20 │ ["p1"]: number
21 │
> 22 │ "p2": number
│ ^^^^
22 │ ["p1"]: number
23 │
24 │ get ["p3"](): number
> 24 │ "p2": number
│ ^^^^
25 │
26 │ get ["p3"](): number
i Suggested fix: Use a literal key instead.
22 │ → "p2":·number
24 │ → "p2":·number
│ - -
```

```
invalid.ts:24:7 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:26:7 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
22 │ "p2": number
23 │
> 24 │ get ["p3"](): number
│ ^^^^
24 │ "p2": number
25 │
26 │ get "p4"(): number
> 26 │ get ["p3"](): number
│ ^^^^
27 │
28 │ get "p4"(): number
i Suggested fix: Use a literal key instead.
24 │ → get·["p3"]():·number
26 │ → get·["p3"]():·number
│ -- --
```

```
invalid.ts:26:6 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:28:6 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
24 │ get ["p3"](): number
25 │
> 26 │ get "p4"(): number
│ ^^^^
26 │ get ["p3"](): number
27 │
28 │ set ["p3"](x: number)
> 28 │ get "p4"(): number
│ ^^^^
29 │
30 │ set ["p3"](x: number)
i Suggested fix: Use a literal key instead.
26 │ → get·"p4"():·number
28 │ → get·"p4"():·number
│ - -
```

```
invalid.ts:28:7 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:30:7 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
26 │ get "p4"(): number
27 │
> 28 │ set ["p3"](x: number)
│ ^^^^
28 │ get "p4"(): number
29 │
30 │ set "p4"(x: number)
> 30 │ set ["p3"](x: number)
│ ^^^^
31 │
32 │ set "p4"(x: number)
i Suggested fix: Use a literal key instead.
28 │ → set·["p3"](x:·number)
30 │ → set·["p3"](x:·number)
│ -- --
```

```
invalid.ts:30:6 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:32:6 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
28 │ set ["p3"](x: number)
29 │
> 30 │ set "p4"(x: number)
│ ^^^^
30 │ set ["p3"](x: number)
31 │
32 │ ["m1"](): void
> 32 │ set "p4"(x: number)
│ ^^^^
33 │
34 │ ["m1"](): void
i Suggested fix: Use a literal key instead.
30 │ → set·"p4"(x:·number)
32 │ → set·"p4"(x:·number)
│ - -
```

```
invalid.ts:32:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:34:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
30 │ set "p4"(x: number)
31 │
> 32 │ ["m1"](): void
│ ^^^^
32 │ set "p4"(x: number)
33 │
34 │ "m2"(): void
> 34 │ ["m1"](): void
│ ^^^^
35 │
36 │ "m2"(): void
i Suggested fix: Use a literal key instead.
32 │ → ["m1"]():·void
34 │ → ["m1"]():·void
│ -- --
```

```
invalid.ts:34:2 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.ts:36:2 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
32 │ ["m1"](): void
33
> 34 │ "m2"(): void
34 │ ["m1"](): void
35
> 36 │ "m2"(): void
│ ^^^^
35 │ }
36 │
37 │
38 │ [""]: number
i Suggested fix: Use a literal key instead.
36 │ → "m2"():·void
│ - -
```

```
invalid.ts:38:3 lint/complexity/useLiteralKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! The computed expression can be simplified without the use of a string literal.
36 │ "m2"(): void
37 │
> 38 │ [""]: number
│ ^^
39 │ }
40 │
i Suggested fix: Use a literal key instead.
34 │ → "m2"():·void
38 │ → [""]:·number
│ - -
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
a[""];
a["b" + 1];
a["c" + "d"];
a["c" + "d"];
a = {
["c" + "d"]: d
};
a = {
"": d
};
a["00"]
a[`0`]
a["a-b"]
Expand All @@ -13,4 +17,4 @@ a[`time${range}`];
class C { a = 0 }
class C { a(){} }
class C { get a(){} }
class C { set a(x){} }
class C { set a(x){} }
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ expression: valid.js
---
# Input
```js
a[""];
a["b" + 1];
a["c" + "d"];
a["c" + "d"];
a = {
["c" + "d"]: d
};
a = {
"": d
};
a["00"]
a[`0`]
a["a-b"]
Expand All @@ -20,6 +24,7 @@ class C { a = 0 }
class C { a(){} }
class C { get a(){} }
class C { set a(x){} }

```


0 comments on commit 0409107

Please sign in to comment.