Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/oxc_linter/src/config/config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl ConfigStoreBuilder {
overrides,
path,
ignore_patterns: _,
extends: _,
} = oxlintrc;

let config = LintConfig { plugins, settings, env, globals, path: Some(path) };
Expand Down
26 changes: 26 additions & 0 deletions crates/oxc_linter/src/config/oxlintrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ pub struct Oxlintrc {
/// Globs to ignore during linting. These are resolved from the configuration file path.
#[serde(rename = "ignorePatterns")]
pub ignore_patterns: Vec<String>,
/// 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.
#[serde(skip_serializing_if = "Vec::is_empty")]
pub extends: Vec<PathBuf>,
}

impl Oxlintrc {
Expand Down Expand Up @@ -156,6 +162,7 @@ mod test {
assert_eq!(config.settings, OxlintSettings::default());
assert_eq!(config.env, OxlintEnv::default());
assert_eq!(config.path, PathBuf::default());
assert_eq!(config.extends, Vec::<PathBuf>::default());
}

#[test]
Expand Down Expand Up @@ -185,4 +192,23 @@ mod test {
serde_json::from_str(r#"{ "plugins": ["typescript", "@typescript-eslint"] }"#).unwrap();
assert_eq!(config.plugins, LintPlugins::TYPESCRIPT);
}

#[test]
fn test_oxlintrc_extends() {
let config: Oxlintrc = serde_json::from_str(
r#"{"extends": [".oxlintrc.json", "./oxlint-ts.json", "../.config/.oxlintrc.json"]}"#,
)
.unwrap();
assert_eq!(
config.extends,
vec![
PathBuf::from(".oxlintrc.json"),
PathBuf::from("./oxlint-ts.json"),
PathBuf::from("../.config/.oxlintrc.json")
]
);

let config: Oxlintrc = serde_json::from_str(r#"{"extends": []}"#).unwrap();
assert_eq!(0, config.extends.len());
}
}
7 changes: 7 additions & 0 deletions crates/oxc_linter/src/snapshots/schema_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ expression: json
}
]
},
"extends": {
"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.",
"type": "array",
"items": {
"type": "string"
}
},
"globals": {
"description": "Enabled or disabled specific global variables.",
"default": {},
Expand Down
7 changes: 7 additions & 0 deletions npm/oxlint/configuration_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
}
]
},
"extends": {
"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.",
"type": "array",
"items": {
"type": "string"
}
},
"globals": {
"description": "Enabled or disabled specific global variables.",
"default": {},
Expand Down
8 changes: 8 additions & 0 deletions tasks/website/src/linter/snapshots/schema_markdown.snap
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ Predefine global variables.
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.


## extends

type: `string[]`


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.


## globals

type: `Record<string, string>`
Expand Down
Loading