Skip to content
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

Enable RuboCop and configure GitHub Actions to run RuboCop #1185

Merged
merged 3 commits into from
Dec 23, 2020
Merged

Enable RuboCop and configure GitHub Actions to run RuboCop #1185

merged 3 commits into from
Dec 23, 2020

Conversation

yahonda
Copy link
Contributor

@yahonda yahonda commented Dec 23, 2020

This pull request enables RuboCop and configure GitHub Actions to run RuboCop.

Fixes #1164

  • RuboCop version is locked to 0.81.0 which supports Ruby 2.3
    Once Ransack bumps the required_ruby_version, RuboCop can be bumped.

  • DisabledByDefault: true not to apply all of default cops

  • Some Layout and Style cops are enabled to make initial changes small
    Other cops can be enabled later.

Here are RuboCop auto correct results

 bundle exec rubocop -a

Inspecting 70 files
............C..C....C.....C.CC...C.C..CC......CCCC.C..C...CC..C.CC...C

Offenses:

lib/polyamorous/polyamorous.rb:14:49: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
  ar_version = ::ActiveRecord::VERSION::STRING[0,3]
                                                ^
lib/ransack.rb:10:59: C: [Corrected] Style/Semicolon: Do not use semicolons to terminate expressions.
  class UntraversableAssociationError < StandardError; end;
                                                          ^
lib/ransack/adapters/active_record/ransack/constants.rb:100:57: C: [Corrected] Layout/SpaceInsideBlockBraces: Space missing inside }.
        validator: proc { |v| BOOLEAN_VALUES.include?(v)},
                                                        ^
lib/ransack/constants.rb:39:7: C: [Corrected] Layout/FirstArrayElementIndentation: Indent the right bracket the same as the start of th
e line where the left bracket is.
      ].freeze
      ^
lib/ransack/constants.rb:55:1: C: [Corrected] Layout/TrailingEmptyLines: 1 trailing blank lines detected.
lib/ransack/helpers.rb:2:38: C: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
require 'ransack/helpers/form_helper'

lib/ransack/helpers/form_builder.rb:48:9: C: [Corrected] Style/SelfAssignment: Use self-assignment shorthand ||=.
        options = options || {}
        ^^^^^^^^^^^^^^^^^^^^^^^
lib/ransack/helpers/form_builder.rb:49:9: C: [Corrected] Style/SelfAssignment: Use self-assignment shorthand ||=.
        html_options = html_options || {}
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/ransack/helpers/form_builder.rb:50:9: C: [Corrected] Style/SelfAssignment: Use self-assignment shorthand ||=.
        action = action || Constants::SEARCH
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/ransack/nodes/attribute.rb:33:11: C: [Corrected] Style/RedundantReturn: Redundant return detected.
          return ransacker.type
          ^^^^^^
lib/ransack/nodes/condition.rb:130:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
lib/ransack/nodes/condition.rb:266:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
lib/ransack/nodes/condition.rb:267:7: C: [Corrected] Layout/EmptyLineBetweenDefs: Use empty lines between method definitions.
      def default_type
      ^^^^^^^^^^^^^^^^
lib/ransack/nodes/sort.rb:12:44: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
          attr, direction = str.split(/\s+/,2)
                                           ^
lib/ransack/nodes/value.rb:53:21: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
          Date.new(y,m,d) rescue nil
                    ^
lib/ransack/nodes/value.rb:53:23: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
          Date.new(y,m,d) rescue nil
                      ^
ransack.gemspec:2:1: C: [Corrected] Layout/EmptyLineAfterMagicComment: Add an empty line after magic comments.
$:.push File.expand_path("../lib", __FILE__)
^
ransack.gemspec:9:60: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
  s.authors     = ["Ernie Miller", "Ryan Bigg", "Jon Atack","Sean Carroll"]
                                                           ^
ransack.gemspec:10:94: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
  s.email       = ["ernie@erniemiller.org", "radarlistener@gmail.com", "jonnyatack@gmail.com","sfcarroll@gmail.com"]
                                                                                             ^
spec/blueprints/articles.rb:5:4: C: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
end

spec/blueprints/comments.rb:5:4: C: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
end

spec/blueprints/notes.rb:5:4: C: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
end

spec/blueprints/tags.rb:3:4: C: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
end

