diff options
author | Robert Speicher <robert@gitlab.com> | 2016-08-08 23:29:56 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-08-08 23:29:56 +0000 |
commit | fa95d9e48bcbe6c0958d8faf2906ec1c3482440b (patch) | |
tree | 60aa7c8307c8221d8d6ed4489c45ade142c0ac1e /doc | |
parent | 1eccfde7dfc96a6d824fc132d5a27d1f2d661454 (diff) | |
parent | 13cabe7184e372c6d903a836c180231d2e78f517 (diff) | |
download | gitlab-ce-fa95d9e48bcbe6c0958d8faf2906ec1c3482440b.tar.gz |
Merge branch 'dz-newlines-styleguide' into 'master'
Add newlines styleguide for Ruby code
See merge request !5636
Diffstat (limited to 'doc')
-rw-r--r-- | doc/development/newlines_styleguide.md | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/doc/development/newlines_styleguide.md b/doc/development/newlines_styleguide.md new file mode 100644 index 00000000000..e03adcaadea --- /dev/null +++ b/doc/development/newlines_styleguide.md @@ -0,0 +1,102 @@ +# 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 + +```ruby +# bad +def method + issue = Issue.new + + issue.save + + render json: issue +end +``` + +```ruby +# good +def method + issue = Issue.new + issue.save + + render json: issue +end +``` + +## Rule: separate code and block with newlines + +### Newline before block + +```ruby +# bad +def method + issue = Issue.new + if issue.save + render json: issue + end +end +``` + +```ruby +# good +def method + issue = Issue.new + + if issue.save + render json: issue + end +end +``` + +## Newline after block + +```ruby +# bad +def method + if issue.save + issue.send_email + end + render json: issue +end +``` + +```ruby +# 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 + +```ruby +# bad +def method + + if issue + + if issue.valid? + issue.save + end + + end + +end +``` + +```ruby +# good +def method + if issue + if issue.valid? + issue.save + end + end +end +``` |