Skip to content

Add maximum_statements and ignore_if_case options to prefer_early_return rule #343

Closed

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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