From 89eefbffaab2808cfb12a1dfc0e42d76f12f35d9 Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 7 Apr 2023 15:58:18 +0200 Subject: [PATCH] Initial RuboCop implementation --- .github/workflows/ci.yml | 2 +- .gitignore | 3 + .rubocop.yml | 3 + Gemfile | 10 +++ Gemfile.lock | 128 ++++++++++++++++++++++++++++++++++ README.md | 57 +++++++++++++++ Rakefile | 17 +++++ lib/voxpupuli/rubocop.rb | 1 + lib/voxpupuli/rubocop/rake.rb | 9 +++ rubocop.yml | 38 ++++++++++ voxpupuli-rubocop.gemspec | 21 ++++++ 11 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .rubocop.yml create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 README.md create mode 100644 Rakefile create mode 100644 lib/voxpupuli/rubocop.rb create mode 100644 lib/voxpupuli/rubocop/rake.rb create mode 100644 rubocop.yml create mode 100644 voxpupuli-rubocop.gemspec diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3a658f1..3b340da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,4 +23,4 @@ jobs: - name: Run Rubocop run: bundle exec rake rubocop - name: Build gem - run: gem build *.gemspec + run: gem build --strict --verbose *.gemspec diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5dafc55 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vendor/ +vendor/ +.bundle/ diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..854be61 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,3 @@ +--- +inherit_from: + - rubocop.yml diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..299a0de --- /dev/null +++ b/Gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +source ENV['GEM_SOURCE'] || 'https://rubygems.org' + +gemspec + +group :release do + gem 'faraday-retry', require: false + gem 'github_changelog_generator', require: false +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d22e719 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,128 @@ +PATH + remote: . + specs: + voxpupuli-rubocop (1.0.0) + rake (~> 13.0, >= 13.0.6) + rubocop (~> 1.49.0) + rubocop-performance (~> 1.16.0) + rubocop-rake (~> 0.6.0) + rubocop-rspec (~> 2.19.0) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (7.0.4.3) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + addressable (2.8.3) + public_suffix (>= 2.0.2, < 6.0) + ast (2.4.2) + async (1.31.0) + console (~> 1.10) + nio4r (~> 2.3) + timers (~> 4.1) + async-http (0.60.1) + async (>= 1.25) + async-io (>= 1.28) + async-pool (>= 0.2) + protocol-http (~> 0.24.0) + protocol-http1 (~> 0.15.0) + protocol-http2 (~> 0.15.0) + traces (>= 0.8.0) + async-http-faraday (0.11.0) + async-http (~> 0.42) + faraday + async-io (1.34.3) + async + async-pool (0.4.0) + async (>= 1.25) + concurrent-ruby (1.2.2) + console (1.16.2) + fiber-local + faraday (2.7.4) + faraday-net_http (>= 2.0, < 3.1) + ruby2_keywords (>= 0.0.4) + faraday-http-cache (2.4.1) + faraday (>= 0.8) + faraday-net_http (3.0.2) + faraday-retry (2.1.0) + faraday (~> 2.0) + fiber-local (1.0.0) + github_changelog_generator (1.16.4) + activesupport + async (>= 1.25.0) + async-http-faraday + faraday-http-cache + multi_json + octokit (~> 4.6) + rainbow (>= 2.2.1) + rake (>= 10.0) + i18n (1.12.0) + concurrent-ruby (~> 1.0) + json (2.6.3) + minitest (5.18.0) + multi_json (1.15.0) + nio4r (2.5.9) + octokit (4.25.1) + faraday (>= 1, < 3) + sawyer (~> 0.9) + parallel (1.22.1) + parser (3.2.2.0) + ast (~> 2.4.1) + protocol-hpack (1.4.2) + protocol-http (0.24.1) + protocol-http1 (0.15.0) + protocol-http (~> 0.22) + protocol-http2 (0.15.1) + protocol-hpack (~> 1.4) + protocol-http (~> 0.18) + public_suffix (5.0.1) + rainbow (3.1.1) + rake (13.0.6) + regexp_parser (2.7.0) + rexml (3.2.5) + rubocop (1.49.0) + json (~> 2.3) + parallel (~> 1.10) + parser (>= 3.2.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.28.0) + parser (>= 3.2.1.0) + rubocop-capybara (2.17.1) + rubocop (~> 1.41) + rubocop-performance (1.16.0) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.19.0) + rubocop (~> 1.33) + rubocop-capybara (~> 2.17) + ruby-progressbar (1.13.0) + ruby2_keywords (0.0.5) + sawyer (0.9.2) + addressable (>= 2.3.5) + faraday (>= 0.17.3, < 3) + timers (4.3.5) + traces (0.9.1) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.4.2) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + faraday-retry + github_changelog_generator + voxpupuli-rubocop! + +BUNDLED WITH + 2.4.1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..ba3aab2 --- /dev/null +++ b/README.md @@ -0,0 +1,57 @@ +# Vox Pupuli RuboCop Gem + +[![License](https://img.shields.io/github/license/voxpupuli/voxpupuli-rubocop.svg)](https://github.com/voxpupuli/voxpupuli-rubocop/blob/master/LICENSE) +[![Test](https://github.com/voxpupuli/voxpupuli-rubocop/actions/workflows/ci.yml/badge.svg)](https://github.com/voxpupuli/voxpupuli-rubocop/actions/workflows/ci.yml) +[![Release](https://github.com/voxpupuli/voxpupuli-rubocop/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/voxpupuli-rubocop/actions/workflows/release.yml) +[![RubyGem Version](https://img.shields.io/gem/v/voxpupuli-rubocop.svg)](https://rubygems.org/gems/voxpupuli-rubocop) +[![RubyGem Downloads](https://img.shields.io/gem/dt/voxpupuli-rubocop.svg)](https://rubygems.org/gems/voxpupuli-rubocop) + +This is one of the Vox Pupuli meta gems. It provides a convenient way to +configure [RuboCop](https://rubocop.org/). RuboCop is the de facto standard Ruby +Linter and Formatter. `voxpupuli-rubocop` depends on the correct RuboCop version ++ dependencies that we want to use in our CI pipelines. There is also a +[rubocop.yml](rubocop.yml) that configures RuboCop. and preconfigured rake +tasks. + +The goal of this gem is to provide a central configuration for RuboCop that's +used in all Vox Pupuli gems. + +## Usage + +In your Gemfile, add the following: + +``` +gem 'voxpupuli-rubocop', '~> 1.0' +``` + +In your Rakefile, include our Rake task: + +``` +require 'voxpupuli/rubocop/rake' +``` + +Now you can list your rake tasks and should see three new ones: + +```terminal +bundle exec rake -T +rake rubocop # Run RuboCop +rake rubocop:autocorrect # Autocorrect RuboCop offenses (only when it's safe) +rake rubocop:autocorrect_all # Autocorrect RuboCop offenses (safe and unsafe) +``` + +To use our default config, create a `.rubocop.yml`: + +``` +--- +inherit_gem: + beaker: rubocop.yml +``` + +You maybe see a bunch of violations with the new configuration. A common path +forward is to accept them but prevent future/more violations. You can generate +a "RuboCop ToDo file", which is basically an allow-list of all current +violations: + +``` +bundle exec rubocop --regenerate-todo +``` diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..3efb0cc --- /dev/null +++ b/Rakefile @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# $:.unshift File.dirname(__FILE__) +require 'voxpupuli/rubocop/rake' +begin + require 'github_changelog_generator/task' +rescue LoadError + # Do nothing if no required gem installed +else + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog] + config.user = 'voxpupuli' + config.project = 'voxpupuli-rubocop' + gem_version = Gem::Specification.load("#{config.project}.gemspec").version + config.future_release = gem_version + end +end diff --git a/lib/voxpupuli/rubocop.rb b/lib/voxpupuli/rubocop.rb new file mode 100644 index 0000000..8e9b8f9 --- /dev/null +++ b/lib/voxpupuli/rubocop.rb @@ -0,0 +1 @@ +# frozen_string_literal: true diff --git a/lib/voxpupuli/rubocop/rake.rb b/lib/voxpupuli/rubocop/rake.rb new file mode 100644 index 0000000..bc09dc7 --- /dev/null +++ b/lib/voxpupuli/rubocop/rake.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'rubocop/rake_task' +RuboCop::RakeTask.new(:rubocop) do |task| + # These make the rubocop experience maybe slightly less terrible + task.options = ['--display-cop-names', '--display-style-guide', '--extra-details'] + # Use Rubocop's Github Actions formatter if possible + task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true' +end diff --git a/rubocop.yml b/rubocop.yml new file mode 100644 index 0000000..ef6f743 --- /dev/null +++ b/rubocop.yml @@ -0,0 +1,38 @@ +--- +require: + - rubocop-performance + - rubocop-rake + - rubocop-rspec + +AllCops: + NewCops: enable + DisplayCopNames: true + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' + Exclude: + - vendor/**/* + - .vendor/**/* + +# this currently doesn't work with the way we handle our secrets +Gemspec/RequireMFA: + Enabled: false + +# current Vox Pupuli default is to use `add_development_dependency` in the gemspec +Gemspec/DevelopmentDependencies: + Enabled: false + +Style/TrailingCommaInHashLiteral: + Enabled: True + EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInArrayLiteral: + Enabled: True + EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInArguments: + Enabled: True + EnforcedStyleForMultiline: comma + +Metrics: + Enabled: false diff --git a/voxpupuli-rubocop.gemspec b/voxpupuli-rubocop.gemspec new file mode 100644 index 0000000..71085e2 --- /dev/null +++ b/voxpupuli-rubocop.gemspec @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +Gem::Specification.new do |s| + s.name = 'voxpupuli-rubocop' + s.version = '1.0.0' + s.authors = ['Vox Pupuli'] + s.email = ['voxpupuli@groups.io'] + s.homepage = 'https://github.com/voxpupuli/voxpupuli-rubocop' + s.summary = 'Helper Gem that pulls in all the RuboCop related gems and provides a RuboCop configuration' + s.description = 'Used in Vox Pupuli gems to configure RuboCop in a unified and centralised way' + s.licenses = 'Apache-2.0' + s.files = Dir['lib/**/*.rb'] + + s.required_ruby_version = '>= 2.7.0' + + s.add_runtime_dependency 'rake', '~> 13.0', '>= 13.0.6' + s.add_runtime_dependency 'rubocop', '~> 1.49.0' + s.add_runtime_dependency 'rubocop-performance', '~> 1.16.0' + s.add_runtime_dependency 'rubocop-rake', '~> 0.6.0' + s.add_runtime_dependency 'rubocop-rspec', '~> 2.19.0' +end