Skip to content

Commit ba7bd51

Browse files
FMP1783camc314
andauthored
feat(linter): implement no-useless-return rule (#16388)
Implement `eslint/no-useless-return` rule. Disallows redundant return statements that have no effect on function behavior. ## Test - 27 valid / 25 invalid test cases - `just ready` passes Note: `globalReturn` cases excluded (unsupported by oxc) Part of #479 --------- Co-authored-by: Cameron Clark <cameron.clark@hey.com>
1 parent 96843a8 commit ba7bd51

File tree

4 files changed

+844
-0
lines changed

4 files changed

+844
-0
lines changed

crates/oxc_linter/src/generated/rule_runner_impls.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,12 @@ impl RuleRunner for crate::rules::eslint::no_useless_rename::NoUselessRename {
870870
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
871871
}
872872

873+
impl RuleRunner for crate::rules::eslint::no_useless_return::NoUselessReturn {
874+
const NODE_TYPES: Option<&AstTypesBitset> =
875+
Some(&AstTypesBitset::from_types(&[AstType::ReturnStatement]));
876+
const RUN_FUNCTIONS: RuleRunFunctionsImplemented = RuleRunFunctionsImplemented::Run;
877+
}
878+
873879
impl RuleRunner for crate::rules::eslint::no_var::NoVar {
874880
const NODE_TYPES: Option<&AstTypesBitset> =
875881
Some(&AstTypesBitset::from_types(&[AstType::VariableDeclaration]));

crates/oxc_linter/src/rules.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ pub(crate) mod eslint {
169169
pub mod no_useless_constructor;
170170
pub mod no_useless_escape;
171171
pub mod no_useless_rename;
172+
pub mod no_useless_return;
172173
pub mod no_var;
173174
pub mod no_void;
174175
pub mod no_warning_comments;
@@ -800,6 +801,7 @@ oxc_macros::declare_all_lint_rules! {
800801
eslint::no_useless_constructor,
801802
eslint::no_useless_escape,
802803
eslint::no_useless_rename,
804+
eslint::no_useless_return,
803805
eslint::no_var,
804806
eslint::no_void,
805807
eslint::no_warning_comments,

0 commit comments

Comments
 (0)