Skip to content

Commit c44dac0

Browse files
committed
feat(linter): add support for extends property in oxlintrc
1 parent 28d9e68 commit c44dac0

5 files changed

Lines changed: 49 additions & 1 deletion

File tree

crates/oxc_linter/src/config/config_builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl ConfigStoreBuilder {
9393
overrides,
9494
path,
9595
ignore_patterns: _,
96+
extends: _,
9697
} = oxlintrc;
9798

9899
let config = LintConfig { plugins, settings, env, globals, path: Some(path) };

crates/oxc_linter/src/config/oxlintrc.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ pub struct Oxlintrc {
9595
/// Globs to ignore during linting. These are resolved from the configuration file path.
9696
#[serde(rename = "ignorePatterns")]
9797
pub ignore_patterns: Vec<String>,
98+
/// Paths of configuration files that this configuration file extends (inherits from). The files
99+
/// are resolved relative to the location of the configuration file that contains the `extends`
100+
/// property. The configuration files are merged from the first to the last, with the last file
101+
/// overriding the previous ones.
102+
#[serde(skip_serializing_if = "Vec::is_empty")]
103+
pub extends: Vec<PathBuf>,
98104
}
99105

100106
impl Oxlintrc {
@@ -155,6 +161,7 @@ mod test {
155161
assert_eq!(config.settings, OxlintSettings::default());
156162
assert_eq!(config.env, OxlintEnv::default());
157163
assert_eq!(config.path, PathBuf::default());
164+
assert_eq!(config.extends, Vec::<PathBuf>::default());
158165
}
159166

160167
#[test]
@@ -184,4 +191,23 @@ mod test {
184191
serde_json::from_str(r#"{ "plugins": ["typescript", "@typescript-eslint"] }"#).unwrap();
185192
assert_eq!(config.plugins, LintPlugins::TYPESCRIPT);
186193
}
194+
195+
#[test]
196+
fn test_oxlintrc_extends() {
197+
let config: Oxlintrc = serde_json::from_str(
198+
r#"{"extends": [".oxlintrc.json", "./oxlint-ts.json", "../.config/.oxlintrc.json"]}"#,
199+
)
200+
.unwrap();
201+
assert_eq!(
202+
config.extends,
203+
vec![
204+
PathBuf::from(".oxlintrc.json"),
205+
PathBuf::from("./oxlint-ts.json"),
206+
PathBuf::from("../.config/.oxlintrc.json")
207+
]
208+
);
209+
210+
let config: Oxlintrc = serde_json::from_str(r#"{"extends": []}"#).unwrap();
211+
assert_eq!(0, config.extends.len());
212+
}
187213
}

crates/oxc_linter/src/snapshots/schema_json.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ expression: json
2727
}
2828
]
2929
},
30+
"extends": {
31+
"description": "Paths of configuration files that this configuration file extends (inherits from). The files are resolved relative to the location of the configuration file that contains the `extends` property. The configuration files are merged from the first to the last, with the last file overriding the previous ones.",
32+
"type": "array",
33+
"items": {
34+
"type": "string"
35+
}
36+
},
3037
"globals": {
3138
"description": "Enabled or disabled specific global variables.",
3239
"default": {},

npm/oxlint/configuration_schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
}
2424
]
2525
},
26+
"extends": {
27+
"description": "Paths of configuration files that this configuration file extends (inherits from). The files are resolved relative to the location of the configuration file that contains the `extends` property. The configuration files are merged from the first to the last, with the last file overriding the previous ones.",
28+
"type": "array",
29+
"items": {
30+
"type": "string"
31+
}
32+
},
2633
"globals": {
2734
"description": "Enabled or disabled specific global variables.",
2835
"default": {},

tasks/website/src/linter/snapshots/schema_markdown.snap

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
source: tasks/website/src/linter/json_schema.rs
33
expression: snapshot
4-
snapshot_kind: text
54
---
65
# Oxlint Configuration File
76

@@ -135,6 +134,14 @@ Predefine global variables.
135134
Environments specify what global variables are predefined. See [ESLint's list of environments](https://eslint.org/docs/v8.x/use/configure/language-options#specifying-environments) for what environments are available and what each one provides.
136135

137136

137+
## extends
138+
139+
type: `string[]`
140+
141+
142+
Paths of configuration files that this configuration file extends (inherits from). The files are resolved relative to the location of the configuration file that contains the `extends` property. The configuration files are merged from the first to the last, with the last file overriding the previous ones.
143+
144+
138145
## globals
139146

140147
type: `Record<string, string>`

0 commit comments

Comments
 (0)