Skip to content

Commit

Permalink
removed set from other code action, made code action more robust to…
Browse files Browse the repository at this point in the history
… different whitespace
  • Loading branch information
ScottCarda-MS committed Dec 12, 2024
1 parent b609dc3 commit 2ac40c2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
11 changes: 5 additions & 6 deletions compiler/qsc_linter/src/lints/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]));
}
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/qsc_linter/src/lints/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down
10 changes: 5 additions & 5 deletions compiler/qsc_linter/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn set_keyword_lint() {
"",
Span {
lo: 71,
hi: 75,
hi: 74,
},
),
],
Expand Down Expand Up @@ -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,
},
),
],
Expand Down

0 comments on commit 2ac40c2

Please sign in to comment.