Skip to content

Latest commit

 

History

History
102 lines (79 loc) · 1.13 KB

newlines_styleguide.md

File metadata and controls

102 lines (79 loc) · 1.13 KB

Newlines styleguide

This style guide recommends best practices for newlines in Ruby code.

Rule: separate code with newlines only when it makes sense from logic perspectice

# bad
def method
  issue = Issue.new

  issue.save
  
  render json: issue 
end
# good
def method
  issue = Issue.new
  issue.save
  
  render json: issue 
end

Rule: separate code and block with newlines

Newline before block

# bad
def method
  issue = Issue.new
  if issue.save
    render json: issue
  end
end
# good
def method
  issue = Issue.new

  if issue.save
    render json: issue
  end
end

Newline after block

# bad
def method
  if issue.save
    issue.send_email
  end
  render json: issue
end
# good
def method
  if issue.save
    issue.send_email
  end

  render json: issue
end

Exception: no need for newline when code block starts or ends right inside another code block

# bad
def method

  if issue

    if issue.valid?
      issue.save
    end

  end

end
# good
def method
  if issue
    if issue.valid?
      issue.save
    end
  end
end