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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"options": {
"reportUnusedDisableDirectives": "warn"
},
"rules": {
"no-console": "warn",
"no-debugger": "warn"
}
}
2 changes: 1 addition & 1 deletion apps/oxlint/src-js/package/config.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ export interface OxlintGlobals {
*/
export interface OxlintOptions {
/**
* Report unused disable directives (e.g. `// eslint-disable-line`).
* Report unused disable directives (e.g. `// oxlint-disable-line` or `// eslint-disable-line`).
*
* Equivalent to passing `--report-unused-disable-directives-severity` on the CLI.
* CLI flags take precedence over this value when both are set.
Expand Down
31 changes: 29 additions & 2 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,17 @@ impl CliRunner {

let config_store = ConfigStore::new(lint_config, nested_configs, external_plugin_store);

// Only propagate Warn/Deny; treat Allow (off) as disabling reports.
let report_unused_directives = match inline_config_options.report_unused_directives {
ReportUnusedDirectives::WithoutSeverity(true) => Some(AllowWarnDeny::Warn),
ReportUnusedDirectives::WithSeverity(Some(severity)) => Some(severity),
_ => config_store.report_unused_disable_directives(),
ReportUnusedDirectives::WithSeverity(Some(severity)) if severity.is_warn_deny() => {
Some(severity)
}
ReportUnusedDirectives::WithSeverity(Some(_)) => None,
_ => match config_store.report_unused_disable_directives() {
Some(severity) if severity.is_warn_deny() => Some(severity),
_ => None,
},
};
let type_aware = self.options.type_aware || config_store.type_aware_enabled();
let type_check = self.options.type_check || config_store.type_check_enabled();
Expand Down Expand Up @@ -1053,6 +1060,26 @@ mod test {
Tester::new().with_cwd("fixtures/report_unused_directives".into()).test_and_snapshot(args);
}

#[test]
fn test_report_unused_directives_from_config() {
// Verify that `reportUnusedDisableDirectives` in the config file enables reporting
// without needing a CLI flag.
let args = &["-c", ".oxlintrc-with-rudd.json"];

Tester::new().with_cwd("fixtures/report_unused_directives".into()).test_and_snapshot(args);
}

#[test]
fn test_report_unused_directives_cli_overrides_config() {
// Verify that the CLI flag takes precedence over the config file value.
// Config has `reportUnusedDisableDirectives: "warn"`, but CLI passes `off`,
// so no unused-directive diagnostics should be reported.
let args =
&["-c", ".oxlintrc-with-rudd.json", "--report-unused-disable-directives-severity=off"];

Tester::new().with_cwd("fixtures/report_unused_directives".into()).test_and_snapshot(args);
}

#[test]
fn test_nested_config() {
let args = &[];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: -c .oxlintrc-with-rudd.json --report-unused-disable-directives-severity=off
working directory: fixtures/report_unused_directives
----------

! eslint(no-console): Unexpected console statement.
,-[test-multiple-scripts.vue:7:1]
6 | // eslint-disable-next-line no-debugger
7 | console.log('regular script');
: ^^^^^^^^^^^
8 |
`----
help: Delete this console statement.

! eslint(no-debugger): `debugger` statement is not allowed
,-[test-multiple-scripts.vue:10:1]
9 | // eslint-disable-next-line no-console
10 | debugger;
: ^^^^^^^^^
11 | </script>
`----
help: Remove the debugger statement

! eslint(no-console): Unexpected console statement.
,-[test-multiple-scripts.vue:31:1]
30 | // oxlint-disable-next-line no-debugger, no-for-loop
31 | console.log("complete line");
: ^^^^^^^^^^^
32 |
`----
help: Delete this console statement.

! eslint(no-debugger): `debugger` statement is not allowed
,-[test.astro:11:1]
10 | // eslint-disable-next-line no-console
11 | debugger;
: ^^^^^^^^^
12 | ---
`----
help: Remove the debugger statement

! eslint(no-console): Unexpected console statement.
,-[test.astro:32:1]
31 | // oxlint-disable-next-line no-debugger, no-for-loop
32 | console.log("complete line");
: ^^^^^^^^^^^
33 |
`----
help: Delete this console statement.

! eslint(no-debugger): `debugger` statement is not allowed
,-[test.js:10:1]
9 | // eslint-disable-next-line no-console
10 | debugger;
: ^^^^^^^^^
11 |
`----
help: Remove the debugger statement

! eslint(no-console): Unexpected console statement.
,-[test.js:27:1]
26 | // oxlint-disable-next-line no-debugger, no-for-loop
27 | console.log("complete line");
: ^^^^^^^^^^^
28 |
`----
help: Delete this console statement.

! eslint(no-debugger): `debugger` statement is not allowed
,-[test.svelte:11:1]
10 | // eslint-disable-next-line no-console
11 | debugger;
: ^^^^^^^^^
12 |
`----
help: Remove the debugger statement

! eslint(no-console): Unexpected console statement.
,-[test.svelte:28:1]
27 | // oxlint-disable-next-line no-debugger, no-for-loop
28 | console.log("complete line");
: ^^^^^^^^^^^
29 |
`----
help: Delete this console statement.

! eslint(no-debugger): `debugger` statement is not allowed
,-[test.vue:15:1]
14 | // eslint-disable-next-line no-console
15 | debugger;
: ^^^^^^^^^
16 |
`----
help: Remove the debugger statement

! eslint(no-console): Unexpected console statement.
,-[test.vue:32:1]
31 | // oxlint-disable-next-line no-debugger, no-for-loop
32 | console.log("complete line");
: ^^^^^^^^^^^
33 |
`----
help: Delete this console statement.

Found 11 warnings and 0 errors.
Finished in <variable>ms on 5 files with 94 rules using 1 threads.
----------
CLI result: LintSucceeded
----------
Loading
Loading