Skip to content

Commit

Permalink
Merge branch 'master' into rubocop-default-enablement
Browse files Browse the repository at this point in the history
  • Loading branch information
bensheldon committed Oct 13, 2022
2 parents 4274086 + bbe922b commit cdcad37
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 170 deletions.
5 changes: 4 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
inherit_from: ./config/default.yml
inherit_from:
- ./config/default.yml

Naming/FileName:
Enabled: true
Exclude:
- "rubocop-github.gemspec"
- "lib/rubocop-github.rb"
- "lib/rubocop-github-rails.rb"
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ GEM
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
minitest (5.16.1)
nokogiri (1.13.6-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.6-x86_64-darwin)
racc (~> 1.4)
parallel (1.22.1)
Expand Down Expand Up @@ -71,6 +73,7 @@ GEM
unicode-display_width (2.2.0)

PLATFORMS
arm64-darwin-21
x86_64-darwin-19
x86_64-darwin-20

Expand Down
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,32 @@ This repository provides recommended RuboCop configuration and additional Cops f

## Usage

**Gemfile**
Add `rubocop-github` to your Gemfile, along with its dependencies:

``` ruby
gem "rubocop-github"
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
```
```ruby
gem "rubocop-github", require: false
gem "rubocop-performance", require: false
gem "rubocop-rails", require: false
```

**.rubocop.yml**
Inherit all of the stylistic rules and cops through an inheritance declaration in your `.rubocop.yml`:

``` yaml
inherit_gem:
rubocop-github:
- config/default.yml
- config/rails.yml
```
```yaml
# .rubocop.yml
inherit_from:
rubocop-github:
- config/default.yml # generic Ruby rules and cops
- config/rails.yml # Rails-specific rules and cops
```

Alternatively, only require the additional custom cops in your `.rubocop.yml` without inheriting/enabling the other stylistic rules:

```yaml
# .rubocop.yml
require:
- rubocop-github # generic Ruby cops only
- rubocop-github-rails # Rails-specific cops only
```

