Skip to content

Files

Latest commit

 

History

History
88 lines (58 loc) · 1.1 KB

Style-NegatedIf.md

File metadata and controls

88 lines (58 loc) · 1.1 KB

Pattern: if with negated condition

Issue: -

Description

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

  • both
  • prefix
  • postfix

Examples

# EnforcedStyle: both
# enforces `unless` for `prefix` and `postfix` conditionals

# good

unless foo
  bar
end

# bad

if !foo
  bar
end

# good

bar unless foo

# bad

bar if !foo
# EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals

# good

unless foo
  bar
end

# bad

if !foo
  bar
end

# good

bar if !foo
# EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals

# good

bar unless foo

# bad

bar if !foo

# good

if !foo
  bar
end

Default configuration

Attribute Value
EnforcedStyle both
SupportedStyles both, prefix, postfix

Further Reading