Skip to content

Add improvements to styleguide #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Re-organise "Coding Style" section
This doesn't add or remove any rules, it just groups them together under:

Layout
 - Indentation
 - Inline
 - Newlines
Maximum Line Length

Inspired by the RuboCop [1] and AirBnb [2] styleguides.

[1]: https://github.com/rubocop/ruby-style-guide/blob/master/README.adoc
[2]: https://github.com/airbnb/ruby/blob/master/README.md
  • Loading branch information
elenatanasoiu committed Aug 28, 2022
commit 2bda235972a35ee44c4484559a49503df44c4a70
102 changes: 57 additions & 45 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,31 @@
This is GitHub's Ruby Style Guide, inspired by [RuboCop's guide][rubocop-guide].

## Table of Contents
1. [Coding Style](#coding-style)
2. [Classes](#classes)
3. [Collections](#collections)
4. [Documentation](#documentation)
5. [Dynamic Dispatch](#dynamic-dispatch)
6. [Exceptions](#exceptions)
7. [Hashes](#hashes)
8. [Keyword Arguments](#keyword-arguments)
9. [Naming](#naming)
10. [Percent Literals](#percent-literals)
11. [Regular Expressions](#regular-expressions)
12. [Requires](#requires)
13. [Strings](#strings)
14. [Syntax](#syntax)

## Coding Style
1. [Layout](#layout)
1. [Indentation](#indentation)
2. [Inline](#inline)
3. [Newlines](#newlines)
2. [Maximum Line Length](#line-length)
3. [Classes](#classes)
4. [Collections](#collections)
5. [Documentation](#documentation)
6. [Dynamic Dispatch](#dynamic-dispatch)
7. [Exceptions](#exceptions)
8. [Hashes](#hashes)
9. [Keyword Arguments](#keyword-arguments)
10. [Naming](#naming)
11. [Percent Literals](#percent-literals)
12. [Regular Expressions](#regular-expressions)
13. [Requires](#requires)
14. [Strings](#strings)
15. [Syntax](#syntax)

## Layout

### Indentation

* Use soft-tabs with a two space indent.

* Keep each line of code to a readable length. Unless you have a reason to, keep lines to a maximum of 118 characters. Why 118? That's the width at which the pull request diff UI needs horizontal scrolling (making pull requests harder to review).

* Never leave trailing whitespace.

* End each file with a [newline](https://github.com/bbatsov/ruby-style-guide#newline-eof).

* Use spaces around operators, after commas, colons and semicolons, around `{`
and before `}`.

``` ruby
sum = 1 + 2
a, b = 1, 2
1 > 2 ? true : false; puts "Hi"
[1, 2, 3].each { |e| puts e }
```

* No spaces after `(`, `[` or before `]`, `)`.

``` ruby
some(arg).other
[1, 2, 3].length
```

* No spaces after `!`.

``` ruby
!array.include?(element)
```

* Indent `when` with the start of the `case` expression.

``` ruby
Expand Down Expand Up @@ -91,6 +68,37 @@ else
end
```

### Inline

* Never leave trailing whitespace.

* Use spaces around operators, after commas, colons and semicolons, around `{`
and before `}`.

``` ruby
sum = 1 + 2
a, b = 1, 2
1 > 2 ? true : false; puts "Hi"
[1, 2, 3].each { |e| puts e }
```

* No spaces after `(`, `[` or before `]`, `)`.

``` ruby
some(arg).other
[1, 2, 3].length
```

* No spaces after `!`.

``` ruby
!array.include?(element)
```

### Newlines

* End each file with a [newline](https://github.com/bbatsov/ruby-style-guide#newline-eof).

* Use empty lines between `def`s and to break up a method into logical
paragraphs.

Expand All @@ -108,6 +116,10 @@ def some_method
end
```

## Maximum Line Length

* Keep each line of code to a readable length. Unless you have a reason to, keep lines to a maximum of 118 characters. Why 118? That's the width at which the pull request diff UI needs horizontal scrolling (making pull requests harder to review).

## Classes

* Avoid the usage of class (`@@`) variables due to their unusual behavior
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy