From 4e10630940e9462a7c3eaa32781d1bc003fc0bbf Mon Sep 17 00:00:00 2001 From: Jose Farias <31393016+josefarias@users.noreply.github.com> Date: Tue, 5 Mar 2024 12:24:23 -0600 Subject: [PATCH] Add rubocop (#67) --- .github/workflows/{ci_tests.yml => ci.yml} | 21 +++++++-- .rubocop.yml | 12 ++++++ Gemfile | 4 +- Gemfile.lock | 43 +++++++++++++++++++ bin/rubocop | 3 ++ lib/hotwire_combobox/engine.rb | 2 +- .../new_options_forms_controller.rb | 4 +- .../dummy/app/controllers/users_controller.rb | 4 +- test/test_helper.rb | 2 +- 9 files changed, 85 insertions(+), 10 deletions(-) rename .github/workflows/{ci_tests.yml => ci.yml} (83%) create mode 100644 .rubocop.yml create mode 100755 bin/rubocop diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci.yml similarity index 83% rename from .github/workflows/ci_tests.yml rename to .github/workflows/ci.yml index 062ba28..a800bd0 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI Tests +name: CI on: push: @@ -7,13 +7,28 @@ on: pull_request: jobs: - build: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + bundler: default + bundler-cache: true + rubygems: latest + + - name: Lint code + run: bin/rubocop -f github + test: runs-on: ubuntu-latest steps: - name: SQLite3 version run: sqlite3 --version - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..d28bec5 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,12 @@ +inherit_gem: { rubocop-37signals: rubocop.yml } + +require: rubocop-capybara + +AllCops: + TargetRubyVersion: 3.0 + Exclude: + - "test/dummy/db/schema.rb" + +Layout/CommentIndentation: + Exclude: + - "lib/hotwire_combobox/helper.rb" diff --git a/Gemfile b/Gemfile index 03d251f..2e9ee91 100644 --- a/Gemfile +++ b/Gemfile @@ -16,4 +16,6 @@ gem "turbo-rails" gem "propshaft" gem "minitest-focus" gem "geared_pagination" -gem "sprockets-rails", :require => "sprockets/railtie" +gem "sprockets-rails", require: "sprockets/railtie" +gem "rubocop-37signals", require: false +gem "rubocop-capybara", require: false diff --git a/Gemfile.lock b/Gemfile.lock index b8481b6..e31132f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,6 +85,7 @@ GEM tzinfo (~> 2.0) addressable (2.8.6) public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) base64 (0.2.0) bigdecimal (3.1.6) builder (3.2.4) @@ -122,6 +123,8 @@ GEM irb (1.11.2) rdoc reline (>= 0.4.2) + json (2.7.1) + language_server-protocol (3.17.0.3) loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) @@ -151,6 +154,10 @@ GEM racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) + parallel (1.24.0) + parser (3.3.0.5) + ast (~> 2.4.1) + racc propshaft (0.8.0) actionpack (>= 7.0.0) activesupport (>= 7.0.0) @@ -199,6 +206,7 @@ GEM rake (>= 12.2) thor (~> 1.0, >= 1.2.2) zeitwerk (~> 2.6) + rainbow (3.1.1) rake (13.1.0) rdoc (6.6.2) psych (>= 4.0.0) @@ -206,6 +214,38 @@ GEM reline (0.4.3) io-console (~> 0.5) rexml (3.2.6) + rubocop (1.61.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.30.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-37signals (1.0.0) + rubocop + rubocop-minitest + rubocop-performance + rubocop-rails + rubocop-ast (1.31.1) + parser (>= 3.3.0.4) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-minitest (0.34.5) + rubocop (>= 1.39, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-performance (1.20.2) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.30.0, < 2.0) + rubocop-rails (2.24.0) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) rubyzip (2.3.2) selenium-webdriver (4.10.0) @@ -232,6 +272,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) webdrivers (5.3.1) nokogiri (~> 1.6) rubyzip (>= 1.3.0) @@ -258,6 +299,8 @@ DEPENDENCIES minitest-focus propshaft puma + rubocop-37signals + rubocop-capybara selenium-webdriver sprockets-rails sqlite3 diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..209c843 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require "bundler/setup" +load Gem.bin_path("rubocop", "rubocop") diff --git a/lib/hotwire_combobox/engine.rb b/lib/hotwire_combobox/engine.rb index 58d680d..a81f813 100644 --- a/lib/hotwire_combobox/engine.rb +++ b/lib/hotwire_combobox/engine.rb @@ -10,7 +10,7 @@ class Engine < ::Rails::Engine unless HotwireCombobox.bypass_convenience_methods? module FormBuilderExtensions def combobox(*args, **kwargs) - @template.hw_combobox_tag *args, **kwargs.merge(form: self) + @template.hw_combobox_tag(*args, **kwargs.merge(form: self)) end end diff --git a/test/dummy/app/controllers/new_options_forms_controller.rb b/test/dummy/app/controllers/new_options_forms_controller.rb index b22fb0a..5113a49 100644 --- a/test/dummy/app/controllers/new_options_forms_controller.rb +++ b/test/dummy/app/controllers/new_options_forms_controller.rb @@ -14,7 +14,7 @@ def user_params .permit( :favorite_state_id, :home_state_id, - favorite_state_attributes: [:name], - home_state_attributes: [:name]) + favorite_state_attributes: %i[ name ], + home_state_attributes: %i[ name ]) end end diff --git a/test/dummy/app/controllers/users_controller.rb b/test/dummy/app/controllers/users_controller.rb index e76575d..f428407 100644 --- a/test/dummy/app/controllers/users_controller.rb +++ b/test/dummy/app/controllers/users_controller.rb @@ -20,7 +20,7 @@ def user_params .permit( :favorite_state_id, :home_state_id, - favorite_state_attributes: [:name], - home_state_attributes: [:name]) + favorite_state_attributes: %i[ name ], + home_state_attributes: %i[ name ]) end end diff --git a/test/test_helper.rb b/test/test_helper.rb index c5eda96..fd29442 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -2,7 +2,7 @@ ENV["RAILS_ENV"] = "test" require_relative "../test/dummy/config/environment" -ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)] +ActiveRecord::Migrator.migrations_paths = [ File.expand_path("../test/dummy/db/migrate", __dir__) ] ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__) require "rails/test_help"