Skip to content

Commit 174d2c7

Browse files
authored
Merge branch 'main' into elenatanasoiu/cop-links
2 parents ffeb9fb + 2a2a9d0 commit 174d2c7

File tree

13 files changed

+251
-214
lines changed

13 files changed

+251
-214
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @github/ruby-architecture-reviewers

CODE_OF_CONDUCT.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to make participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies within all project spaces, and it also applies when
49+
an individual is representing the project or its community in public spaces.
50+
Examples of representing a project or community include using an official
51+
project e-mail address, posting via an official social media account, or acting
52+
as an appointed representative at an online or offline event. Representation of
53+
a project may be further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org

CONTRIBUTING.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Contributing
2+
3+
We welcome your contributions to the project. Thank you!
4+
5+
Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
6+
7+
8+
## What to contribute
9+
10+
This repository, `rubocop-github`, is part of a broader RuboCop ecosystem.
11+
12+
If the Cop you would like to propose is **generally applicable outside of GitHub**:
13+
14+
1. Propose the change upstream in the core open source project (e.g. [`rubocop`](https://github.com/rubocop/rubocop), or [`rubocop-rails`](https://github.com/rubocop/rubocop-rails)), where it will have maximal visibility and discussion/feedback.
15+
1. Patch the change provisionally into GitHub's project(s), for immediate benefit; that can include this repository.
16+
1. ...if the proposal is accepted, remove the patch and pull the updated upstream.
17+
1. ...if the proposal is not accepted, we usually learn something about our proposal, and we then choose whether to maintain the patch ourselves, discard it, or identify a better open-source home for it.
18+
19+
If the Cop is **only applicable for GitHub**, then this is the right place to propose it.
20+
21+
## How to contribute a Pull Request
22+
23+
1. Fork and clone the repository
24+
1. [Build it and make sure the tests pass](README.md#Testing) on your machine
25+
1. Create a new branch: `git checkout -b my-branch-name`
26+
1. Make your change, add tests, and make sure the tests still pass
27+
1. Push to your fork and submit a Pull Request
28+
1. Pat yourself on the back and wait for your pull request to be reviewed and merged.
29+
30+
## For Maintainers
31+
32+
### Releasing a new version
33+
34+
1. Update `rubocop-github.gemspec` with the next version number
35+
1. Update the `CHANGELOG` with changes and contributor
36+
1. Run `bundle` to update gem version contained in the lockfile
37+
1. Make a commit: `Release v{VERSION}`
38+
1. Tag the commit : `git tag v{VERSION}`
39+
1. Create the package: `gem build rubocop-github.gemspec`
40+
1. Push to GitHub: `git push origin && git push origin --tags`
41+
1. Push to Rubygems: `gem push rubocop-github-{VERSION}.gem`
42+
1. Publish a new release on GitHub: https://github.com/github/rubocop-github/releases/new

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RuboCop GitHub ![CI](https://github.com/github/rubocop-github/workflows/CI/badge.svg?event=push)
22

3-
This repository provides recommended RuboCop configuration and additional Cops for use on GitHub open source and internal Ruby projects.
3+
This repository provides recommended RuboCop configuration and additional Cops for use on GitHub open source and internal Ruby projects, and is the home of [GitHub's Ruby Style Guide](./STYLEGUIDE.md).
44

55
## Usage
66

STYLEGUIDE.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ This is GitHub's Ruby Style Guide, inspired by [RuboCop's guide][rubocop-guide].
2727
1. [Conditional keywords](#conditional-keywords)
2828
2. [Ternary operator](#ternary-operator)
2929
17. [Syntax](#syntax)
30+
18. [Rails](#rails)
31+
1. [content_for](#content_for)
32+
2. [Instance Variables in Views](#instance-variables-in-views)
3033

3134
## Layout
3235

@@ -951,4 +954,129 @@ result = hash.map { |_, v| v + 1 }
951954

952955
Refactoring is even better. It's worth looking hard at any code that explicitly checks types.
953956

957+
## Rails
958+
959+
### content_for
960+
961+
Limit usage of `content_for` helper. The use of `content_for` is the same as setting an instance variable plus `capture`.
962+
963+
``` erb
964+
<% content_for :foo do %>
965+
Hello
966+
<% end %>
967+
```
968+
969+
Is effectively the same as
970+
971+
``` erb
972+
<% @foo_content = capture do %>
973+
Hello
974+
<% end %>
975+
```
976+
977+
See "Instance Variables in Views" below.
978+
979+
#### Common Anti-patterns
980+
981+
**Using `content_for` within the same template to capture data.**
982+
983+
Instead, just use `capture`.
984+
985+
``` erb
986+
<!-- bad -->
987+
<% content_for :page do %>
988+
Hello
989+
<% end %>
990+
<% if foo? %>
991+
<div class="container">
992+
<%= yield :page %>
993+
</div>
994+
<% else %>
995+
<%= yield :page %>
996+
<% end %>
997+
```
998+
999+
Simply capture and use a local variable since the result is only needed in this template.
1000+
1001+
``` erb
1002+
<!-- good -->
1003+
<% page = capture do %>
1004+
Hello
1005+
<% end %>
1006+
<% if foo? %>
1007+
<div class="container">
1008+
<%= page %>
1009+
</div>
1010+
<% else %>
1011+
<%= page %>
1012+
<% end %>
1013+
```
1014+
1015+
**Using `content_for` to pass content to a subtemplate.**
1016+
1017+
Instead, `render layout:` with a block.
1018+
1019+
``` erb
1020+
<!-- bad -->
1021+
<% content_for :page do %>
1022+
Hello
1023+
<% end %>
1024+
<%= render partial: "page" %>
1025+
<!-- _page.html.erb -->
1026+
<div class="container">
1027+
<%= yield :page %>
1028+
</div>
1029+
```
1030+
1031+
Pass the content in a block directly to the `render` function.
1032+
1033+
``` erb
1034+
<!-- good -->
1035+
<%= render layout: "page" do %>
1036+
Hello
1037+
<% end %>
1038+
<!-- _page.html.erb -->
1039+
<div class="container">
1040+
<%= yield %>
1041+
</div>
1042+
```
1043+
1044+
### Instance Variables in Views
1045+
1046+
In general, passing data between templates with instance variables is discouraged. This even applies from controllers to templates, not just between partials.
1047+
1048+
`:locals` can be used to pass data from a controller just like partials.
1049+
1050+
``` ruby
1051+
def show
1052+
render "blob/show", locals: {
1053+
:repository => current_repository,
1054+
:commit => current_commit,
1055+
:blob => current_blob
1056+
}
1057+
end
1058+
```
1059+
1060+
Rails implicit renders are also discouraged.
1061+
1062+
Always explicitly render templates with a full directory path. This makes template callers easier to trace. You can find all the callers of `"app/view/site/hompage.html.erb"` with a simple project search for `"site/homepage"`.
1063+
1064+
``` ruby
1065+
def homepage
1066+
render "site/homepage"
1067+
end
1068+
```
1069+
1070+
#### Exceptions
1071+
1072+
There are some known edge cases where you might be forced to use instance variables. In these cases, its okay to do so.
1073+
1074+
##### Legacy templates
1075+
1076+
If you need to call a subview that expects an instance variable be set. If possible consider refactoring the subview to accept a local instead.
1077+
1078+
##### Layouts
1079+
1080+
Unfortunately the only way to get data into a layout template is with instance variables. You can't explicitly pass locals to them.
1081+
9541082
[rubocop-guide]: https://github.com/rubocop-hq/ruby-style-guide

config/default.yml

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,14 @@ Layout/HeredocIndentation:
182182
Enabled: false
183183

184184
Layout/IndentationConsistency:
185-
Enabled: false
185+
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#indentation
186186

187187
Layout/IndentationStyle:
188-
Enabled: true
189188
EnforcedStyle: spaces
190189
IndentationWidth: 2
191190
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#default-indentation
192191

193192
Layout/IndentationWidth:
194-
Enabled: true
195193
Width: 2
196194
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#default-indentation
197195

@@ -262,11 +260,9 @@ Layout/SingleLineBlockChain:
262260
Enabled: false
263261

264262
Layout/SpaceAfterColon:
265-
Enabled: true
266263
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#spaces-operators
267264

268265
Layout/SpaceAfterComma:
269-
Enabled: true
270266
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#spaces-operators
271267

272268
Layout/SpaceAfterMethodName:
@@ -276,18 +272,16 @@ Layout/SpaceAfterNot:
276272
Enabled: true
277273

278274
Layout/SpaceAfterSemicolon:
279-
Enabled: true
280275
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#spaces-operators
281276

282277
Layout/SpaceAroundBlockParameters:
283278
Enabled: true
284279

285280
Layout/SpaceAroundEqualsInParameterDefault:
286-
Enabled: true
287281
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#spaces-around-equals
288282

289283
Layout/SpaceAroundKeyword:
290-
Enabled: false
284+
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#spaces-operators
291285

292286
Layout/SpaceAroundMethodCallOperator:
293287
Enabled: false
@@ -317,7 +311,6 @@ Layout/SpaceInLambdaLiteral:
317311
Enabled: false
318312

319313
Layout/SpaceInsideArrayLiteralBrackets:
320-
Enabled: true
321314
EnforcedStyle: no_space
322315
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#no-spaces-braces
323316

@@ -349,7 +342,6 @@ Layout/TrailingEmptyLines:
349342
Enabled: true
350343

351344
Layout/TrailingWhitespace:
352-
Enabled: true
353345
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#trailing-whitespace
354346

355347
Lint/AmbiguousAssignment:
@@ -691,7 +683,7 @@ Lint/UnreachableLoop:
691683
# TODO: Enable this since it's in the styleguide.
692684
Lint/UnusedBlockArgument:
693685
Enabled: false
694-
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#spaces-around-equals
686+
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#underscore-unused-vars
695687

696688
Lint/UnusedMethodArgument:
697689
Enabled: false
@@ -1090,7 +1082,6 @@ Style/DateTime:
10901082
Enabled: false
10911083

10921084
Style/DefWithParentheses:
1093-
Enabled: true
10941085
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#method-parens-when-arguments
10951086

10961087
Style/Dir:
@@ -1178,7 +1169,6 @@ Style/FloatDivision:
11781169
Enabled: false
11791170

11801171
Style/For:
1181-
Enabled: true
11821172
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#avoid-for
11831173

11841174
Style/FormatString:
@@ -1215,7 +1205,6 @@ Style/HashLikeCase:
12151205
Enabled: false
12161206

12171207
Style/HashSyntax:
1218-
Enabled: true
12191208
EnforcedStyle: ruby19_no_mixed_keys
12201209
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#symbols-as-keys
12211210

@@ -1316,7 +1305,6 @@ Style/MultilineIfModifier:
13161305
Enabled: false
13171306

13181307
Style/MultilineIfThen:
1319-
Enabled: true
13201308
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#no-then-for-multi-line-if-unless
13211309

13221310
Style/MultilineInPatternThen:
@@ -1583,8 +1571,8 @@ Style/StringHashKeys:
15831571
Enabled: false
15841572

15851573
Style/StringLiterals:
1586-
Enabled: true
15871574
EnforcedStyle: double_quotes
1575+
StyleGuide: https://github.com/github/rubocop-github/blob/main/STYLEGUIDE.md#double-quotes
15881576

15891577
Style/StringLiteralsInInterpolation:
15901578
Enabled: false

0 commit comments

Comments
 (0)