Skip to content

Commit

Permalink
fix(linter): add missing error message prefix to `eslint/no-const-ass…
Browse files Browse the repository at this point in the history
…ign`
  • Loading branch information
Boshen committed Nov 28, 2024
1 parent d5a2161 commit cc078d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
5 changes: 4 additions & 1 deletion crates/oxc_linter/src/rules/eslint/no_const_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use oxc_span::Span;
use crate::{context::LintContext, rule::Rule};

fn no_const_assign_diagnostic(name: &str, decl_span: Span, assign_span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Unexpected re-assignment of const variable {name}")).with_labels([
OxcDiagnostic::warn(format!(
"eslint(no-const-assign): Unexpected re-assignment of const variable {name}"
))
.with_labels([
decl_span.label(format!("{name} is declared here as const")),
assign_span.label(format!("{name} is re-assigned here")),
])
Expand Down
34 changes: 17 additions & 17 deletions crates/oxc_linter/src/snapshots/eslint_no_const_assign.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,135 +2,135 @@
source: crates/oxc_linter/src/tester.rs
snapshot_kind: text
---
eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; x = 1;
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:11]
1const {a: x} = {a: 0}; x = 1;
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; ({x} = {x: 1});
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; ({a: x = 1} = {});
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; x += 1;
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; ++x;
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable i
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable i
╭─[no_const_assign.tsx:1:12]
1for (const i = 0; i < 10; ++i) { foo(i); }
· ┬ ┬
· │ ╰── i is re-assigned here
· ╰── i is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; x = 1; x = 2;
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; x = 1; x = 2;
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; function foo() { x = x + 1; }
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; function foo(a) { x = a; }
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; while (true) { x = x + 1; }
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:7]
1const x = 0; function foo(a) { function bar(b) { x = b; } bar(123); }
· ┬ ┬
· │ ╰── x is re-assigned here
· ╰── x is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable x
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable x
╭─[no_const_assign.tsx:1:1]
1x = 123; const x = 1;
· ┬ ┬
· │ ╰── x is declared here as const
· ╰── x is re-assigned here
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable d
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable d
╭─[no_const_assign.tsx:1:24]
1const [a, b, ...[c, ...d]] = [1, 2, 3, 4, 5]; d = 123
· ┬ ┬
· │ ╰── d is re-assigned here
· ╰── d is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable d
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable d
╭─[no_const_assign.tsx:1:7]
1const d = 123; [a, b, ...[c, ...d]] = [1, 2, 3, 4, 5]
· ┬ ┬
· │ ╰── d is re-assigned here
· ╰── d is declared here as const
╰────

eslint(no-const-assign): Unexpected re-assignment of const variable b
eslint(no-const-assign): eslint(no-const-assign): Unexpected re-assignment of const variable b
╭─[no_const_assign.tsx:1:7]
1const b = 0; ({a, ...b} = {a: 1, c: 2, d: 3})
· ┬ ┬
Expand Down

0 comments on commit cc078d6

Please sign in to comment.