Skip to content

Files

Latest commit

 

History

History
80 lines (57 loc) · 1.11 KB

Style-NegatedUnless.md

File metadata and controls

80 lines (57 loc) · 1.11 KB

Pattern: Misused unless with negated condition

Issue: -

Description

Checks for uses of unless with a negated condition. Only unless without else are considered. There are three different styles:

  • both
  • prefix
  • postfix

Examples

EnforcedStyle: both (default)

# enforces `if` for `prefix` and `postfix` conditionals

# bad
unless !foo
  bar
end

# good
if foo
  bar
end

# bad
bar unless !foo

# good
bar if foo

EnforcedStyle: prefix

# enforces `if` for just `prefix` conditionals

# bad
unless !foo
  bar
end

# good
if foo
  bar
end

# good
bar unless !foo

EnforcedStyle: postfix

# enforces `if` for just `postfix` conditionals

# bad
bar unless !foo

# good
bar if foo

# good
unless !foo
  bar
end

Configurable attributes

Name Default value Configurable values
EnforcedStyle both both, prefix, postfix

Further Reading