Skip to content

Commit b22bf35

Browse files
Copilothardfist
andauthored
doc: Add Rslint configuration documentation page (#294)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: hardfist <[email protected]>
1 parent d68e1d0 commit b22bf35

File tree

3 files changed

+304
-5
lines changed

3 files changed

+304
-5
lines changed

website/docs/en/_nav.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
[
2-
{
3-
"text": "Rules",
4-
"link": "/rules/",
5-
"activeMatch": "/rules/"
6-
},
72
{
83
"text": "Guide",
94
"link": "/guide/",
105
"activeMatch": "/guide/"
6+
},
7+
{
8+
"text": "Configuration",
9+
"link": "/config/",
10+
"activeMatch": "/config/"
11+
},
12+
{
13+
"text": "Rules",
14+
"link": "/rules/",
15+
"activeMatch": "/rules/"
1116
}
1217
]

website/docs/en/config/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["index"]

website/docs/en/config/index.md

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
# Configuration
2+
3+
Rslint uses a configuration file to define linting rules and behavior. This page describes all the configuration options available.
4+
5+
## Configuration File
6+
7+
Rslint looks for configuration files in the following order:
8+
9+
- `rslint.json`
10+
- `rslint.jsonc` (JSON with comments)
11+
12+
You can also specify a custom configuration file using the `--config` option:
13+
14+
```bash
15+
rslint --config custom-config.json
16+
```
17+
18+
### Creating a Configuration File
19+
20+
To create a default configuration file, run:
21+
22+
```bash
23+
rslint --init
24+
```
25+
26+
This creates a `rslint.jsonc` file with sensible defaults.
27+
28+
## Configuration Format
29+
30+
The configuration file contains an array of configuration entries. Each entry defines rules and options for matching files:
31+
32+
```jsonc
33+
[
34+
{
35+
"ignores": ["./dist/**", "./node_modules/**"],
36+
"languageOptions": {
37+
"parserOptions": {
38+
"project": ["./tsconfig.json"],
39+
},
40+
},
41+
"rules": {
42+
"@typescript-eslint/no-unused-vars": "error",
43+
"@typescript-eslint/array-type": ["warn", { "default": "array-simple" }],
44+
},
45+
"plugins": ["@typescript-eslint"],
46+
},
47+
]
48+
```
49+
50+
## Configuration Options
51+
52+
### ignores
53+
54+
- **Type:** `string[]`
55+
- **Default:** `[]`
56+
57+
An array of glob patterns for files and directories to ignore during linting.
58+
59+
```jsonc
60+
{
61+
"ignores": [
62+
"./dist/**",
63+
"./build/**",
64+
"./node_modules/**",
65+
"**/*.d.ts",
66+
"./tests/**/fixtures/**",
67+
],
68+
}
69+
```
70+
71+
Patterns support:
72+
73+
- **Glob patterns**: `*.js`, `**/*.ts`
74+
- **Directory patterns**: `dist/**`, `node_modules/**`
75+
- **Negation**: `!important.ts` (when used with other patterns)
76+
77+
### languageOptions
78+
79+
- **Type:** `object`
80+
- **Default:** `{}`
81+
82+
Language-specific configuration options.
83+
84+
#### languageOptions.parserOptions
85+
86+
- **Type:** `object`
87+
- **Default:** `{}`
88+
89+
Parser configuration for TypeScript analysis.
90+
91+
##### languageOptions.parserOptions.project
92+
93+
- **Type:** `string[]`
94+
- **Default:** `["./tsconfig.json"]`
95+
96+
Array of TypeScript project configuration files. Rslint will lint all files included in these TypeScript projects.
97+
98+
```jsonc
99+
{
100+
"languageOptions": {
101+
"parserOptions": {
102+
"project": [
103+
"./tsconfig.json",
104+
"./packages/*/tsconfig.json",
105+
"./apps/*/tsconfig.json",
106+
],
107+
},
108+
},
109+
}
110+
```
111+
112+
This is especially useful for monorepos where you have multiple TypeScript projects.
113+
114+
### rules
115+
116+
- **Type:** `object`
117+
- **Default:** `{}`
118+
119+
Configuration for linting rules. Rules can be configured in several formats:
120+
121+
#### String Format
122+
123+
```jsonc
124+
{
125+
"rules": {
126+
"@typescript-eslint/no-unused-vars": "error",
127+
"@typescript-eslint/prefer-const": "warn",
128+
"@typescript-eslint/no-explicit-any": "off",
129+
},
130+
}
131+
```
132+
133+
Valid severity levels:
134+
135+
- `"error"` - Rule violations cause linting to fail
136+
- `"warn"` - Rule violations produce warnings
137+
- `"off"` - Rule is disabled
138+
139+
#### Array Format
140+
141+
For rules that accept configuration options:
142+
143+
```jsonc
144+
{
145+
"rules": {
146+
"@typescript-eslint/array-type": ["error", { "default": "array-simple" }],
147+
"@typescript-eslint/no-unused-vars": [
148+
"warn",
149+
{
150+
"vars": "all",
151+
"args": "after-used",
152+
"ignoreRestSiblings": false,
153+
},
154+
],
155+
},
156+
}
157+
```
158+
159+
#### Object Format
160+
161+
Alternative object-based configuration:
162+
163+
```jsonc
164+
{
165+
"rules": {
166+
"@typescript-eslint/no-unused-vars": {
167+
"level": "error",
168+
"options": {
169+
"vars": "all",
170+
"args": "after-used",
171+
},
172+
},
173+
},
174+
}
175+
```
176+
177+
### plugins
178+
179+
- **Type:** `string[]`
180+
- **Default:** `[]`
181+
182+
Array of plugins to enable. When a plugin is enabled, all its implemented rules are automatically available with default configurations.
183+
184+
```jsonc
185+
{
186+
"plugins": ["@typescript-eslint", "eslint-plugin-import"],
187+
}
188+
```
189+
190+
#### Available Plugins
191+
192+
##### @typescript-eslint
193+
194+
Enables TypeScript-specific linting rules. This is the most commonly used plugin for TypeScript projects.
195+
196+
```jsonc
197+
{
198+
"plugins": ["@typescript-eslint"],
199+
"rules": {
200+
// TypeScript-specific rules are now available
201+
"@typescript-eslint/no-unused-vars": "error",
202+
"@typescript-eslint/prefer-const": "warn",
203+
},
204+
}
205+
```
206+
207+
##### eslint-plugin-import
208+
209+
Enables import/export related rules for better module management.
210+
211+
```jsonc
212+
{
213+
"plugins": ["eslint-plugin-import"],
214+
"rules": {
215+
// Import rules are now available
216+
"import/no-unresolved": "error",
217+
"import/order": "warn",
218+
},
219+
}
220+
```
221+
222+
## Complete Example
223+
224+
Here's a comprehensive configuration example for a typical TypeScript project:
225+
226+
```jsonc
227+
[
228+
{
229+
// Ignore build outputs and dependencies
230+
"ignores": [
231+
"./dist/**",
232+
"./build/**",
233+
"./node_modules/**",
234+
"./coverage/**",
235+
"**/*.d.ts",
236+
"./tests/**/fixtures/**",
237+
],
238+
239+
// TypeScript project configuration
240+
"languageOptions": {
241+
"parserOptions": {
242+
"project": ["./tsconfig.json", "./packages/*/tsconfig.json"],
243+
},
244+
},
245+
246+
// Enable TypeScript plugin
247+
"plugins": ["@typescript-eslint"],
248+
249+
// Rule configuration
250+
"rules": {
251+
// Variable and import rules
252+
"@typescript-eslint/no-unused-vars": [
253+
"error",
254+
{
255+
"vars": "all",
256+
"args": "after-used",
257+
"argsIgnorePattern": "^_",
258+
"varsIgnorePattern": "^_",
259+
},
260+
],
261+
262+
// Type safety rules
263+
"@typescript-eslint/no-unsafe-argument": "error",
264+
"@typescript-eslint/no-unsafe-assignment": "error",
265+
"@typescript-eslint/no-unsafe-call": "error",
266+
"@typescript-eslint/no-unsafe-member-access": "error",
267+
"@typescript-eslint/no-unsafe-return": "error",
268+
"@typescript-eslint/await-thenable": "error",
269+
270+
// Code style rules
271+
"@typescript-eslint/array-type": ["warn", { "default": "array-simple" }],
272+
"@typescript-eslint/prefer-const": "error",
273+
"@typescript-eslint/no-unnecessary-type-assertion": "warn",
274+
275+
// Async/Promise rules
276+
"@typescript-eslint/no-floating-promises": [
277+
"error",
278+
{ "ignoreVoid": true },
279+
],
280+
"@typescript-eslint/require-await": "warn",
281+
"@typescript-eslint/return-await": ["error", "always"],
282+
283+
// Best practices
284+
"@typescript-eslint/no-empty-function": [
285+
"error",
286+
{ "allow": ["constructors"] },
287+
],
288+
"@typescript-eslint/no-empty-interface": "error",
289+
"@typescript-eslint/prefer-as-const": "error",
290+
},
291+
},
292+
]
293+
```

0 commit comments

Comments
 (0)