spec/helpers/ransack_helper.rb:9:4: C: [Corrected] Layout/TrailingEmptyLines: Final newline missing.
end

spec/ransack/adapters/active_record/base_spec.rb:467:62: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
            expect(Comment.ransack(article_title_cont: 'aven',s: 'person_salary desc').result).to eq(comments)
                                                             ^
spec/ransack/adapters/active_record/base_spec.rb:469:77: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
            expect(Comment.joins(:person).ransack(article_title_cont: 'aven',s: 'persons_salary desc').result).to eq(comments)
                                                                            ^
spec/ransack/adapters/active_record/base_spec.rb:548:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
spec/ransack/adapters/active_record/context_spec.rb:12:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
spec/ransack/adapters/active_record/context_spec.rb:84:77: C: [Corrected] Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
            search = Search.new(Person, { comments_body_not_eq: 'some_title'})
                                                                            ^
spec/ransack/helpers/form_helper_spec.rb:189:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(            /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+
desc/
                       ^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:205:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match( /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
                       ^
spec/ransack/helpers/form_helper_spec.rb:219:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(         /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+des
c/
                       ^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:235:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(                     /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=em
ail\+desc/
                       ^^^^^^^^^^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:261:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(          /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+de
sc/
                       ^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:277:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(                /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+asc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+
desc/
                       ^^^^^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:292:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(            /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\
+desc/
                       ^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:309:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(                     /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=e
mail\+desc/
                       ^^^^^^^^^^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:324:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(            /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\
+desc/
                       ^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:341:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(                     /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=e
mail\+desc/
                       ^^^^^^^^^^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:356:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(      /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+asc/
                       ^^^^^^
spec/ransack/helpers/form_helper_spec.rb:373:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(                     /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=e
mail\+asc/
                       ^^^^^^^^^^^^^^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:388:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(  /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&amp;q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
                       ^^
spec/ransack/helpers/form_helper_spec.rb:405:24: C: [Corrected] Layout/SpaceInsideParens: Space inside parentheses detected.
          should match(        /people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
                       ^^^^^^^^
spec/ransack/helpers/form_helper_spec.rb:646:62: C: [Corrected] Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
            c.custom_arrows = { default_arrow: "defaultarrow"}
                                                             ^
spec/ransack/helpers/form_helper_spec.rb:652:51: C: [Corrected] Layout/SpaceInsideHashLiteralBraces: Space inside } missing.
            c.custom_arrows = { default_arrow: nil}
                                                  ^
spec/ransack/nodes/grouping_spec.rb:83:43: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
                    'ransacker_args' => [1,2]
                                          ^
spec/ransack/nodes/grouping_spec.rb:93:43: C: [Corrected] Layout/SpaceAfterComma: Space missing after comma.
                    'ransacker_args' => [3,4]
                                          ^
spec/ransack/predicate_spec.rb:425:29: C: [Corrected] Layout/SpaceInsideBlockBraces: Space between { and | missing.
          Ransack.configure {|c| c.add_predicate "not_in_csv", arel_predicate: "not_in", formatter: proc { |v| v.split(",") } }
                            ^^
spec/support/schema.rb:90:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.
spec/support/schema.rb:113:1: C: [Corrected] Layout/EmptyLines: Extra blank line detected.

70 files inspected, 50 offenses detected, 50 offenses corrected
$

- RuboCop version is locked to 0.81.0 which supports Ruby 2.3
Once Ransack bumps the required_ruby_version, RuboCop can be bumped.

- `DisabledByDefault: true` not to apply all of default cops

- Some Layout and Style cops are enabled to make initial changes small
Other cops can be enabled later.
@yahonda yahonda mentioned this pull request Dec 23, 2020
@ceritium
Copy link

Cool, JFYI, I created a PR for testing that the github actions works as expected when rubocop checks fail

#1187

Screenshot 2020-12-23 at 11 07 47

Copy link
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good to me, and I like the initial small set of cops that you chose 👍.

@scarroll32
Copy link
Member

Thank you @yahonda this is really great!

I like the initial small set of cops that you chose

I couldn't agree more, we can slowly add other cops later.

@scarroll32 scarroll32 merged commit bdaac5c into activerecord-hackery:master Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Rubocop
4 participants