fix(linter): fix guard_for_in span error (#2755)

As talked here
https://github.com/oxc-project/oxc/pull/2746#discussion_r1528145418
errors in guard_for_in could be improved so I attempted to improve it.

If anyone have a suggestion for the span element positions say me!

---------

Co-authored-by: j.buendia <j.buendia>
This commit is contained in:
Jose 2024-03-19 05:16:30 +01:00 committed by GitHub
parent 86d006e171
commit a671d754df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 8 deletions

View file

@ -5,7 +5,7 @@ use oxc_diagnostics::{
thiserror::Error,
};
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use oxc_span::{GetSpan, Span};
use crate::{context::LintContext, rule::Rule, AstNode};
@ -68,7 +68,7 @@ impl Rule for GuardForIn {
}
ctx.diagnostic(GuardForInDiagnostic(Span::new(
for_in_statement.span.start,
for_in_statement.span.end,
for_in_statement.right.span().end + 1,
)));
}
}

View file

@ -5,41 +5,41 @@ expression: guard_for_in
⚠ eslint(guard-for-in): Require `for-in` loops to include an `if` statement
╭─[guard_for_in.tsx:1:1]
1 │ for (var x in o) { if (x) { f(); continue; } g(); }
· ───────────────────────────────────────────────────
· ────────────────
╰────
help: The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
⚠ eslint(guard-for-in): Require `for-in` loops to include an `if` statement
╭─[guard_for_in.tsx:1:1]
1 │ for (var x in o) { if (x) { continue; f(); } g(); }
· ───────────────────────────────────────────────────
· ────────────────
╰────
help: The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
⚠ eslint(guard-for-in): Require `for-in` loops to include an `if` statement
╭─[guard_for_in.tsx:1:1]
1 │ for (var x in o) { if (x) { f(); } g(); }
· ─────────────────────────────────────────
· ────────────────
╰────
help: The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
⚠ eslint(guard-for-in): Require `for-in` loops to include an `if` statement
╭─[guard_for_in.tsx:1:1]
1 │ for (var x in o) { if (x) f(); g(); }
· ─────────────────────────────────────
· ────────────────
╰────
help: The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
⚠ eslint(guard-for-in): Require `for-in` loops to include an `if` statement
╭─[guard_for_in.tsx:1:1]
1 │ for (var x in o) { foo() }
· ──────────────────────────
· ────────────────
╰────
help: The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.
⚠ eslint(guard-for-in): Require `for-in` loops to include an `if` statement
╭─[guard_for_in.tsx:1:1]
1 │ for (var x in o) foo();
· ───────────────────────
· ────────────────
╰────
help: The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype.