-
-
Notifications
You must be signed in to change notification settings - Fork 541
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lint/useDefaultCase): add missing eslint tests
- Loading branch information
1 parent
73a8633
commit 173d410
Showing
24 changed files
with
319 additions
and
14 deletions.
There are no files selected for viewing
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
4 changes: 4 additions & 0 deletions
4
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidAny.js
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,4 @@ | ||
switch (a) { | ||
case 1: | ||
break; | ||
} |
33 changes: 33 additions & 0 deletions
33
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidAny.js.snap
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,33 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: invalidAny.js | ||
--- | ||
# Input | ||
```jsx | ||
switch (a) { | ||
case 1: | ||
break; | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
invalidAny.js:1:1 lint/nursery/useDefaultCase ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Expected a default case. | ||
> 1 │ switch (a) { | ||
│ ^^^^^^^^^^^^ | ||
> 2 │ case 1: | ||
> 3 │ break; | ||
> 4 │ } | ||
│ ^ | ||
5 │ | ||
i The lack of a default clause can result in unexpected behaviors in your code. | ||
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/.?/`. | ||
``` |
15 changes: 15 additions & 0 deletions
15
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidAny.options.json
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,15 @@ | ||
{ | ||
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
"linter": { | ||
"rules": { | ||
"nursery": { | ||
"useDefaultCase": { | ||
"level": "error", | ||
"options": { | ||
"commentPattern": ".?" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidDefaultOmitted.js
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,6 @@ | ||
switch (a) { | ||
case 1: | ||
break; | ||
// default omitted intentionally | ||
// TODO: add default case | ||
} |
37 changes: 37 additions & 0 deletions
37
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidDefaultOmitted.js.snap
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,37 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: invalidDefaultOmitted.js | ||
--- | ||
# Input | ||
```jsx | ||
switch (a) { | ||
case 1: | ||
break; | ||
// default omitted intentionally | ||
// TODO: add default case | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
invalidDefaultOmitted.js:1:1 lint/nursery/useDefaultCase ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Expected a default case. | ||
> 1 │ switch (a) { | ||
│ ^^^^^^^^^^^^ | ||
> 2 │ case 1: | ||
> 3 │ break; | ||
> 4 │ // default omitted intentionally | ||
> 5 │ // TODO: add default case | ||
> 6 │ } | ||
│ ^ | ||
7 │ | ||
i The lack of a default clause can result in unexpected behaviors in your code. | ||
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/default omitted/`. | ||
``` |
15 changes: 15 additions & 0 deletions
15
...es/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidDefaultOmitted.options.json
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,15 @@ | ||
{ | ||
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
"linter": { | ||
"rules": { | ||
"nursery": { | ||
"useDefaultCase": { | ||
"level": "error", | ||
"options": { | ||
"commentPattern": "default omitted" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidSkippedDefaultCase.js
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,5 @@ | ||
switch (a) { | ||
case 1: | ||
break; | ||
// no default | ||
} |
35 changes: 35 additions & 0 deletions
35
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/invalidSkippedDefaultCase.js.snap
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,35 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: invalidSkippedDefaultCase.js | ||
--- | ||
# Input | ||
```jsx | ||
switch (a) { | ||
case 1: | ||
break; | ||
// no default | ||
} | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
invalidSkippedDefaultCase.js:1:1 lint/nursery/useDefaultCase ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! Expected a default case. | ||
> 1 │ switch (a) { | ||
│ ^^^^^^^^^^^^ | ||
> 2 │ case 1: | ||
> 3 │ break; | ||
> 4 │ // no default | ||
> 5 │ } | ||
│ ^ | ||
6 │ | ||
i The lack of a default clause can result in unexpected behaviors in your code. | ||
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/skipped default case/`. | ||
``` |
15 changes: 15 additions & 0 deletions
15
...iome_js_analyze/tests/specs/nursery/useDefaultCase/invalidSkippedDefaultCase.options.json
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,15 @@ | ||
{ | ||
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
"linter": { | ||
"rules": { | ||
"nursery": { | ||
"useDefaultCase": { | ||
"level": "error", | ||
"options": { | ||
"commentPattern": "skipped default case" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validAny.js
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,5 @@ | ||
switch (a) { | ||
case 1: | ||
break; | ||
// | ||
} |
13 changes: 13 additions & 0 deletions
13
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validAny.js.snap
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,13 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: validAny.js | ||
--- | ||
# Input | ||
```jsx | ||
switch (a) { | ||
case 1: | ||
break; | ||
// | ||
} | ||
|
||
``` |
15 changes: 15 additions & 0 deletions
15
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validAny.options.json
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,15 @@ | ||
{ | ||
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
"linter": { | ||
"rules": { | ||
"nursery": { | ||
"useDefaultCase": { | ||
"level": "error", | ||
"options": { | ||
"commentPattern": ".?" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validDefault.js
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,8 @@ | ||
switch (a) { | ||
case 1: | ||
break; | ||
/* | ||
TODO: | ||
throw error in default case | ||
*/ | ||
} |
16 changes: 16 additions & 0 deletions
16
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validDefault.js.snap
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,16 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: validDefault.js | ||
--- | ||
# Input | ||
```jsx | ||
switch (a) { | ||
case 1: | ||
break; | ||
/* | ||
TODO: | ||
throw error in default case | ||
*/ | ||
} | ||
|
||
``` |
15 changes: 15 additions & 0 deletions
15
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validDefault.options.json
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,15 @@ | ||
{ | ||
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
"linter": { | ||
"rules": { | ||
"nursery": { | ||
"useDefaultCase": { | ||
"level": "error", | ||
"options": { | ||
"commentPattern": "default" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validDefaultCaseOmitted.js
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,6 @@ | ||
switch (a) { | ||
case 1: | ||
break; | ||
default: | ||
break; | ||
} |
14 changes: 14 additions & 0 deletions
14
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validDefaultCaseOmitted.js.snap
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,14 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: validDefaultCaseOmitted.js | ||
--- | ||
# Input | ||
```jsx | ||
switch (a) { | ||
case 1: | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
``` |
15 changes: 15 additions & 0 deletions
15
.../biome_js_analyze/tests/specs/nursery/useDefaultCase/validDefaultCaseOmitted.options.json
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,15 @@ | ||
{ | ||
"$schema": "../../../../../../packages/@biomejs/biome/configuration_schema.json", | ||
"linter": { | ||
"rules": { | ||
"nursery": { | ||
"useDefaultCase": { | ||
"level": "error", | ||
"options": { | ||
"commentPattern": "default case omitted" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
crates/biome_js_analyze/tests/specs/nursery/useDefaultCase/validSkipDefault.js
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,5 @@ | ||
switch (a) { | ||
case 1: | ||
break; | ||
// skip default case | ||
} |
Oops, something went wrong.