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

Initial RuboCop implementation #1

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vendor/
vendor/
.bundle/
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
inherit_from:
- rubocop.yml
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
128 changes: 128 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
17 changes: 17 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/voxpupuli/rubocop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# frozen_string_literal: true
9 changes: 9 additions & 0 deletions lib/voxpupuli/rubocop/rake.rb
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions voxpupuli-rubocop.gemspec
Original file line number Diff line number Diff line change
@@ -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