Skip to content

Commit 6c0e0b5

Browse files
committed
docs(linter): Add oxlint.config.ts to the config docs. (#19941)
Previously we were not showing the `oxlint.config.ts` format at all in the config reference docs. This at least fixes that and removes an inaccurate warning message. Helps fix part of oxc-project/website#950
1 parent d40a942 commit 6c0e0b5

File tree

5 files changed

+116
-26
lines changed

5 files changed

+116
-26
lines changed

apps/oxlint/src-js/package/config.generated.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,7 @@ export type CustomComponent =
9090
*
9191
* This configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).
9292
*
93-
* Usage: `oxlint -c oxlintrc.json --import-plugin`
94-
*
95-
* ::: danger NOTE
96-
*
97-
* Only the `.json` format is supported. You can use comments in configuration files.
98-
*
99-
* :::
93+
* Usage: `oxlint -c oxlintrc.json`
10094
*
10195
* Example
10296
*
@@ -133,6 +127,42 @@ export type CustomComponent =
133127
* ]
134128
* }
135129
* ```
130+
*
131+
* `oxlint.config.ts`
132+
*
133+
* ```ts
134+
* import { defineConfig } from "oxlint";
135+
*
136+
* export default defineConfig({
137+
* plugins: ["import", "typescript", "unicorn"],
138+
* env: {
139+
* "browser": true
140+
* },
141+
* globals: {
142+
* "foo": "readonly"
143+
* },
144+
* settings: {
145+
* react: {
146+
* version: "18.2.0"
147+
* },
148+
* custom: { option: true }
149+
* },
150+
* rules: {
151+
* "eqeqeq": "warn",
152+
* "import/no-cycle": "error",
153+
* "react/self-closing-comp": ["error", { "html": false }]
154+
* },
155+
* overrides: [
156+
* {
157+
* files: ["*.test.ts", "*.spec.ts"],
158+
* rules: {
159+
* "@typescript-eslint/no-explicit-any": "off"
160+
* }
161+
* }
162+
* ]
163+
* }
164+
* });
165+
* ```
136166
*/
137167
export interface Oxlintrc {
138168
/**

crates/oxc_linter/src/config/oxlintrc.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,7 @@ impl OxlintOptions {
7676
///
7777
/// This configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).
7878
///
79-
/// Usage: `oxlint -c oxlintrc.json --import-plugin`
80-
///
81-
/// ::: danger NOTE
82-
///
83-
/// Only the `.json` format is supported. You can use comments in configuration files.
84-
///
85-
/// :::
79+
/// Usage: `oxlint -c oxlintrc.json`
8680
///
8781
/// Example
8882
///
@@ -119,6 +113,42 @@ impl OxlintOptions {
119113
/// ]
120114
/// }
121115
/// ```
116+
///
117+
/// `oxlint.config.ts`
118+
///
119+
/// ```ts
120+
/// import { defineConfig } from "oxlint";
121+
///
122+
/// export default defineConfig({
123+
/// plugins: ["import", "typescript", "unicorn"],
124+
/// env: {
125+
/// "browser": true
126+
/// },
127+
/// globals: {
128+
/// "foo": "readonly"
129+
/// },
130+
/// settings: {
131+
/// react: {
132+
/// version: "18.2.0"
133+
/// },
134+
/// custom: { option: true }
135+
/// },
136+
/// rules: {
137+
/// "eqeqeq": "warn",
138+
/// "import/no-cycle": "error",
139+
/// "react/self-closing-comp": ["error", { "html": false }]
140+
/// },
141+
/// overrides: [
142+
/// {
143+
/// files: ["*.test.ts", "*.spec.ts"],
144+
/// rules: {
145+
/// "@typescript-eslint/no-explicit-any": "off"
146+
/// }
147+
/// }
148+
/// ]
149+
/// }
150+
/// });
151+
/// ```
122152
#[derive(Debug, Default, Clone, Deserialize, Serialize, JsonSchema)]
123153
#[serde(default, deny_unknown_fields)]
124154
#[non_exhaustive]

