diff --git a/.rubocop.yml b/.rubocop.yml index 802a6e6..9c49771 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index 41c4de2..e0932d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -71,6 +73,7 @@ GEM unicode-display_width (2.2.0) PLATFORMS + arm64-darwin-21 x86_64-darwin-19 x86_64-darwin-20 diff --git a/README.md b/README.md index 800d0b0..8796a67 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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). diff --git a/STYLEGUIDE.md b/STYLEGUIDE.md index b10d59c..c32650c 100644 --- a/STYLEGUIDE.md +++ b/STYLEGUIDE.md @@ -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. [[link](#keyword-arguments)] -``` ruby - So instead of this: + ``` ruby def remove_member(user, skip_membership_check=false) # ... @@ -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) # ... @@ -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 \ No newline at end of file +[rubocop-guide]: https://github.com/rubocop-hq/ruby-style-guide diff --git a/config/default.yml b/config/default.yml index 6dcd009..52a0655 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1,5 +1,5 @@ require: - - rubocop/cop/github + - rubocop-github - rubocop-performance Bundler/DuplicatedGem: diff --git a/config/default_cops.yml b/config/default_cops.yml new file mode 100644 index 0000000..00b5ea0 --- /dev/null +++ b/config/default_cops.yml @@ -0,0 +1,3 @@ +GitHub/InsecureHashAlgorithm: + Description: 'Encourage usage of secure hash algorithms' + Enabled: pending diff --git a/config/rails.yml b/config/rails.yml index ab16d61..2782574 100644 --- a/config/rails.yml +++ b/config/rails.yml @@ -1,4 +1,5 @@ require: + - rubocop-github-rails - rubocop-rails Rails/OutputSafety: @@ -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 diff --git a/config/rails_cops.yml b/config/rails_cops.yml new file mode 100644 index 0000000..ef3d9a4 --- /dev/null +++ b/config/rails_cops.yml @@ -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' diff --git a/guides/image-has-alt.md b/guides/image-has-alt.md deleted file mode 100644 index a761dba..0000000 --- a/guides/image-has-alt.md +++ /dev/null @@ -1,29 +0,0 @@ -# GitHub/Accessibility/ImageHasAlt - -## Rule Details - -Images should have an alt prop with meaningful text or an empty string for decorative images. - -## Resources - -- [W3C WAI Images Tutorial](https://www.w3.org/WAI/tutorials/images/) -- [Primer: Alternative text for images](https://primer.style/design/accessibility/alternative-text-for-images) - -## Examples -### **Incorrect** code for this rule 👎 - -```erb -<%= image_tag "spinners/octocat-spinner-16px.gif", size: "12x12" %> -``` - -### **Correct** code for this rule 👍 - -```erb - -<%= image_tag "spinners/octocat-spinner-16px.gif", size: "12x12", alt: "GitHub Logo spinner" %> -``` - -```erb - -<%= image_tag "spinners/octocat-spinner-16px.gif", size: "12x12", alt: "" %> -``` \ No newline at end of file diff --git a/guides/link-has-href.md b/guides/link-has-href.md deleted file mode 100644 index 8a574c9..0000000 --- a/guides/link-has-href.md +++ /dev/null @@ -1,29 +0,0 @@ -# GitHub/Accessibility/LinkHasHref - -## Rule Details - -Links should go somewhere, you probably want to use a `