Skip to content

Files

Latest commit

 

History

History
51 lines (38 loc) · 748 Bytes

Style-GuardClause.md

File metadata and controls

51 lines (38 loc) · 748 Bytes

Pattern: Missing use of guard clause

Issue: -

Description

Use a guard clause instead of wrapping the code inside a conditional expression.

Examples

# bad
def test
  if something
    work
  end
end

# good
def test
  return unless something
  work
end

# also good
def test
  work if something
end

# bad
if something
  raise 'exception'
else
  ok
end

# good
raise 'exception' if something
ok

Default configuration

Attribute Value
MinBodyLength 1

Further Reading