mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter) bug in fixer for no-null (#5273)
i tested this in the microsoft/vscode repo and there were no syntax errors after running the fixer 🎉
hopefully this is the last fix.
This commit is contained in:
parent
e6fd52e2a6
commit
d6b84ec44e
1 changed files with 28 additions and 2 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue