0
# Rule Management
1
2
Oxlint provides a hierarchical rule management system with categories, individual rule configuration, and flexible severity controls. Rules can be configured through command-line options or configuration files with fine-grained control over scope and application.
3
4
## Rule Categories
5
6
Oxlint organizes rules into logical categories that can be enabled or disabled as groups:
7
8
### Correctness
9
```bash { .api }
10
oxlint -D correctness # Deny (error level)
11
oxlint -W correctness # Warn level
12
oxlint -A correctness # Allow (suppress)
13
```
14
15
Code that is outright wrong or useless. Enabled by default at error level.
16
17
**Examples:** `no-debugger`, `no-unreachable`, `no-duplicate-keys`
18
19
### Suspicious
20
```bash { .api }
21
oxlint -D suspicious
22
oxlint -W suspicious
23
oxlint -A suspicious
24
```
25
26
Code that is most likely wrong or problematic but may have legitimate uses.
27
28
**Examples:** `no-empty`, `no-implicit-coercion`, `no-unused-vars`
29
30
### Pedantic
31
```bash { .api }
32
oxlint -D pedantic
33
oxlint -W pedantic
34
oxlint -A pedantic
35
```
36
37
Strict rules that enforce best practices but may have occasional false positives.
38
39
**Examples:** `prefer-const`, `no-var`, `eqeqeq`
40
41
### Style
42
```bash { .api }
43
oxlint -D style
44
oxlint -W style
45
oxlint -A style
46
```
47
48
Code style and formatting rules for consistent code appearance.
49
50
**Examples:** `semi`, `quotes`, `indent`, `comma-dangle`
51
52
### Nursery
53
```bash { .api }
54
oxlint -D nursery
55
oxlint -W nursery
56
oxlint -A nursery
57
```
58
59
New rules under development that may change behavior or have limited testing.
60
61
### Restriction
62
```bash { .api }
63
oxlint -D restriction
64
oxlint -W restriction
65
oxlint -A restriction
66
```
67
68
Rules that prevent the use of specific language features or patterns.
69
70
**Examples:** `no-eval`, `no-with`, `no-implicit-globals`
71
72
### All Categories
73
```bash { .api }
74
oxlint -A all # Allow all rules
75
oxlint -D all # Deny all rules (except nursery)
76
```
77
78
Applies to all categories except nursery. Does not automatically enable plugins.
79
80
## Rule Severity Levels
81
82
### Command Line Severity Control
83
84
```bash { .api }
85
# Allow (suppress) - rules produce no output
86
oxlint --allow RULE_NAME
87
oxlint -A RULE_NAME
88
89
# Warn - rules produce warnings (exit code 0 unless --deny-warnings)
90
oxlint --warn RULE_NAME
91
oxlint -W RULE_NAME
92
93
# Deny (error) - rules produce errors (exit code 1)
94
oxlint --deny RULE_NAME
95
oxlint -D RULE_NAME
96
```
97
98
### Configuration File Severity
99
100
```json { .api }
101
{
102
"rules": {
103
"rule-name": "off", // 0 - disable rule
104
"rule-name": "warn", // 1 - warning level
105
"rule-name": "error" // 2 - error level
106
}
107
}
108
```
109
110
## Individual Rule Configuration
111
112
### Basic Rule Configuration
113
114
```json { .api }
115
{
116
"rules": {
117
"no-debugger": "error",
118
"no-console": "warn",
119
"no-unused-vars": "off",
120
"eqeqeq": "error",
121
"prefer-const": "warn"
122
}
123
}
124
```
125
126
### Rule Configuration with Options
127
128
```json { .api }
129
{
130
"rules": {
131
"prefer-const": ["error", {
132
"destructuring": "any",
133
"ignoreReadBeforeAssign": false
134
}],
135
"no-unused-vars": ["warn", {
136
"vars": "all",
137
"args": "after-used",
138
"ignoreRestSiblings": true
139
}],
140
"quotes": ["error", "single", {
141
"avoidEscape": true,
142
"allowTemplateLiterals": false
143
}]
144
}
145
}
146
```
147
148
## Command Line Rule Management
149
150
### Layered Rule Configuration
151
152
Rules are applied in order from left to right, allowing fine-grained control:
153
154
```bash
155
# Start with all rules allowed, then deny specific categories
156
oxlint -A all -D correctness -D suspicious src/
157
158
# Allow a category but deny specific rules
159
oxlint -A pedantic -D prefer-const -D no-var src/
160
161
# Mix of category and individual rule controls
162
oxlint -D suspicious --allow no-debugger -W no-console src/
163
```
164
165
### Rule Precedence
166
167
Command-line options override configuration file settings:
168
169
```bash
170
# Override config file rules
171
oxlint -c .oxlintrc.json -A no-debugger -D prefer-const src/
172
```
173
174
## Advanced Rule Management
175
176
### File-Specific Rule Overrides
177
178
```json { .api }
179
{
180
"rules": {
181
"no-console": "error"
182
},
183
"overrides": [
184
{
185
"files": ["**/*.test.js", "**/*.spec.js"],
186
"rules": {
187
"no-console": "off"
188
}
189
},
190
{
191
"files": ["scripts/**/*.js"],
192
"rules": {
193
"no-console": "warn",
194
"no-process-exit": "off"
195
}
196
}
197
]
198
}
199
```
200
201
### Plugin-Specific Rules
202
203
```json { .api }
204
{
205
"plugins": ["typescript", "react"],
206
"rules": {
207
// TypeScript rules
208
"@typescript-eslint/no-unused-vars": "error",
209
"@typescript-eslint/explicit-function-return-type": "warn",
210
211
// React rules
212
"react/jsx-uses-react": "error",
213
"react/jsx-uses-vars": "error",
214
215
// Disable conflicting core rules when using TypeScript
216
"no-unused-vars": "off"
217
}
218
}
219
```
220
221
### Category-Level Configuration
222
223
```json { .api }
224
{
225
"categories": {
226
"correctness": "error",
227
"suspicious": "warn",
228
"pedantic": "off",
229
"style": "warn"
230
},
231
"rules": {
232
// Override specific rules within categories
233
"no-debugger": "warn", // Override correctness default
234
"prefer-const": "error" // Override pedantic default
235
}
236
}
237
```
238
239
## Rule Discovery and Information
240
241
### List Available Rules
242
243
```bash { .api }
244
oxlint --rules
245
```
246
247
Displays all available rules organized by plugin and category.
248
249
### Rule Documentation
250
251
Rules follow standard naming conventions:
252
- Core rules: `rule-name`
253
- Plugin rules: `plugin-name/rule-name`
254
- TypeScript rules: `@typescript-eslint/rule-name`
255
256
## Warning and Error Handling
257
258
### Warning Thresholds
259
260
```bash { .api }
261
# Set maximum number of warnings before exit code 1
262
oxlint --max-warnings 10 src/
263
264
# Treat any warning as error
265
oxlint --deny-warnings src/
266
267
# Suppress warnings, show errors only
268
oxlint --quiet src/
269
```
270
271
### Inline Directive Reporting
272
273
```bash { .api }
274
# Report unused eslint-disable directives
275
oxlint --report-unused-disable-directives src/
276
277
# Report with specific severity
278
oxlint --report-unused-disable-directives-severity error src/
279
```
280
281
## Common Rule Configuration Patterns
282
283
### Strict Configuration
284
285
```json
286
{
287
"categories": {
288
"correctness": "error",
289
"suspicious": "error",
290
"pedantic": "error"
291
},
292
"rules": {
293
"no-debugger": "error",
294
"no-console": "error",
295
"eqeqeq": "error",
296
"prefer-const": "error"
297
}
298
}
299
```
300
301
### Gradual Adoption
302
303
```json
304
{
305
"categories": {
306
"correctness": "error",
307
"suspicious": "warn",
308
"pedantic": "off"
309
},
310
"rules": {
311
// Gradually enable pedantic rules
312
"prefer-const": "warn",
313
"no-var": "warn"
314
}
315
}
316
```
317
318
### Framework-Specific Rules
319
320
```json
321
{
322
"plugins": ["react", "typescript"],
323
"overrides": [
324
{
325
"files": ["**/*.tsx", "**/*.jsx"],
326
"rules": {
327
"react/jsx-uses-react": "error",
328
"react/jsx-key": "error",
329
"react/no-unused-state": "warn"
330
}
331
},
332
{
333
"files": ["**/*.ts", "**/*.tsx"],
334
"rules": {
335
"@typescript-eslint/no-unused-vars": "error",
336
"@typescript-eslint/no-explicit-any": "warn",
337
"no-unused-vars": "off"
338
}
339
}
340
]
341
}
342
```