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 {
|
||||
const NODE_TYPES: Option<&AstTypesBitset> = Some(&AstTypesBitset::from_types(&[
|
||||
AstType::CallExpression,
|
||||
AstType::ChainExpression,
|
||||
AstType::UnaryExpression,
|
||||
]));
|
||||
const NODE_TYPES: Option<&AstTypesBitset> =
|
||||
Some(&AstTypesBitset::from_types(&[AstType::CallExpression, AstType::UnaryExpression]));
|
||||
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ use serde::Deserialize;
|
||||
use oxc_ast::{
|
||||
AstKind,
|
||||
ast::{
|
||||
CallExpression, ChainElement, ConditionalExpression, DoWhileStatement, Expression,
|
||||
ForStatement, IfStatement, NewExpression, WhileStatement,
|
||||
CallExpression, ConditionalExpression, DoWhileStatement, Expression, ForStatement,
|
||||
IfStatement, NewExpression, WhileStatement,
|
||||
},
|
||||
};
|
||||
use oxc_diagnostics::OxcDiagnostic;
|
||||
@@ -99,19 +99,17 @@ impl Rule for NoExtraBooleanCast {
|
||||
|
||||
fn run<'a>(&self, node: &AstNode<'a>, ctx: &LintContext<'a>) {
|
||||
match node.kind() {
|
||||
AstKind::CallExpression(expr)
|
||||
if !expr.optional
|
||||
&& expr.callee.is_specific_id("Boolean")
|
||||
&& is_flagged_ctx(node, ctx, self.enforce_for_inner_expressions) =>
|
||||
{
|
||||
report_boolean_call(expr, node, ctx);
|
||||
}
|
||||
AstKind::ChainExpression(chain)
|
||||
if is_flagged_ctx(node, ctx, self.enforce_for_inner_expressions) =>
|
||||
{
|
||||
if let ChainElement::CallExpression(expr) = &chain.expression
|
||||
&& expr.callee.is_specific_id("Boolean")
|
||||
{
|
||||
AstKind::CallExpression(expr) if expr.callee.is_specific_id("Boolean") => {
|
||||
let node = if expr.optional {
|
||||
let parent = ctx.nodes().parent_node(node.id());
|
||||
if !matches!(parent.kind(), AstKind::ChainExpression(_)) {
|
||||
return;
|
||||
}
|
||||
parent
|
||||
} else {
|
||||
node
|
||||
};
|
||||
if is_flagged_ctx(node, ctx, self.enforce_for_inner_expressions) {
|
||||
report_boolean_call(expr, node, ctx);
|
||||
}
|
||||
}
|
||||
@@ -362,6 +360,8 @@ fn test() {
|
||||
use crate::tester::Tester;
|
||||
|
||||
let pass = vec![
|
||||
("if (Boolean?.(foo).value) {}", None),
|
||||
("if (Boolean?.(foo)()) {}", None),
|
||||
("Boolean(bar, !!baz);", None),
|
||||
("var foo = !!bar;", None),
|
||||
("function foo() { return !!bar; }", None),
|
||||
@@ -1527,6 +1527,7 @@ fn test() {
|
||||
];
|
||||
|
||||
let fix = vec![
|
||||
("while (Boolean?.(foo)) {}", "while (foo) {}", None),
|
||||
("if (!!foo) {}", "if (foo) {}", None),
|
||||
("do {} while (!!foo)", "do {} while (foo)", None),
|
||||
("while (!!foo) {}", "while (foo) {}", None),
|
||||
|
||||
@@ -67,7 +67,7 @@ eslint/no-eval | 73005
|
||||
eslint/no-ex-assign | 111
|
||||
eslint/no-extend-native | 7
|
||||
eslint/no-extra-bind | 62606
|
||||
eslint/no-extra-boolean-cast | 72504
|
||||
eslint/no-extra-boolean-cast | 71712
|
||||
eslint/no-extra-label | 836
|
||||
eslint/no-fallthrough | 284
|
||||
eslint/no-func-assign | 14283
|
||||
|
||||
Reference in new issue
Block a user