npm/oxlint/configuration_schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "Oxlintrc",
4-
"description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```",
4+
"description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```\n\n`oxlint.config.ts`\n\n```ts\nimport { defineConfig } from \"oxlint\";\n\nexport default defineConfig({\nplugins: [\"import\", \"typescript\", \"unicorn\"],\nenv: {\n\"browser\": true\n},\nglobals: {\n\"foo\": \"readonly\"\n},\nsettings: {\nreact: {\nversion: \"18.2.0\"\n},\ncustom: { option: true }\n},\nrules: {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\noverrides: [\n{\nfiles: [\"*.test.ts\", \"*.spec.ts\"],\nrules: {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n});\n```",
55
"type": "object",
66
"properties": {
77
"$schema": {
@@ -784,5 +784,5 @@
784784
"markdownDescription": "Configure Vitest plugin rules.\n\nSee [eslint-plugin-vitest](https://github.com/vitest-dev/eslint-plugin-vitest)'s\nconfiguration for a full reference."
785785
}
786786
},
787-
"markdownDescription": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```"
788-
}
787+
"markdownDescription": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```\n\n`oxlint.config.ts`\n\n```ts\nimport { defineConfig } from \"oxlint\";\n\nexport default defineConfig({\nplugins: [\"import\", \"typescript\", \"unicorn\"],\nenv: {\n\"browser\": true\n},\nglobals: {\n\"foo\": \"readonly\"\n},\nsettings: {\nreact: {\nversion: \"18.2.0\"\n},\ncustom: { option: true }\n},\nrules: {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\noverrides: [\n{\nfiles: [\"*.test.ts\", \"*.spec.ts\"],\nrules: {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n});\n```"
788+
}

tasks/website_linter/src/snapshots/schema_json.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ expression: json
55
{
66
"$schema": "http://json-schema.org/draft-07/schema#",
77
"title": "Oxlintrc",
8-
"description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```",
8+
"description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```\n\n`oxlint.config.ts`\n\n```ts\nimport { defineConfig } from \"oxlint\";\n\nexport default defineConfig({\nplugins: [\"import\", \"typescript\", \"unicorn\"],\nenv: {\n\"browser\": true\n},\nglobals: {\n\"foo\": \"readonly\"\n},\nsettings: {\nreact: {\nversion: \"18.2.0\"\n},\ncustom: { option: true }\n},\nrules: {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\noverrides: [\n{\nfiles: [\"*.test.ts\", \"*.spec.ts\"],\nrules: {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n});\n```",
99
"type": "object",
1010
"properties": {
1111
"$schema": {
@@ -788,5 +788,5 @@ expression: json
788788
"markdownDescription": "Configure Vitest plugin rules.\n\nSee [eslint-plugin-vitest](https://github.com/vitest-dev/eslint-plugin-vitest)'s\nconfiguration for a full reference."
789789
}
790790
},
791-
"markdownDescription": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```"
791+
"markdownDescription": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```\n\n`oxlint.config.ts`\n\n```ts\nimport { defineConfig } from \"oxlint\";\n\nexport default defineConfig({\nplugins: [\"import\", \"typescript\", \"unicorn\"],\nenv: {\n\"browser\": true\n},\nglobals: {\n\"foo\": \"readonly\"\n},\nsettings: {\nreact: {\nversion: \"18.2.0\"\n},\ncustom: { option: true }\n},\nrules: {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\noverrides: [\n{\nfiles: [\"*.test.ts\", \"*.spec.ts\"],\nrules: {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n});\n```"
792792
}

tasks/website_linter/src/snapshots/schema_markdown.snap

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@ search: false
1010

1111
This configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).
1212

13-
Usage: `oxlint -c oxlintrc.json --import-plugin`
14-
15-
::: danger NOTE
16-
17-
Only the `.json` format is supported. You can use comments in configuration files.
18-
19-
:::
13+
Usage: `oxlint -c oxlintrc.json`
2014

2115
Example
2216

@@ -68,6 +62,42 @@ Example
6862
}
6963
```
7064

65+
`oxlint.config.ts`
66+
67+
```ts
68+
import { defineConfig } from "oxlint";
69+
70+
export default defineConfig({
71+
plugins: ["import", "typescript", "unicorn"],
72+
env: {
73+
"browser": true
74+
},
75+
globals: {
76+
"foo": "readonly"
77+
},
78+
settings: {
79+
react: {
80+
version: "18.2.0"
81+
},
82+
custom: { option: true }
83+
},
84+
rules: {
85+
"eqeqeq": "warn",
86+
"import/no-cycle": "error",
87+
"react/self-closing-comp": ["error", { "html": false }]
88+
},
89+
overrides: [
90+
{
91+
files: ["*.test.ts", "*.spec.ts"],
92+
rules: {
93+
"@typescript-eslint/no-explicit-any": "off"
94+
}
95+
}
96+
]
97+
}
98+
});
99+
```
100+
71101

72102
## $schema
73103

0 commit comments

Comments
 (0)