From a671d754dfeed0db13397af09d68a3a41d596094 Mon Sep 17 00:00:00 2001 From: Jose <48152124+JoSeBu1@users.noreply.github.com> Date: Tue, 19 Mar 2024 05:16:30 +0100 Subject: [PATCH] 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 --- crates/oxc_linter/src/rules/eslint/guard_for_in.rs | 4 ++-- crates/oxc_linter/src/snapshots/guard_for_in.snap | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/oxc_linter/src/rules/eslint/guard_for_in.rs b/crates/oxc_linter/src/rules/eslint/guard_for_in.rs index 526709178..34ddcf2fc 100644 --- a/crates/oxc_linter/src/rules/eslint/guard_for_in.rs +++ b/crates/oxc_linter/src/rules/eslint/guard_for_in.rs @@ -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, ))); } } diff --git a/crates/oxc_linter/src/snapshots/guard_for_in.snap b/crates/oxc_linter/src/snapshots/guard_for_in.snap index 6743d969c..8ec591f3d 100644 --- a/crates/oxc_linter/src/snapshots/guard_for_in.snap +++ b/crates/oxc_linter/src/snapshots/guard_for_in.snap @@ -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.