Skip to content

Add maximum_statements and ignore_if_case options to prefer_early_return rule #343

Description

@illia-aihistov-solid

The ESLint implementation of the rule has a maximumStatements parameter (set to 1 by default), which skips the analysis if the number of statements inside the block does not exceed maximumStatements.
https://github.com/regru/eslint-plugin-prefer-early-return

We can also add an ignore-if-case parameter, similar to DCM (https://dcm.dev/docs/rules/common/prefer-early-return/#example-with-ignore-if-case), to ignore the rule for the if-case case.

I suggest adding these parameters to the prefer_early_return rule (maximum_statements: 1 and ignore_if_case: true by default).

We could also consider extending the rule to apply to loop bodies:

so instead of

for ... {
if ... {
a
b
...
}
}

it will propose

for ... {
if!... continue;
a
b
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions