From b6b8ed18ec37d76b803936440742b6b851a9510e Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Tue, 28 May 2024 11:04:26 -0600 Subject: [PATCH 1/7] Move dev deps to Gemfile --- Gemfile | 9 +++++++++ progress_bar.gemspec | 9 +-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index dbc8bdd..4b1e313 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,12 @@ source "https://rubygems.org" gemspec + +group :development, :test do + gem "rake" + gem "reek" + gem "rspec" + gem "rubocop" + gem "rubocop-rspec" + gem "timecop" +end diff --git a/progress_bar.gemspec b/progress_bar.gemspec index 4d253a1..e71217d 100644 --- a/progress_bar.gemspec +++ b/progress_bar.gemspec @@ -18,15 +18,8 @@ Gem::Specification.new do |s| s.add_dependency("highline", [">= 1.6", "< 3"]) s.add_dependency("options", "~> 2.3.0") - s.add_development_dependency("rake") - s.add_development_dependency("reek") - s.add_development_dependency("rspec") - s.add_development_dependency("rubocop") - s.add_development_dependency("rubocop-rspec") - s.add_development_dependency("timecop") - s.files = `git ls-files`.split("\n") - s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] + s.metadata["rubygems_mfa_required"] = "true" end From 501a33674ab8815f701ea5f87308e87e6f59d7c0 Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Tue, 28 May 2024 11:04:43 -0600 Subject: [PATCH 2/7] Update rubocop --- .rubocop.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1c23fb0..8b72e23 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -23,7 +23,7 @@ Layout/HashAlignment: EnforcedColonStyle: table Lint/AmbiguousBlockAssociation: Exclude: - - "spec/**/*" # `expect { }.to change { }` is fine + - "spec/**/*" # `expect { }.to change { }` is fine Lint/ShadowingOuterLocalVariable: # Shadowing outer local variables with block parameters is often useful to # not reinvent a new name for the same thing, it highlights the relation @@ -37,7 +37,7 @@ Metrics/BlockLength: - Guardfile - shared_context - feature - ExcludedMethods: + AllowedMethods: - configure - context - define @@ -83,8 +83,6 @@ Style/SymbolArray: MinSize: 4 # Rspec -Capybara/FeatureMethods: - Enabled: false RSpec/ContextWording: Enabled: false RSpec/DescribeClass: From e8674aadd92be35ee829172380e3e789afe55144 Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Tue, 28 May 2024 11:13:07 -0600 Subject: [PATCH 3/7] Add danger for rubocop --- .github/workflows/danger.yml | 17 +++++++++++++++++ Dangerfile | 6 ++++++ Gemfile | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 .github/workflows/danger.yml create mode 100644 Dangerfile diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml new file mode 100644 index 0000000..ccd0d9f --- /dev/null +++ b/.github/workflows/danger.yml @@ -0,0 +1,17 @@ +name: Run Danger on PRs + +on: + pull_request: + types: [opened, synchronize] + +jobs: + danger: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - run: bundle exec danger + env: + DANGER_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 0000000..2c275e1 --- /dev/null +++ b/Dangerfile @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +# vi: ft=ruby + +github.dismiss_out_of_range_messages +rubocop.lint inline_comment: true diff --git a/Gemfile b/Gemfile index 4b1e313..18ca0d4 100644 --- a/Gemfile +++ b/Gemfile @@ -12,4 +12,6 @@ group :development, :test do gem "rubocop" gem "rubocop-rspec" gem "timecop" + + gem "danger-rubocop", "~> 0.13.0" end From e57c35872befe0d47fa439127ad215b29dfdfda2 Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Tue, 28 May 2024 11:15:27 -0600 Subject: [PATCH 4/7] Update rspec github action ruby matrix --- .github/workflows/rspec.yml | 23 +++++++++++------------ .ruby-version | 1 + 2 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 .ruby-version diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 0c562e7..82544a0 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -8,20 +8,19 @@ jobs: strategy: matrix: ruby: - - 2.4.x - - 2.5.x - - 2.6.x - - 2.7.x + - "2.7" + - "3.0" + - "3.1" + - "3.2" + - "3.3" + - "3.4" + - head steps: - - uses: actions/checkout@v1 - - uses: actions/setup-ruby@v1 + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - - name: Install dependencies - run: | - gem install bundler --no-document - bundle install - + bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: RSpec run: | - rspec + bundle exec rspec diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..15a2799 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.3.0 From 681533f3f5242bd5e1cfe1972b62546d5b70db24 Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Tue, 28 May 2024 11:15:40 -0600 Subject: [PATCH 5/7] Remove pronto workflow --- .github/workflows/pronto.yml | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 .github/workflows/pronto.yml diff --git a/.github/workflows/pronto.yml b/.github/workflows/pronto.yml deleted file mode 100644 index 9accb3a..0000000 --- a/.github/workflows/pronto.yml +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Lint -"on": [pull_request] -jobs: - lint: - name: Pronto - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1.0.0 - - uses: actions/setup-ruby@v1 - with: - ruby-version: '2.7' - - name: Install dependencies - run: | - sudo apt-get update -qq - sudo apt-get install -qqy --no-install-recommends yamllint jq - gem install bundler --no-document - bundle install - gem install --no-document \ - pronto \ - pronto-brakeman \ - pronto-flay \ - pronto-reek \ - pronto-rubocop \ - pronto-yamllint - - - name: Pronto - env: - PRONTO_GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - export PRONTO_PULL_REQUEST_ID=$(jq .number -r $GITHUB_EVENT_PATH) - pronto run -c origin/master -f github_status github_pr_review text From 95d6856f43ac9c244c705a8bf639b171d0640449 Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Tue, 28 May 2024 11:31:32 -0600 Subject: [PATCH 6/7] Remove highline constraint --- progress_bar.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/progress_bar.gemspec b/progress_bar.gemspec index e71217d..cfd3d81 100644 --- a/progress_bar.gemspec +++ b/progress_bar.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.required_ruby_version = ">= 2.4.0" - s.add_dependency("highline", [">= 1.6", "< 3"]) + s.add_dependency("highline", ">= 1.6") s.add_dependency("options", "~> 2.3.0") s.files = `git ls-files`.split("\n") From 634b3ab636cbd06013445244298c7cff8bf603ba Mon Sep 17 00:00:00 2001 From: Paul Sadauskas Date: Tue, 28 May 2024 11:34:10 -0600 Subject: [PATCH 7/7] Rubocop autofixes --- lib/progress_bar.rb | 20 +++++++++++--------- spec/with_progress_spec.rb | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/progress_bar.rb b/lib/progress_bar.rb index 0b1c331..23da27b 100644 --- a/lib/progress_bar.rb +++ b/lib/progress_bar.rb @@ -30,10 +30,10 @@ def initialize(*args) def increment!(count = 1) @count += count now = ::Time.now - if (now - @last_write) > 0.2 || @count >= max - write - @last_write = now - end + return unless (now - @last_write) > 0.2 || @count >= max + + write + @last_write = now end def puts(text) @@ -93,7 +93,7 @@ def print(str) end def clear! - print "\r" + " " * terminal_width + "\r" + print "\r" + (" " * terminal_width) + "\r" end def render(meter) @@ -152,12 +152,13 @@ def bar_width def non_bar_width meters.reject { |meter| meter == :bar }.inject(0) do |width, meter| - width += width_of(meter) + 1 + width + width_of(meter) + 1 end end - def counter_width # [ 1/100] - max_width * 2 + 3 + # [ 1/100] + def counter_width + (max_width * 2) + 3 end def percentage_width @@ -176,7 +177,8 @@ def eta_width format_interval(eta).length + 2 end - def rate_width # [ 23.45/s] + # [ 23.45/s] + def rate_width render_rate.length end diff --git a/spec/with_progress_spec.rb b/spec/with_progress_spec.rb index b92b332..b87737c 100644 --- a/spec/with_progress_spec.rb +++ b/spec/with_progress_spec.rb @@ -30,7 +30,7 @@ it "should give Enumerator" do enum = (1..20).each_with_progress - expect(enum).to be_kind_of(Enumerator) + expect(enum).to be_a(Enumerator) expect(bar.max).to eq 20 expect(bar.count).to eq 0