Skip to content

Rule Request: no_duplicated_condition #4666

Closed
@lo1tuma

Description

New Issue Checklist

New rule request

  1. Why should this rule be added?

This rule should flag conditions that are used multiple times in the same branching statement like if-else-if or switch statement.

  1. Provide several examples of what would and wouldn't trigger violations.

Violating Examples

if x < 5 {
  foo()
} else if x < 2 {
  bar()
} else if x < 5 { // duplicated condition
  baz()
}

switch x {
case "a":
  foo()
case "a" // duplicated condition
  bar()
}

Non-Violating Examples

if x < 5 {
  foo()
  baz()
} else if x < 2 {
  bar()
}

switch x {
case "a":
  foo()
  bar()
}
  1. Should the rule be configurable, if so what parameters should be configurable?

This rule doesn’t need to be configurable.

  1. Should the rule be opt-in or enabled by default? Why?
    See README.md for guidelines on when to mark a rule as opt-in.

This would be a good candidate for a builtin rule as it points out bad structured code.

Metadata

Assignees

No one assigned

    Labels

    good first issueIssue to be taken up by new contributors yet unfamiliar with the project.rule-requestRequests for a new rules.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions