Skip to content

Commit

Permalink
feat(lint/useDefaultCase): add missing eslint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michellocana committed Apr 26, 2024
1 parent 73a8633 commit 173d410
Show file tree
Hide file tree
Showing 24 changed files with 319 additions and 14 deletions.
12 changes: 6 additions & 6 deletions crates/biome_js_analyze/src/lint/nursery/use_default_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ impl Rule for UseDefaultCase {

Some(
RuleDiagnostic::new(
rule_category!(),
node.range(),
markup! {
"Expected a default case."
},
rule_category!(),
node.range(),
markup! {
"Expected a default case."
},
)
.note(markup! {
"The lack of a default clause can result in unexpected behaviors in your code."
}).note(markup! {
"Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex /" {comment_pattern} "/"
"Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/" {comment_pattern} "/`."
}),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ invalid.js:1:1 lint/nursery/useDefaultCase ━━━━━━━━━━━━
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 /^no default$/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/^no default$/`.
```
Expand All @@ -65,7 +65,7 @@ invalid.js:6:1 lint/nursery/useDefaultCase ━━━━━━━━━━━━
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 /^no default$/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/^no default$/`.
```
Expand All @@ -89,7 +89,7 @@ invalid.js:12:1 lint/nursery/useDefaultCase ━━━━━━━━━━━━
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 /^no default$/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/^no default$/`.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
switch (a) {
case 1:
break;
}
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 `/.?/`.
```
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": ".?"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ invalidCommentPattern.js:1:1 lint/nursery/useDefaultCase ━━━━━━━
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 /skip default(\s\d)*/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/skip default(\s\d)*/`.
```
Expand All @@ -77,7 +77,7 @@ invalidCommentPattern.js:6:1 lint/nursery/useDefaultCase ━━━━━━━
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 /skip default(\s\d)*/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/skip default(\s\d)*/`.
```
Expand All @@ -102,7 +102,7 @@ invalidCommentPattern.js:12:1 lint/nursery/useDefaultCase ━━━━━━━
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 /skip default(\s\d)*/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/skip default(\s\d)*/`.
```
Expand All @@ -126,7 +126,7 @@ invalidCommentPattern.js:19:1 lint/nursery/useDefaultCase ━━━━━━━
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 /skip default(\s\d)*/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/skip default(\s\d)*/`.
```
Expand All @@ -149,7 +149,7 @@ invalidCommentPattern.js:25:1 lint/nursery/useDefaultCase ━━━━━━━
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 /skip default(\s\d)*/
i Consider adding a default clause or a comment explicitly stating that the default clause is not required, following the regex `/skip default(\s\d)*/`.
```
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
}
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/`.
```
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"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
switch (a) {
case 1:
break;
// no default
}
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/`.
```
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"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
switch (a) {
case 1:
break;
//
}
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;
//
}

```
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": ".?"
}
}
}
}
}
}
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
*/
}
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
*/
}

```
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"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
switch (a) {
case 1:
break;
default:
break;
}
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;
}

```
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"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
switch (a) {
case 1:
break;
// skip default case
}
Loading

0 comments on commit 173d410

Please sign in to comment.