Skip to content

Commit 5799fa2

Browse files
authored
Add Rubocop Action & autocorrect violations (#112)
* Add Rubocop Action * Update changelog
1 parent 38e7c90 commit 5799fa2

40 files changed

+139
-175
lines changed

.github/workflows/rubocop.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Rubocop
2+
on: [pull_request]
3+
jobs:
4+
rubocop:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v3
8+
- name: Set up Ruby
9+
uses: ruby/setup-ruby@v1
10+
with:
11+
ruby-version: "3.2"
12+
bundler-cache: true
13+
- name: Run Rubocop
14+
run: bundle exec rubocop

.rubocop.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
AllCops:
2-
Exclude:
3-
- vendor/**/*
2+
TargetRubyVersion: 2.7
43

54
inherit_from: .rubocop_todo.yml

.rubocop_todo.yml

Lines changed: 19 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,47 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2019-12-08 10:39:57 -0500 using RuboCop version 0.77.0.
3+
# on 2023-03-30 00:44:45 UTC using RuboCop version 1.48.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 8
10-
# Configuration parameters: Include.
11-
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
12-
Bundler/DuplicatedGem:
13-
Exclude:
14-
- 'Gemfile'
15-
16-
# Offense count: 8
17-
# Cop supports --auto-correct.
18-
# Configuration parameters: TreatCommentsAsGroupSeparators, Include.
19-
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
20-
Bundler/OrderedGems:
21-
Exclude:
22-
- 'Gemfile'
23-
249
# Offense count: 1
25-
# Cop supports --auto-correct.
26-
Layout/EmptyLineAfterGuardClause:
27-
Exclude:
28-
- 'app/controllers/grape_swagger_rails/application_controller.rb'
29-
30-
# Offense count: 1
31-
# Cop supports --auto-correct.
32-
Layout/EmptyLineAfterMagicComment:
10+
# Configuration parameters: Severity, Include.
11+
# Include: **/*.gemspec
12+
Gemspec/RequiredRubyVersion:
3313
Exclude:
3414
- 'grape-swagger-rails.gemspec'
3515

36-
# Offense count: 1
37-
# Cop supports --auto-correct.
38-
Layout/EmptyLinesAroundArguments:
39-
Exclude:
40-
- 'lib/grape-swagger-rails.rb'
41-
42-
# Offense count: 12
43-
# Cop supports --auto-correct.
44-
# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle.
45-
# SupportedHashRocketStyles: key, separator, table
46-
# SupportedColonStyles: key, separator, table
47-
# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit
48-
Layout/HashAlignment:
49-
Exclude:
50-
- 'lib/grape-swagger-rails.rb'
51-
52-
# Offense count: 1
53-
Lint/AmbiguousRegexpLiteral:
16+
# Offense count: 2
17+
# Configuration parameters: AllowedMethods.
18+
# AllowedMethods: enums
19+
Lint/ConstantDefinitionInBlock:
5420
Exclude:
5521
- 'lib/tasks/swagger_ui.rake'
5622

5723
# Offense count: 1
58-
# Configuration parameters: AllowSafeAssignment.
59-
Lint/AssignmentInCondition:
60-
Exclude:
61-
- 'spec/dummy/bin/spring'
62-
63-
# Offense count: 2
64-
# Cop supports --auto-correct.
65-
Lint/ScriptPermission:
66-
Exclude:
67-
- 'Rakefile'
68-
- 'spec/dummy/Rakefile'
69-
70-
# Offense count: 2
71-
# Configuration parameters: AllowComments.
72-
Lint/SuppressedException:
24+
Lint/MixedRegexpCaptureTypes:
7325
Exclude:
74-
- 'spec/dummy/bin/rails'
75-
- 'spec/dummy/bin/rake'
26+
- 'lib/tasks/swagger_ui.rake'
7627

7728
# Offense count: 9
78-
# Configuration parameters: CountComments, ExcludedMethods.
79-
# ExcludedMethods: refine
29+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
30+
# AllowedMethods: refine
8031
Metrics/BlockLength:
8132
Max: 282
8233

8334
# Offense count: 2
84-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
35+
# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms.
36+
# CheckDefinitionPathHierarchyRoots: lib, spec, test, src
8537
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
8638
Naming/FileName:
8739
Exclude:
8840
- 'lib/grape-swagger-rails.rb'
8941
- 'spec/features/grape-swagger-rails_spec.rb'
9042

91-
# Offense count: 2
92-
# Cop supports --auto-correct.
93-
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners.
94-
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
95-
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
96-
# FunctionalMethods: let, let!, subject, watch
97-
# IgnoredMethods: lambda, proc, it
98-
Style/BlockDelimiters:
99-
Exclude:
100-
- 'lib/tasks/swagger_ui.rake'
101-
10243
# Offense count: 4
44+
# Configuration parameters: AllowedConstants.
10345
Style/Documentation:
10446
Exclude:
10547
- 'spec/**/*'
@@ -108,72 +50,9 @@ Style/Documentation:
10850
- 'lib/grape-swagger-rails.rb'
10951
- 'lib/grape-swagger-rails/engine.rb'
11052

111-
# Offense count: 2
112-
# Cop supports --auto-correct.
113-
# Configuration parameters: EnforcedStyle.
114-
# SupportedStyles: compact, expanded
115-
Style/EmptyMethod:
116-
Exclude:
117-
- 'app/controllers/grape_swagger_rails/application_controller.rb'
118-
- 'spec/dummy/app/controllers/welcome_controller.rb'
119-
12053
# Offense count: 1
121-
# Cop supports --auto-correct.
122-
Style/Encoding:
123-
Exclude:
124-
- 'grape-swagger-rails.gemspec'
125-
126-
# Offense count: 14
127-
# Cop supports --auto-correct.
128-
Style/ExpandPathArguments:
129-
Exclude:
130-
- 'Rakefile'
131-
- 'grape-swagger-rails.gemspec'
132-
- 'lib/script/rails'
133-
- 'lib/tasks/swagger_ui.rake'
134-
- 'spec/dummy/Rakefile'
135-
- 'spec/dummy/bin/bundle'
136-
- 'spec/dummy/bin/rails'
137-
- 'spec/dummy/bin/rake'
138-
- 'spec/dummy/config/application.rb'
139-
- 'spec/dummy/config/boot.rb'
140-
- 'spec/dummy/config/environment.rb'
141-
- 'spec/spec_helper.rb'
142-
143-
# Offense count: 37
144-
# Cop supports --auto-correct.
145-
# Configuration parameters: EnforcedStyle.
146-
# SupportedStyles: always, never
147-
Style/FrozenStringLiteralComment:
148-
Enabled: false
149-
150-
# Offense count: 3
151-
# Cop supports --auto-correct.
152-
# Configuration parameters: PreferredDelimiters.
153-
Style/PercentLiteralDelimiters:
154-
Exclude:
155-
- 'grape-swagger-rails.gemspec'
156-
- 'lib/grape-swagger-rails.rb'
157-
- 'spec/features/swagger_spec.rb'
158-
159-
# Offense count: 1
160-
# Cop supports --auto-correct.
161-
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
162-
# SupportedStyles: slashes, percent_r, mixed
163-
Style/RegexpLiteral:
164-
Exclude:
165-
- 'lib/tasks/swagger_ui.rake'
166-
167-
# Offense count: 2
168-
# Cop supports --auto-correct.
169-
# Configuration parameters: MinSize.
170-
# SupportedStyles: percent, brackets
171-
Style/SymbolArray:
172-
EnforcedStyle: brackets
173-
174-
# Offense count: 48
175-
# Cop supports --auto-correct.
176-
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
54+
# This cop supports safe autocorrection (--autocorrect).
55+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
17756
# URISchemes: http, https
178-
Metrics/LineLength:
179-
Max: 129
57+
Layout/LineLength:
58+
Max: 124

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* Your contribution here.
44
* [#110](https://github.com/ruby-grape/grape-swagger-rails/pull/110): Update dummy app to current rails conventions - [@duffn](https://github.com/duffn).
5+
* [#112](https://github.com/ruby-grape/grape-swagger-rails/pull/112): Add Rubocop Action & autocorrect violations - [@duffn](https://github.com/duffn).
56

67
### 0.4.0 (2023/03/28)
78

Dangerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
danger.import_dangerfile(gem: 'ruby-grape-danger')

Gemfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
source 'https://rubygems.org'
24

35
gemspec
@@ -6,8 +8,8 @@ case version = ENV['GRAPE_SWAGGER_VERSION'] || '~> 1.6.0'
68
when 'HEAD'
79
gem 'grape-swagger', github: 'ruby-grape/grape-swagger'
810
else
9-
gem 'grape-swagger', version
1011
gem 'grape', '>= 1.3.0'
12+
gem 'grape-swagger', version
1113
end
1214

1315
group :development, :test do

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'bundler/setup'
24

35
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
@@ -16,4 +18,4 @@ RSpec::Core::RakeTask.new(:spec)
1618
require 'rubocop/rake_task'
1719
RuboCop::RakeTask.new(:rubocop)
1820

19-
task default: [:rubocop, :spec]
21+
task default: %i[rubocop spec]

app/controllers/grape_swagger_rails/application_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module GrapeSwaggerRails
24
class ApplicationController < ActionController::Base
35
if Rails::VERSION::MAJOR >= 4
@@ -6,13 +8,13 @@ class ApplicationController < ActionController::Base
68
before_filter { run_before_action }
79
end
810

9-
def index
10-
end
11+
def index; end
1112

1213
private
1314

1415
def run_before_action
1516
return unless GrapeSwaggerRails.options.before_action
17+
1618
instance_exec(request, &GrapeSwaggerRails.options.before_action)
1719
end
1820
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
GrapeSwaggerRails::Engine.routes.draw do
24
root to: 'application#index'
35
end

grape-swagger-rails.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
lib = File.expand_path('lib', __dir__)
24
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
35
require 'grape-swagger-rails/version'

0 commit comments

Comments
 (0)