From fb02855c6e3a5ead0c2a450a60b4788c811d1c1c Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Mon, 20 Nov 2023 17:51:44 +0100 Subject: [PATCH] fix(no_var): report diagnostic on var keyword (#1213) --- examples/dlint/testdata/issue1145_no_trailing_newline.out | 2 +- src/rules/no_var.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/dlint/testdata/issue1145_no_trailing_newline.out b/examples/dlint/testdata/issue1145_no_trailing_newline.out index 6fda401d8..45fe04a25 100644 --- a/examples/dlint/testdata/issue1145_no_trailing_newline.out +++ b/examples/dlint/testdata/issue1145_no_trailing_newline.out @@ -15,7 +15,7 @@ no-var ,-[issue1145_no_trailing_newline.ts:3:1] 3 | ---*/ 4 | var base - : ^^^^^^^^ + : ^^^ `---- help: https://lint.deno.land/#no-var diff --git a/src/rules/no_var.rs b/src/rules/no_var.rs index 9bac22ece..4110f18cd 100644 --- a/src/rules/no_var.rs +++ b/src/rules/no_var.rs @@ -2,8 +2,8 @@ use super::{Context, LintRule}; use crate::handler::{Handler, Traverse}; use crate::Program; -use deno_ast::view::{VarDecl, VarDeclKind}; -use deno_ast::SourceRanged; +use deno_ast::view::{NodeTrait, VarDecl, VarDeclKind}; +use deno_ast::SourceRangedForSpanned; #[derive(Debug)] pub struct NoVar; @@ -39,7 +39,8 @@ struct NoVarHandler; impl Handler for NoVarHandler { fn var_decl(&mut self, var_decl: &VarDecl, ctx: &mut Context) { if var_decl.decl_kind() == VarDeclKind::Var { - ctx.add_diagnostic(var_decl.range(), CODE, MESSAGE); + let range = var_decl.tokens().first().unwrap().range(); + ctx.add_diagnostic(range, CODE, MESSAGE); } } }