Skip to content

Commit 42f1844

Browse files
committed
Add rubocop
1 parent 3249cdf commit 42f1844

File tree

5 files changed

+270
-0
lines changed

5 files changed

+270
-0
lines changed

.rubocop.yml

+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
AllCops:
4+
Exclude:
5+
- !ruby/regexp /(vendor|bundle|bin|db)\/.*/
6+
DisplayCopNames: true
7+
DisplayStyleGuide: true
8+
TargetRubyVersion: 2.2
9+
# https://github.com/bbatsov/rubocop/blob/master/manual/caching.md
10+
# https://github.com/bbatsov/rubocop/blob/e8680418b351491e111a18cf5b453fc07a3c5239/config/default.yml#L60-L77
11+
UseCache: true
12+
CacheRootDirectory: tmp
13+
14+
Rails:
15+
Enabled: true
16+
17+
Style/NumericPredicate:
18+
Enabled: false
19+
20+
# Rubocop options don't align with code-style, which allows alias.
21+
# https://github.com/bbatsov/ruby-style-guide/pull/383
22+
# https://github.com/bbatsov/rubocop/issues/1460
23+
# see https://github.com/bbatsov/ruby-style-guide#alias-method-lexically
24+
# vs. https://github.com/bbatsov/ruby-style-guide#alias-method
25+
Style/Alias:
26+
Enabled: false
27+
28+
Style/SingleLineBlockParams:
29+
Enabled: false
30+
31+
# SupportedStyles: line_count_based, semantic, braces_for_chaining
32+
Style/BlockDelimiters:
33+
Enabled: true
34+
EnforcedStyle: line_count_based
35+
36+
Style/MissingElse:
37+
Enabled: true
38+
EnforcedStyle: case
39+
40+
Style/EmptyElse:
41+
EnforcedStyle: empty
42+
43+
Style/AlignParameters:
44+
EnforcedStyle: with_fixed_indentation
45+
Enabled: true
46+
47+
Style/AlignHash:
48+
EnforcedHashRocketStyle: key
49+
EnforcedColonStyle: key
50+
EnforcedLastArgumentHashStyle: ignore_implicit
51+
52+
Style/IndentHash:
53+
EnforcedStyle: consistent
54+
55+
Style/IndentationWidth:
56+
Width: 2
57+
58+
Style/MultilineOperationIndentation:
59+
EnforcedStyle: indented
60+
61+
Style/ClosingParenthesisIndentation:
62+
Enabled: false
63+
64+
Style/SpaceInsideHashLiteralBraces:
65+
EnforcedStyle: no_space
66+
67+
Style/FirstParameterIndentation:
68+
EnforcedStyle: special_for_inner_method_call_in_parentheses
69+
70+
Style/ExtraSpacing:
71+
Enabled: true
72+
73+
Lint/BlockAlignment:
74+
Enabled: true
75+
EnforcedStyleAlignWith: either
76+
77+
Lint/EndAlignment:
78+
Enabled: true
79+
80+
Style/SpaceAfterColon:
81+
Enabled: true
82+
83+
Style/SpaceAfterComma:
84+
Enabled: true
85+
86+
Style/SpaceAfterNot:
87+
Enabled: true
88+
89+
Style/SpaceAroundEqualsInParameterDefault:
90+
EnforcedStyle: no_space
91+
92+
Style/SpaceBeforeBlockBraces:
93+
Enabled: false
94+
# EnforcedStyle: space
95+
96+
Style/SpaceInsideBlockBraces:
97+
EnforcedStyle: space
98+
EnforcedStyleForEmptyBraces: no_space
99+
# Space between { and |. Overrides EnforcedStyle if there is a conflict.
100+
SpaceBeforeBlockParameters: true
101+
102+
Style/SpaceInsideBrackets:
103+
Enabled: true
104+
105+
Style/SpaceInsideParens:
106+
Enabled: true
107+
108+
Style/EmptyLines:
109+
Enabled: true
110+
111+
Style/EmptyLinesAroundAccessModifier:
112+
Enabled: true
113+
114+
Style/EmptyLinesAroundBlockBody:
115+
EnforcedStyle: no_empty_lines
116+
117+
Style/EmptyLinesAroundClassBody:
118+
EnforcedStyle: no_empty_lines
119+
120+
Style/EmptyLinesAroundModuleBody:
121+
EnforcedStyle: no_empty_lines
122+
123+
Style/EmptyLinesAroundMethodBody:
124+
Enabled: true
125+
126+
Style/EmptyLineBetweenDefs:
127+
Enabled: true
128+
129+
Style/LeadingCommentSpace:
130+
Enabled: true
131+
132+
Style/TrailingCommaInLiteral:
133+
EnforcedStyleForMultiline: no_comma
134+
135+
Style/TrailingCommaInArguments:
136+
EnforcedStyleForMultiline: no_comma
137+
138+
Style/TrailingWhitespace:
139+
Enabled: true
140+
141+
Style/PercentLiteralDelimiters:
142+
PreferredDelimiters:
143+
'%': '{}'
144+
'%i': ()
145+
'%q': ()
146+
'%Q': ()
147+
'%r': '{}'
148+
'%s': ()
149+
'%w': ()
150+
'%W': ()
151+
'%x': ()
152+
153+
Style/StringLiterals:
154+
# EnforcedStyle: single_quotes
155+
Enabled: false
156+
157+
Style/StringLiteralsInInterpolation:
158+
# EnforcedStyle: single_quotes
159+
Enabled: false
160+
161+
Style/RegexpLiteral:
162+
Enabled: false
163+
164+
Lint/AssignmentInCondition:
165+
# AllowSafeAssignment: true
166+
# accepts = in condition surrounded with braces, e.g. if (test = 10)
167+
# accepts []= in condition surrounded with braces, e.g. if (test[0] = 10)
168+
Enabled: true
169+
170+
Style/VariableNumber:
171+
Enabled: false
172+
173+
Rails/HttpPositionalArguments:
174+
Enabled: false
175+
176+
Style/IndentArray:
177+
EnforcedStyle: consistent
178+
179+
Style/NumericLiterals:
180+
Enabled: false
181+
182+
Style/Documentation:
183+
Enabled: false
184+
185+
Style/SpaceInLambdaLiteral:
186+
EnforcedStyle: require_no_space
187+
188+
Style/DoubleNegation:
189+
Enabled: false
190+
191+
Metrics/LineLength:
192+
Max: 100

.rubocop_todo.yml

Whitespace-only changes.

bin/rubocop

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Usage:
4+
# bin/rubocop [-A|-t|-h]
5+
#
6+
# Options:
7+
# Autocorrect -A
8+
# Make todo -t
9+
# Usage -h,--help,help
10+
11+
set -e
12+
13+
case $1 in
14+
-A)
15+
echo "Rubocop autocorrect is ON" >&2
16+
bundle exec rake -f lib/tasks/rubocop.rake rubocop:auto_correct
17+
;;
18+
19+
-t)
20+
echo "Rubocop is generating a new TODO" >&2
21+
bundle exec rake -f lib/tasks/rubocop.rake rubocop:auto_gen_config
22+
;;
23+
24+
-h|--help|help)
25+
sed -ne '/^#/!q;s/.\{1,2\}//;1d;p' < "$0"
26+
;;
27+
28+
*)
29+
# with no args, run vanilla rubocop
30+
# else assume we're passing in arbitrary arguments
31+
if [ -z "$1" ]; then
32+
bundle exec rake -f lib/tasks/rubocop.rake rubocop
33+
else
34+
bundle exec rubocop "$@"
35+
fi
36+
;;
37+
esac

lib/tasks/rubocop.rake

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
begin
2+
require "rubocop"
3+
require "rubocop/rake_task"
4+
rescue LoadError # rubocop:disable Lint/HandleExceptions
5+
else
6+
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
7+
patterns = [
8+
'Gemfile',
9+
'Rakefile',
10+
'apps/**/Gemfile',
11+
'apps/**/Rakefile',
12+
'apps/**/*.{rb,rake,gemspec}',
13+
'lib/**/*.{rb,rake}',
14+
'config/**/*.rb',
15+
'app/**/*.rb',
16+
'spec/**/*.rb'
17+
]
18+
desc 'Execute rubocop'
19+
RuboCop::RakeTask.new(:rubocop) do |task|
20+
task.formatters = ['progress']
21+
task.patterns = patterns
22+
task.fail_on_error = true
23+
end
24+
25+
namespace :rubocop do
26+
desc 'Auto-gen rubocop config'
27+
task :auto_gen_config do
28+
options = ['--auto-gen-config'].concat patterns
29+
require 'benchmark'
30+
result = 0
31+
cli = RuboCop::CLI.new
32+
time = Benchmark.realtime do
33+
result = cli.run(options)
34+
end
35+
puts "Finished in #{time} seconds" if cli.options[:debug]
36+
abort('RuboCop failed!') if result.nonzero?
37+
end
38+
end
39+
end

swagger_ui_engine.gemspec

+2
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ Gem::Specification.new do |s|
2121
]
2222

2323
s.add_runtime_dependency 'rails', ['>= 4.2', '<= 5.2.0']
24+
25+
s.add_development_dependency 'rubocop'
2426
end

0 commit comments

Comments
 (0)