Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc49d891

Browse files
committed
perf(linter): use match forno_negated_condition (#14522)
1 parente222fc2 commitc49d891

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

‎crates/oxc_linter/src/generated/rule_runner_impls.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ impl RuleRunner for crate::rules::eslint::no_multi_str::NoMultiStr {
394394
}
395395

396396
implRuleRunnerforcrate::rules::eslint::no_negated_condition::NoNegatedCondition{
397-
constNODE_TYPES:Option<&AstTypesBitset> =None;
397+
constNODE_TYPES:Option<&AstTypesBitset> =
398+
Some(&AstTypesBitset::from_types(&[AstType::ConditionalExpression,AstType::IfStatement]));
398399
}
399400

400401
implRuleRunnerforcrate::rules::eslint::no_nested_ternary::NoNestedTernary{

‎crates/oxc_linter/src/rules/eslint/no_negated_condition.rs‎

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ declare_oxc_lint!(
5858

5959
implRuleforNoNegatedCondition{
6060
fnrun<'a>(&self,node:&AstNode<'a>,ctx:&LintContext<'a>){
61-
let stmt_test =match node.kind(){
61+
match node.kind(){
6262
AstKind::IfStatement(if_stmt) =>{
6363
letSome(if_stmt_alternate) =&if_stmt.alternateelse{
6464
return;
@@ -68,32 +68,30 @@ impl Rule for NoNegatedCondition {
6868
return;
6969
}
7070

71-
if_stmt.test.without_parentheses()
72-
}
73-
AstKind::ConditionalExpression(conditional_expr) =>{
74-
conditional_expr.test.without_parentheses()
75-
}
76-
_ =>return,
77-
};
78-
79-
match stmt_test{
80-
Expression::UnaryExpression(unary_expr) =>{
81-
if unary_expr.operator !=UnaryOperator::LogicalNot{
82-
return;
71+
let test = if_stmt.test.without_parentheses();
72+
ifis_negated_expression(test){
73+
ctx.diagnostic(no_negated_condition_diagnostic(test.span()));
8374
}
8475
}
85-
Expression::BinaryExpression(binary_expr) =>{
86-
if !matches!(
87-
binary_expr.operator,
88-
BinaryOperator::Inequality |BinaryOperator::StrictInequality
89-
){
90-
return;
76+
AstKind::ConditionalExpression(conditional_expr) =>{
77+
let test = conditional_expr.test.without_parentheses();
78+
ifis_negated_expression(test){
79+
ctx.diagnostic(no_negated_condition_diagnostic(test.span()));
9180
}
9281
}
93-
_ =>return,
82+
_ =>{}
9483
}
84+
}
85+
}
9586

96-
ctx.diagnostic(no_negated_condition_diagnostic(stmt_test.span()));
87+
fnis_negated_expression(expr:&Expression) ->bool{
88+
match expr{
89+
Expression::UnaryExpression(unary_expr) => unary_expr.operator ==UnaryOperator::LogicalNot,
90+
Expression::BinaryExpression(binary_expr) =>matches!(
91+
binary_expr.operator,
92+
BinaryOperator::Inequality |BinaryOperator::StrictInequality
93+
),
94+
_ =>false,
9795
}
9896
}
9997

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp