From d6b84ec44e874fb5084b510cb9c0dbbc0334c5df Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Wed, 28 Aug 2024 02:14:38 +0000 Subject: [PATCH] fix(linter) bug in fixer for `no-null` (#5273) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit i tested this in the microsoft/vscode repo and there were no syntax errors after running the fixer 🎉 hopefully this is the last fix. --- .../oxc_linter/src/rules/unicorn/no_null.rs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/oxc_linter/src/rules/unicorn/no_null.rs b/crates/oxc_linter/src/rules/unicorn/no_null.rs index 259413d03..3207caf38 100644 --- a/crates/oxc_linter/src/rules/unicorn/no_null.rs +++ b/crates/oxc_linter/src/rules/unicorn/no_null.rs @@ -202,13 +202,18 @@ impl Rule for NoNull { let mut null_span = null_literal.span; // Find the last parent that is a TSAsExpression (`null as any`) or TSNonNullExpression (`null!`) for parent in ctx.nodes().iter_parents(node.id()).skip(1) { + let parent = parent.kind(); if matches!( - parent.kind(), + parent, AstKind::TSAsExpression(_) | AstKind::TSNonNullExpression(_) ) { - null_span = parent.kind().span(); + null_span = parent.span(); + } + if matches!(parent, AstKind::ReturnStatement(_)) { + break; } } + fixer.delete(&null_span) }); } @@ -381,6 +386,27 @@ fn test() { ), ("() => { return null! }", "() => { return }", None), ("() => { return null as any as typeof Array }", "() => { return }", None), + ( + r"const newDecorations = enabled ? + this._debugService.getModel().getBreakpoints().map(breakpoint => { + const parsed = test() + if (!parsed ) { + return null; + } + return { handle: parsed.handle}; + }).filter(x => !!x) as INotebookDeltaDecoration[] + : [];", + r"const newDecorations = enabled ? + this._debugService.getModel().getBreakpoints().map(breakpoint => { + const parsed = test() + if (!parsed ) { + return ; + } + return { handle: parsed.handle}; + }).filter(x => !!x) as INotebookDeltaDecoration[] + : [];", + None, + ), ]; Tester::new(NoNull::NAME, pass, fail).expect_fix(fix).test_and_snapshot(); }