File tree Expand file tree Collapse file tree 4 files changed +30
-8
lines changed
src/docs/guide/usage/linter/rules Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,12 @@ type: `boolean`
150
150
151
151
default: ` false`
152
152
153
+ ### allowTypeAnnotation
154
+
155
+ type: ` boolean`
156
+
157
+ default: ` false`
158
+
153
159
### style
154
160
155
161
type: ` "expression" | "declaration"`
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ Disallow unsafe declaration merging.
20
20
### Why is this bad?
21
21
22
22
Declaration merging between classes and interfaces is unsafe.
23
- The TypeScript compiler doesn't check whether properties are initialized, which can cause lead to TypeScript not detecting code that will cause runtime errors.
23
+ The TypeScript compiler doesn't check whether properties are initialized, which can lead to TypeScript not detecting code that will cause runtime errors.
24
24
25
25
### Examples
26
26
Original file line number Diff line number Diff line change @@ -15,20 +15,21 @@ const source = `https://github.com/oxc-project/oxc/blob/${ data }/crates/oxc_lin
15
15
16
16
### What it does
17
17
18
- Require empty switch cases to not have braces. Non-empty braces are required to have braces around them.
18
+ Requires empty switch cases to omit braces, while non-empty cases must use braces.
19
+ This reduces visual clutter for empty cases and enforces proper scoping for non-empty ones.
19
20
20
21
### Why is this bad?
21
22
22
- There is less visual clutter for empty cases and proper scope for non-empty cases.
23
+ Using braces unnecessarily for empty cases adds visual noise,
24
+ while omitting braces in non-empty cases can lead to scoping issues.
23
25
24
26
### Examples
25
27
26
28
Examples of ** incorrect** code for this rule:
27
29
28
30
``` javascript
29
31
switch (num) {
30
- case 1 : {
31
- }
32
+ case 1 : {}
32
33
case 2 :
33
34
console .log (" Case 2" );
34
35
break ;
@@ -39,15 +40,30 @@ Examples of **correct** code for this rule:
39
40
40
41
``` javascript
41
42
switch (num) {
42
- case 1 : {
43
- }
43
+ case 1 :
44
44
case 2 : {
45
45
console .log (" Case 2" );
46
46
break ;
47
47
}
48
48
}
49
49
```
50
50
51
+ ### Options
52
+
53
+ ` { type: "always" | "avoid", default: "always" } `
54
+
55
+ - ` "always" `
56
+ Always report when clause is not a ` BlockStatement ` .
57
+
58
+ - ` "avoid" `
59
+ Allows braces only when needed for scoping (e.g., variable or function declarations).
60
+
61
+ Example:
62
+
63
+ ``` json
64
+ "unicorn/switch-case-braces" : [" error" , " avoid" ]
65
+ ```
66
+
51
67
## How to use
52
68
53
69
To ** enable** this rule in the CLI or using the config file, you can use:
Original file line number Diff line number Diff line change 1
1
export default {
2
2
load ( ) {
3
- return "49b664c6b9e5eb8b9c177f9fab1b8372763359e0 " ;
3
+ return "1a71d7c16f27c7f52f1bd1f5823a15f1f8123693 " ;
4
4
} ,
5
5
} ;
You can’t perform that action at this time.
0 commit comments