From 2ac40c23cb95c2bd44a25e2f4bf0a2a225418145 Mon Sep 17 00:00:00 2001 From: Scott Carda Date: Thu, 12 Dec 2024 10:28:30 -0800 Subject: [PATCH] removed `set` from other code action, made code action more robust to different whitespace --- compiler/qsc_linter/src/lints/ast.rs | 11 +++++------ compiler/qsc_linter/src/lints/hir.rs | 2 +- compiler/qsc_linter/src/tests.rs | 10 +++++----- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/compiler/qsc_linter/src/lints/ast.rs b/compiler/qsc_linter/src/lints/ast.rs index f0a1cb2d24..2840770733 100644 --- a/compiler/qsc_linter/src/lints/ast.rs +++ b/compiler/qsc_linter/src/lints/ast.rs @@ -181,17 +181,16 @@ impl AstLintPass for DeprecatedSet { ExprKind::Assign(_, _) | ExprKind::AssignOp(_, _, _) | ExprKind::AssignUpdate(_, _, _) => { - if compilation.get_source_code(expr.span).starts_with("set ") { + if ["set ", "set\n", "set\r\n", "set\t"] + .iter() + .any(|s| compilation.get_source_code(expr.span).starts_with(s)) + { // If the `set` keyword is used, push a lint. let span = Span { lo: expr.span.lo, hi: expr.span.lo + 3, }; - let code_action_span = Span { - lo: span.lo, - hi: span.lo + 4, - }; - buffer.push(lint!(self, span, vec![(String::new(), code_action_span)])); + buffer.push(lint!(self, span, vec![(String::new(), span)])); } } _ => {} diff --git a/compiler/qsc_linter/src/lints/hir.rs b/compiler/qsc_linter/src/lints/hir.rs index ffbc70da13..cddb2d2019 100644 --- a/compiler/qsc_linter/src/lints/hir.rs +++ b/compiler/qsc_linter/src/lints/hir.rs @@ -222,7 +222,7 @@ impl HirLintPass for DeprecatedWithOperator { (compilation.indentation_at_offset(info.span.lo) + 4) as usize; let innermost_expr = compilation.get_source_code(expr.span); let mut new_expr = if info.is_w_eq { - format!("set {} = new {} {{\n", innermost_expr, info.ty_name) + format!("{} = new {} {{\n", innermost_expr, info.ty_name) } else { format!("new {} {{\n", info.ty_name) }; diff --git a/compiler/qsc_linter/src/tests.rs b/compiler/qsc_linter/src/tests.rs index cdc43516d6..1142284621 100644 --- a/compiler/qsc_linter/src/tests.rs +++ b/compiler/qsc_linter/src/tests.rs @@ -30,7 +30,7 @@ fn set_keyword_lint() { "", Span { lo: 71, - hi: 75, + hi: 74, }, ), ], @@ -494,23 +494,23 @@ fn deprecated_with_eq_op_for_structs() { struct Foo { x : Int } function Bar() : Foo { mutable foo = new Foo { x = 2 }; - set foo w/= x <- 3; + foo w/= x <- 3; foo } "}, &expect![[r#" [ SrcLint { - source: "set foo w/= x <- 3", + source: "foo w/= x <- 3", level: Allow, message: "deprecated `w/` and `w/=` operators for structs", help: "`w/` and `w/=` operators for structs are deprecated, use `new` instead", code_action_edits: [ ( - "set foo = new Foo {\n ...foo,\n x = 3,\n }", + "foo = new Foo {\n ...foo,\n x = 3,\n }", Span { lo: 115, - hi: 133, + hi: 129, }, ), ],