Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "check-typecheck-extends",
"version": "0.0.0",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[case]]
name = "check_typecheck_extends"
vp = "local"
env = { VITE_DISABLE_AUTO_INSTALL = "1" }
steps = [
{ argv = ["vp", "check", "--no-fmt", "--no-lint"], continue-on-failure = true },
{ argv = ["vp", "check", "--no-lint"], continue-on-failure = true },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# check_typecheck_extends

## `vp check --no-fmt --no-lint`

```
pass: Found no type errors in 2 files (<duration>, <n> threads)
```

## `vp check --no-lint`

```
pass: All 3 files are correctly formatted (<duration>, <n> threads)
pass: Found no type errors in 2 files (<duration>, <n> threads)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const value: number = 42;
export { value };
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const base = {
options: {
typeAware: true,
},
};

export default {
lint: {
extends: [base],
options: {
typeCheck: true,
},
},
};
38 changes: 36 additions & 2 deletions packages/cli/binding/src/check/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,21 @@ impl LintMessageKind {
/// `typeCheck` requires `typeAware` as a prerequisite — oxlint's type-aware
/// analysis must be on for TypeScript diagnostics to surface.
pub(super) fn lint_config_type_check_enabled(lint_config: Option<&serde_json::Value>) -> bool {
let options = lint_config.and_then(|config| config.get("options"));
json_bool(options, "typeAware", false) && json_bool(options, "typeCheck", false)
let type_aware =
lint_config.and_then(|config| lint_config_option(config, "typeAware")).unwrap_or(false);
let type_check =
lint_config.and_then(|config| lint_config_option(config, "typeCheck")).unwrap_or(false);
type_aware && type_check
}

fn lint_config_option(config: &serde_json::Value, key: &str) -> Option<bool> {
if let Some(value) = config.get("options").and_then(|options| options.get(key)) {
return Some(value.as_bool().unwrap_or(false));
}

config.get("extends").and_then(serde_json::Value::as_array).and_then(|configs| {
configs.iter().filter_map(|config| lint_config_option(config, key)).last()
})
Comment thread
jong-kyung marked this conversation as resolved.
}

/// Read a boolean `key` from a JSON object, falling back to `default` when the
Expand Down Expand Up @@ -281,6 +294,27 @@ mod tests {
assert_eq!(kind.issue_heading(), "Type errors found");
}

#[test]
fn lint_config_type_check_resolves_extends() {
let config = json!({
"extends": [
{ "options": { "typeAware": false } },
{
"extends": [{ "options": { "typeAware": true } }],
"options": { "typeCheck": false }
}
],
"options": { "typeCheck": true }
});
assert!(lint_config_type_check_enabled(Some(&config)));

let config = json!({
"extends": [{ "options": { "typeAware": true, "typeCheck": true } }],
"options": { "typeAware": false }
});
assert!(!lint_config_type_check_enabled(Some(&config)));
}

#[test]
fn lint_config_type_check_enabled_rejects_non_bool_values() {
assert!(!lint_config_type_check_enabled(Some(&json!({
Expand Down
Loading