Skip to content

Commit

Permalink
fix(no_var): report diagnostic on var keyword (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacasonato authored Nov 20, 2023
1 parent 53a2219 commit fb02855
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/dlint/testdata/issue1145_no_trailing_newline.out
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ no-var
,-[issue1145_no_trailing_newline.ts:3:1]
3 | ---*/
4 | var base
: ^^^^^^^^
: ^^^
`----
help: https://lint.deno.land/#no-var

Expand Down
7 changes: 4 additions & 3 deletions src/rules/no_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit fb02855

Please sign in to comment.