diff --git a/crates/oxc_linter/src/lib.rs b/crates/oxc_linter/src/lib.rs index b0482861f7ac1..bf751b287f7f0 100644 --- a/crates/oxc_linter/src/lib.rs +++ b/crates/oxc_linter/src/lib.rs @@ -274,9 +274,18 @@ impl Linter { // TODO: `error` isn't right, we need to get the severity from `external_rules` OxcDiagnostic::error(diagnostic.message) .with_label(Span::new(diagnostic.loc.start, diagnostic.loc.end)) - .with_error_code( - plugin_name.to_string(), - rule_name.to_string(), + .with_error_code(plugin_name.to_string(), rule_name.to_string()) + .with_severity( + (*external_rules + .iter() + .find(|(rule_id, _)| { + rule_id.raw() == diagnostic.external_rule_id + }) + .map(|(_, severity)| severity) + .expect( + "external rule must exist when resolving severity", + )) + .into(), ), PossibleFixes::None, )); diff --git a/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap b/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap index e691005ab1d47..8f312d0978265 100644 --- a/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap +++ b/napi/oxlint2/test/__snapshots__/e2e.test.ts.snap @@ -336,3 +336,22 @@ exports[`oxlint2 CLI > should report an error if a rule is not found within a cu x Rule 'unknown-rule' not found in plugin 'basic-custom-plugin' " `; + +exports[`oxlint2 CLI > should report the correct severity when using a custom plugin 1`] = ` +" + ! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\\eslint(no-debugger)]8;;\\: \`debugger\` statement is not allowed + ,-[index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + \`---- + help: Remove the debugger statement + + ! basic-custom-plugin(no-debugger): Unexpected Debugger Statement + ,-[index.js:1:1] + 1 | debugger; + : ^^^^^^^^^ + \`---- + +Found 2 warnings and 0 errors. +Finished in Xms on 1 file using X threads." +`; diff --git a/napi/oxlint2/test/e2e.test.ts b/napi/oxlint2/test/e2e.test.ts index 2c8e4287e6c8d..ed5e33d7c7b82 100644 --- a/napi/oxlint2/test/e2e.test.ts +++ b/napi/oxlint2/test/e2e.test.ts @@ -83,4 +83,13 @@ describe('oxlint2 CLI', () => { expect(exitCode).toBe(1); expect(normalizeOutput(stdout)).toMatchSnapshot(); }); + + it('should report the correct severity when using a custom plugin', async () => { + const { stdout, exitCode } = await runOxlint( + 'test/fixtures/basic_custom_plugin_warn_severity', + ); + + expect(exitCode).toBe(0); + expect(normalizeOutput(stdout)).toMatchSnapshot(); + }); }); diff --git a/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/.oxlintrc.json b/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/.oxlintrc.json new file mode 100644 index 0000000000000..0abdbdceb0e25 --- /dev/null +++ b/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/.oxlintrc.json @@ -0,0 +1,7 @@ +{ + "plugins": ["./test_plugin"], + "rules": { + "basic-custom-plugin/no-debugger": "warn" + }, + "ignorePatterns": ["test_plugin"] +} diff --git a/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/index.js b/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/index.js new file mode 100644 index 0000000000000..eab74692130a6 --- /dev/null +++ b/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/index.js @@ -0,0 +1 @@ +debugger; diff --git a/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/test_plugin/index.js b/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/test_plugin/index.js new file mode 100644 index 0000000000000..d4e46f0bc4d7b --- /dev/null +++ b/napi/oxlint2/test/fixtures/basic_custom_plugin_warn_severity/test_plugin/index.js @@ -0,0 +1,19 @@ +export default { + meta: { + name: "basic-custom-plugin", + }, + rules: { + "no-debugger": { + create(context) { + return { + DebuggerStatement(debuggerStatement) { + context.report({ + message: "Unexpected Debugger Statement", + node: debuggerStatement, + }); + }, + }; + }, + }, + }, +};