mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(linter): getter-return false positive with TypeScript syntax (#2363)
closes #2349
This commit is contained in:
parent
ca77ccc951
commit
f49ffb2b63
1 changed files with 27 additions and 25 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use oxc_ast::{
|
||||
ast::{
|
||||
ArrowExpression, ChainElement, Expression, Function, MemberExpression,
|
||||
MethodDefinitionKind, ObjectProperty, PropertyKind,
|
||||
ChainElement, Expression, MemberExpression, MethodDefinitionKind, ObjectProperty,
|
||||
PropertyKind,
|
||||
},
|
||||
AstKind,
|
||||
};
|
||||
|
|
@ -53,6 +53,30 @@ declare_oxc_lint!(
|
|||
nursery
|
||||
);
|
||||
|
||||
impl Rule for GetterReturn {
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
match node.kind() {
|
||||
AstKind::Function(func) if !func.is_typescript_syntax() => {
|
||||
self.run_diagnostic(node, ctx, func.span);
|
||||
}
|
||||
AstKind::ArrowExpression(expr) => {
|
||||
self.run_diagnostic(node, ctx, expr.span);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_configuration(value: serde_json::Value) -> Self {
|
||||
let allow_implicit = value
|
||||
.get(0)
|
||||
.and_then(|config| config.get("allowImplicit"))
|
||||
.and_then(serde_json::Value::as_bool)
|
||||
.unwrap_or(false);
|
||||
|
||||
Self { allow_implicit }
|
||||
}
|
||||
}
|
||||
|
||||
impl GetterReturn {
|
||||
fn handle_member_expression<'a>(member_expression: &'a MemberExpression<'a>) -> bool {
|
||||
for (a, b) in METHODS_TO_WATCH_FOR {
|
||||
|
|
@ -263,29 +287,6 @@ enum DefinitelyReturnsOrThrows {
|
|||
Yes,
|
||||
}
|
||||
|
||||
impl Rule for GetterReturn {
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
match node.kind() {
|
||||
AstKind::Function(Function { span, .. })
|
||||
| AstKind::ArrowExpression(ArrowExpression { span, .. }) => {
|
||||
self.run_diagnostic(node, ctx, *span);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_configuration(value: serde_json::Value) -> Self {
|
||||
let allow_implicit = value
|
||||
.get(0)
|
||||
.and_then(|config| config.get("allowImplicit"))
|
||||
.and_then(serde_json::Value::as_bool)
|
||||
.unwrap_or(false);
|
||||
|
||||
Self { allow_implicit }
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test() {
|
||||
use crate::tester::Tester;
|
||||
|
|
@ -363,6 +364,7 @@ fn test() {
|
|||
("foo.defineProperties(null, { bar: { get() {} } });", None),
|
||||
("foo.create(null, { bar: { get() {} } });", None),
|
||||
("var foo = { get willThrowSoValid() { throw MyException() } };", None),
|
||||
("export abstract class Foo { protected abstract get foobar(): number; }", None),
|
||||
];
|
||||
|
||||
let fail = vec![
|
||||
|
|
|
|||
Loading…
Reference in a new issue