|
1 | 1 | use oxc_ast::{AstKind, ast::UpdateOperator}; |
2 | 2 | use oxc_diagnostics::OxcDiagnostic; |
3 | 3 | use oxc_macros::declare_oxc_lint; |
4 | | -use oxc_span::Span; |
| 4 | +use oxc_span::{GetSpan, Span}; |
5 | 5 |
|
6 | 6 | use crate::{AstNode, context::LintContext, rule::Rule}; |
7 | 7 |
|
@@ -107,15 +107,15 @@ impl Rule for NoPlusplus { |
107 | 107 | } |
108 | 108 |
|
109 | 109 | let ident = expr.argument.get_identifier_name(); |
110 | | - |
111 | | - if let Some(ident) = ident { |
| 110 | + if ident.is_some() { |
112 | 111 | let operator = match expr.operator { |
113 | 112 | UpdateOperator::Increment => "+=", |
114 | 113 | UpdateOperator::Decrement => "-=", |
115 | 114 | }; |
| 115 | + let source = expr.argument.span().source_text(ctx.source_text()); |
116 | 116 | ctx.diagnostic_with_suggestion( |
117 | 117 | no_plusplus_diagnostic(expr.span, expr.operator), |
118 | | - |fixer| fixer.replace(expr.span, format!("{ident} {operator} 1")), |
| 118 | + |fixer| fixer.replace(expr.span, format!("{source} {operator} 1")), |
119 | 119 | ); |
120 | 120 | } else { |
121 | 121 | ctx.diagnostic(no_plusplus_diagnostic(expr.span, expr.operator)); |
@@ -265,6 +265,7 @@ fn test() { |
265 | 265 | "let x = 0; let y = { foo: x += 1 };", |
266 | 266 | None, |
267 | 267 | ), |
| 268 | + ("a.b++;", "a.b += 1;", None), |
268 | 269 | ]; |
269 | 270 |
|
270 | 271 | Tester::new(NoPlusplus::NAME, NoPlusplus::PLUGIN, pass, fail) |
|
0 commit comments