💭 Looking for `config/accessibility.yml` and the `GitHub/Accessibility` configs? They have been moved to [a new gem](https://github.com/github/rubocop-rails-accessibility).

Expand All @@ -39,4 +49,4 @@ bundle exec rake test

## The Cops

All cops are located under [`lib/rubocop/cop/github`](lib/rubocop/cop/github) and [`lib/rubocop/cop/github/accessibility`](lib/rubocop/cop/github/accessibility), and contain examples/documentation.
All cops are located under [`lib/rubocop/cop/github`](lib/rubocop/cop/github).
8 changes: 4 additions & 4 deletions STYLEGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,8 @@ hsh = {
[Keyword arguments](http://magazine.rubyist.net/?Ruby200SpecialEn-kwarg) are recommended but not required when a method's arguments may otherwise be opaque or non-obvious when called. Additionally, prefer them over the old "Hash as pseudo-named args" style from pre-2.0 ruby.
<a name="keyword-arguments"></a><sup>[[link](#keyword-arguments)]</sup>
``` ruby
So instead of this:
``` ruby
def remove_member(user, skip_membership_check=false)
# ...
Expand All @@ -430,7 +429,8 @@ end
remove_member(user, true)
```
Do this, which is much clearer.
Do this, which is much clearer:
``` ruby
def remove_member(user, skip_membership_check: false)
# ...
Expand Down Expand Up @@ -893,4 +893,4 @@ result = hash.map { |_, v| v + 1 }

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

[rubocop-guide]: https://github.com/rubocop-hq/ruby-style-guide
[rubocop-guide]: https://github.com/rubocop-hq/ruby-style-guide
2 changes: 1 addition & 1 deletion config/default.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require:
- rubocop/cop/github
- rubocop-github
- rubocop-performance

Bundler/DuplicatedGem:
Expand Down
3 changes: 3 additions & 0 deletions config/default_cops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GitHub/InsecureHashAlgorithm:
Description: 'Encourage usage of secure hash algorithms'
Enabled: pending
34 changes: 1 addition & 33 deletions config/rails.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require:
- rubocop-github-rails
- rubocop-rails

Rails/OutputSafety:
Expand All @@ -22,63 +23,30 @@ GitHub/RailsApplicationRecord:

GitHub/RailsControllerRenderActionSymbol:
Enabled: true
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsControllerRenderLiteral:
Enabled: true
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsControllerRenderPathsExist:
Enabled: true
ViewPath:
- 'app/views'
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsControllerRenderShorthand:
Enabled: true
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-shorthand.md
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsRenderInline:
Enabled: true
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-inline.md
Include:
- 'app/controllers/**/*.rb'
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'

GitHub/RailsRenderObjectCollection:
Enabled: false

GitHub/RailsViewRenderLiteral:
Enabled: true
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
Include:
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'

GitHub/RailsViewRenderPathsExist:
Enabled: true
ViewPath:
- 'app/views'
Include:
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'

GitHub/RailsViewRenderShorthand:
Enabled: true
Include:
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'

# Exclude Rails ERB files from incompatible cops

Expand Down
62 changes: 62 additions & 0 deletions config/rails_cops.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
GitHub/RailsApplicationRecord:
Enabled: pending

GitHub/RailsControllerRenderActionSymbol:
Enabled: pending
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsControllerRenderLiteral:
Enabled: pending
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsControllerRenderPathsExist:
Enabled: pending
ViewPath:
- 'app/views'
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsControllerRenderShorthand:
Enabled: pending
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-shorthand.md
Include:
- 'app/controllers/**/*.rb'

GitHub/RailsRenderInline:
Enabled: pending
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-controller-render-inline.md
Include:
- 'app/controllers/**/*.rb'
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'

GitHub/RailsRenderObjectCollection:
Enabled: pending

GitHub/RailsViewRenderLiteral:
Enabled: pending
StyleGuide: https://github.com/github/rubocop-github/blob/master/guides/rails-render-literal.md
Include:
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'

GitHub/RailsViewRenderPathsExist:
Enabled: pending
ViewPath:
- 'app/views'
Include:
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'

GitHub/RailsViewRenderShorthand:
Enabled: pending
Include:
- 'app/helpers/**/*.rb'
- 'app/view_models/**/*.rb'
- 'app/views/**/*.erb'
29 changes: 0 additions & 29 deletions guides/image-has-alt.md

This file was deleted.

29 changes: 0 additions & 29 deletions guides/link-has-href.md

This file was deleted.

24 changes: 0 additions & 24 deletions guides/no-positive-tabindex.md

This file was deleted.

24 changes: 0 additions & 24 deletions guides/no-redundant-image-alt.md

This file was deleted.

18 changes: 18 additions & 0 deletions lib/rubocop-github-rails.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require "rubocop"
require "rubocop/github"
require "rubocop/github/inject"

RuboCop::GitHub::Inject.rails_defaults!

require "rubocop/cop/github/rails_application_record"
require "rubocop/cop/github/rails_controller_render_action_symbol"
require "rubocop/cop/github/rails_controller_render_literal"
require "rubocop/cop/github/rails_controller_render_paths_exist"
require "rubocop/cop/github/rails_controller_render_shorthand"
require "rubocop/cop/github/rails_render_inline"
require "rubocop/cop/github/rails_render_object_collection"
require "rubocop/cop/github/rails_view_render_literal"
require "rubocop/cop/github/rails_view_render_paths_exist"
require "rubocop/cop/github/rails_view_render_shorthand"
9 changes: 9 additions & 0 deletions lib/rubocop-github.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require "rubocop"
require "rubocop/github"
require "rubocop/github/inject"

RuboCop::GitHub::Inject.default_defaults!

require "rubocop/cop/github/insecure_hash_algorithm"
Loading

0 comments on commit cdcad37

Please sign in to comment.