Skip to content

Commit d690060

Browse files
fix(linter): fix the auto-fix issue of the eslint/no-plusplus rule (#10469)
1 parent ac23773 commit d690060

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

crates/oxc_linter/src/rules/eslint/no_plusplus.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use oxc_ast::{AstKind, ast::UpdateOperator};
22
use oxc_diagnostics::OxcDiagnostic;
33
use oxc_macros::declare_oxc_lint;
4-
use oxc_span::Span;
4+
use oxc_span::{GetSpan, Span};
55

66
use crate::{AstNode, context::LintContext, rule::Rule};
77

@@ -107,15 +107,15 @@ impl Rule for NoPlusplus {
107107
}
108108

109109
let ident = expr.argument.get_identifier_name();
110-
111-
if let Some(ident) = ident {
110+
if ident.is_some() {
112111
let operator = match expr.operator {
113112
UpdateOperator::Increment => "+=",
114113
UpdateOperator::Decrement => "-=",
115114
};
115+
let source = expr.argument.span().source_text(ctx.source_text());
116116
ctx.diagnostic_with_suggestion(
117117
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")),
119119
);
120120
} else {
121121
ctx.diagnostic(no_plusplus_diagnostic(expr.span, expr.operator));
@@ -265,6 +265,7 @@ fn test() {
265265
"let x = 0; let y = { foo: x += 1 };",
266266
None,
267267
),
268+
("a.b++;", "a.b += 1;", None),
268269
];
269270

270271
Tester::new(NoPlusplus::NAME, NoPlusplus::PLUGIN, pass, fail)

0 commit comments

Comments
 (0)