mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(linter/eslint/no-extra-boolean-cast): narrow AST dispatch (#28362)
Handle optional Boolean calls through their call nodes while retaining chain context for diagnostics and fixes. Reduce fixture callbacks from 72,504 to 71,712. --- <sub>Stack created with <a href="https://github.com/github/gh-stack">GitHub Stacks CLI</a> • <a href="https://gh.io/stacks-feedback">Give Feedback 💬</a></sub> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
1 parent
93c6e6dd5e
commit
bc5e94d391
3 files changed
+19
-21
No files matched your search
+2
-5
@@ -709,11 +709,8 @@ impl RuleRunner for crate::rules::eslint::no_extra_bind::NoExtraBind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RuleRunner for crate::rules::eslint::no_extra_boolean_cast::NoExtraBooleanCast {
|
impl RuleRunner for crate::rules::eslint::no_extra_boolean_cast::NoExtraBooleanCast {
|
||||||
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
|
const NODE_TYPES: Option<&AstTypesBitset> =
|
||||||
AstType::CallExpression,
|
Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::UnaryExpression]));
|
||||||
AstType::ChainExpression,
|
|
||||||
AstType::UnaryExpression,
|
|
||||||
]));
|
|
||||||
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
|
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ use serde::Deserialize;
|
|||||||
use oxc_ast::{
|
use oxc_ast::{
|
||||||
AstKind,
|
AstKind,
|
||||||
ast::{
|
ast::{
|
||||||
CallExpression, ChainElement, ConditionalExpression, DoWhileStatement, Expression,
|
CallExpression, ConditionalExpression, DoWhileStatement, Expression, ForStatement,
|
||||||
ForStatement, IfStatement, NewExpression, WhileStatement,
|
IfStatement, NewExpression, WhileStatement,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
use oxc_diagnostics::OxcDiagnostic;
|
use oxc_diagnostics::OxcDiagnostic;
|
||||||
@@ -99,19 +99,17 @@ impl Rule for NoExtraBooleanCast {
|
|||||||
|
|
||||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
AstKind::CallExpression(expr)
|
AstKind::CallExpression(expr) if expr.callee.is_specific_id("Boolean") => {
|
||||||
if !expr.optional
|
let node = if expr.optional {
|
||||||
&& expr.callee.is_specific_id("Boolean")
|
let parent = ctx.nodes().parent_node(node.id());
|
||||||
&& is_flagged_ctx(node, ctx, self.enforce_for_inner_expressions) =>
|
if !matches!(parent.kind(), AstKind::ChainExpression(_)) {
|
||||||
{
|
return;
|
||||||
report_boolean_call(expr, node, ctx);
|
}
|
||||||
}
|
parent
|
||||||
AstKind::ChainExpression(chain)
|
} else {
|
||||||
if is_flagged_ctx(node, ctx, self.enforce_for_inner_expressions) =>
|
node
|
||||||
{
|
};
|
||||||
if let ChainElement::CallExpression(expr) = &chain.expression
|
if is_flagged_ctx(node, ctx, self.enforce_for_inner_expressions) {
|
||||||
&& expr.callee.is_specific_id("Boolean")
|
|
||||||
{
|
|
||||||
report_boolean_call(expr, node, ctx);
|
report_boolean_call(expr, node, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -362,6 +360,8 @@ fn test() {
|
|||||||
use crate::tester::Tester;
|
use crate::tester::Tester;
|
||||||
|
|
||||||
let pass = vec![
|
let pass = vec![
|
||||||
|
("if (Boolean?.(foo).value) {}", None),
|
||||||
|
("if (Boolean?.(foo)()) {}", None),
|
||||||
("Boolean(bar, !!baz);", None),
|
("Boolean(bar, !!baz);", None),
|
||||||
("var foo = !!bar;", None),
|
("var foo = !!bar;", None),
|
||||||
("function foo() { return !!bar; }", None),
|
("function foo() { return !!bar; }", None),
|
||||||
@@ -1527,6 +1527,7 @@ fn test() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
let fix = vec![
|
let fix = vec![
|
||||||
|
("while (Boolean?.(foo)) {}", "while (foo) {}", None),
|
||||||
("if (!!foo) {}", "if (foo) {}", None),
|
("if (!!foo) {}", "if (foo) {}", None),
|
||||||
("do {} while (!!foo)", "do {} while (foo)", None),
|
("do {} while (!!foo)", "do {} while (foo)", None),
|
||||||
("while (!!foo) {}", "while (foo) {}", None),
|
("while (!!foo) {}", "while (foo) {}", None),
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ eslint/no-eval | 73005
|
|||||||
eslint/no-ex-assign | 111
|
eslint/no-ex-assign | 111
|
||||||
eslint/no-extend-native | 7
|
eslint/no-extend-native | 7
|
||||||
eslint/no-extra-bind | 62606
|
eslint/no-extra-bind | 62606
|
||||||
eslint/no-extra-boolean-cast | 72504
|
eslint/no-extra-boolean-cast | 71712
|
||||||
eslint/no-extra-label | 836
|
eslint/no-extra-label | 836
|
||||||
eslint/no-fallthrough | 284
|
eslint/no-fallthrough | 284
|
||||||
eslint/no-func-assign | 14283
|
eslint/no-func-assign | 14283
|
||||||
|
|||||||
Reference in new issue
Block a user