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
15 changes: 12 additions & 3 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
));
Expand Down
19 changes: 19 additions & 0 deletions napi/oxlint2/test/__snapshots__/e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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."
`;
9 changes: 9 additions & 0 deletions napi/oxlint2/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"plugins": ["./test_plugin"],
"rules": {
"basic-custom-plugin/no-debugger": "warn"
},
"ignorePatterns": ["test_plugin"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugger;
Original file line number Diff line number Diff line change
@@ -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,
});
},
};
},
},
},
};
Loading