Skip to content

Commit 3c97d9f

Browse files
committed
Setup rubocop and apply Rails style guide
1 parent 1361957 commit 3c97d9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+934
-690
lines changed

.rubocop.yml

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
AllCops:
2+
TargetRubyVersion: 2.5
3+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
4+
# to ignore them, so only the ones explicitly set in this file are enabled.
5+
DisabledByDefault: true
6+
Exclude:
7+
- '**/templates/**/*'
8+
- '**/vendor/**/*'
9+
- 'actionpack/lib/action_dispatch/journey/parser.rb'
10+
- 'railties/test/fixtures/tmp/**/*'
11+
- 'node_modules/**/*'
12+
- 'bin/*'
13+
14+
Performance:
15+
Exclude:
16+
- '**/test/**/*'
17+
18+
Rails:
19+
Enabled: true
20+
21+
# Prefer assert_not over assert !
22+
Rails/AssertNot:
23+
Include:
24+
- '**/test/**/*'
25+
26+
# Prefer assert_not_x over refute_x
27+
Rails/RefuteMethods:
28+
Include:
29+
- '**/test/**/*'
30+
31+
# Prefer &&/|| over and/or.
32+
Style/AndOr:
33+
Enabled: true
34+
35+
# Do not use braces for hash literals when they are the last argument of a
36+
# method call.
37+
Style/BracesAroundHashParameters:
38+
Enabled: true
39+
EnforcedStyle: context_dependent
40+
41+
# Align `when` with `case`.
42+
Layout/CaseIndentation:
43+
Enabled: true
44+
45+
# Align comments with method definitions.
46+
Layout/CommentIndentation:
47+
Enabled: true
48+
49+
Layout/ElseAlignment:
50+
Enabled: true
51+
52+
# Align `end` with the matching keyword or starting expression except for
53+
# assignments, where it should be aligned with the LHS.
54+
Layout/EndAlignment:
55+
Enabled: true
56+
EnforcedStyleAlignWith: variable
57+
AutoCorrect: true
58+
59+
Layout/EmptyLineAfterMagicComment:
60+
Enabled: true
61+
62+
Layout/EmptyLinesAroundBlockBody:
63+
Enabled: true
64+
65+
# In a regular class definition, no empty lines around the body.
66+
Layout/EmptyLinesAroundClassBody:
67+
Enabled: true
68+
69+
# In a regular method definition, no empty lines around the body.
70+
Layout/EmptyLinesAroundMethodBody:
71+
Enabled: true
72+
73+
# In a regular module definition, no empty lines around the body.
74+
Layout/EmptyLinesAroundModuleBody:
75+
Enabled: true
76+
77+
Layout/FirstParameterIndentation:
78+
Enabled: true
79+
80+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
81+
Style/HashSyntax:
82+
Enabled: true
83+
84+
# Method definitions after `private` or `protected` isolated calls need one
85+
# extra level of indentation.
86+
Layout/IndentationConsistency:
87+
Enabled: true
88+
EnforcedStyle: rails
89+
90+
# Two spaces, no tabs (for indentation).
91+
Layout/IndentationWidth:
92+
Enabled: true
93+
94+
Layout/LeadingCommentSpace:
95+
Enabled: true
96+
97+
Layout/SpaceAfterColon:
98+
Enabled: true
99+
100+
Layout/SpaceAfterComma:
101+
Enabled: true
102+
103+
Layout/SpaceAroundEqualsInParameterDefault:
104+
Enabled: true
105+
106+
Layout/SpaceAroundKeyword:
107+
Enabled: true
108+
109+
Layout/SpaceAroundOperators:
110+
Enabled: true
111+
112+
Layout/SpaceBeforeComma:
113+
Enabled: true
114+
115+
Layout/SpaceBeforeFirstArg:
116+
Enabled: true
117+
118+
Style/DefWithParentheses:
119+
Enabled: true
120+
121+
# Defining a method with parameters needs parentheses.
122+
Style/MethodDefParentheses:
123+
Enabled: true
124+
125+
Style/FrozenStringLiteralComment:
126+
Enabled: true
127+
EnforcedStyle: always
128+
Exclude:
129+
- 'actionview/test/**/*.builder'
130+
- 'actionview/test/**/*.ruby'
131+
- 'actionpack/test/**/*.builder'
132+
- 'actionpack/test/**/*.ruby'
133+
- 'activestorage/db/migrate/**/*.rb'
134+
135+
Style/RedundantFreeze:
136+
Enabled: true
137+
Exclude:
138+
- 'actionpack/lib/action_dispatch/journey/router/utils.rb'
139+
- 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb'
140+
141+
# Use `foo {}` not `foo{}`.
142+
Layout/SpaceBeforeBlockBraces:
143+
Enabled: true
144+
145+
# Use `foo { bar }` not `foo {bar}`.
146+
Layout/SpaceInsideBlockBraces:
147+
Enabled: true
148+
EnforcedStyleForEmptyBraces: space
149+
150+
# Use `{ a: 1 }` not `{a:1}`.
151+
Layout/SpaceInsideHashLiteralBraces:
152+
Enabled: true
153+
154+
Layout/SpaceInsideParens:
155+
Enabled: true
156+
157+
# Check quotes usage according to lint rule below.
158+
Style/StringLiterals:
159+
Enabled: true
160+
EnforcedStyle: double_quotes
161+
162+
# Detect hard tabs, no hard tabs.
163+
Layout/Tab:
164+
Enabled: true
165+
166+
# Blank lines should not have any spaces.
167+
Layout/TrailingBlankLines:
168+
Enabled: true
169+
170+
# No trailing whitespace.
171+
Layout/TrailingWhitespace:
172+
Enabled: true
173+
174+
# Use quotes for string literals when they are enough.
175+
Style/UnneededPercentQ:
176+
Enabled: true
177+
178+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
179+
Lint/RequireParentheses:
180+
Enabled: true
181+
182+
Lint/StringConversionInInterpolation:
183+
Enabled: true
184+
185+
Lint/UriEscapeUnescape:
186+
Enabled: true
187+
188+
Style/ParenthesesAroundCondition:
189+
Enabled: true
190+
191+
Style/RedundantReturn:
192+
Enabled: true
193+
AllowMultipleReturnValues: true
194+
195+
Style/Semicolon:
196+
Enabled: true
197+
AllowAsExpressionSeparator: true
198+
199+
# Prefer Foo.method over Foo::method
200+
Style/ColonMethodCall:
201+
Enabled: true
202+
203+
Style/TrivialAccessors:
204+
Enabled: true
205+
206+
Performance/FlatMap:
207+
Enabled: true
208+
209+
Performance/RedundantMerge:
210+
Enabled: true
211+
212+
Performance/StartWith:
213+
Enabled: true
214+
215+
Performance/EndWith:
216+
Enabled: true
217+
218+
Performance/RegexpMatch:
219+
Enabled: true
220+
221+
Performance/UnfreezeString:
222+
Enabled: true

Gemfile

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
1-
source 'https://rubygems.org'
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
24
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
35

4-
ruby '2.5.3'
6+
ruby "2.5.3"
57

6-
gem 'active_link_to', '~> 1.0.5'
7-
gem 'bootsnap', '>= 1.1.0', require: false
8-
gem 'cable_ready', '~> 2.0.6'
9-
gem 'country_select'
10-
gem 'devise'
11-
gem 'jbuilder', '~> 2.5'
12-
gem 'pg', '>= 0.18', '< 2.0'
13-
gem 'puma', '~> 3.11'
14-
gem 'rails', '~> 5.2.1'
15-
gem 'redis', '~> 4.0'
16-
gem 'sass-rails', '~> 5.0'
17-
gem 'simple_form', '~> 4.0'
18-
gem 'stimulus_reflex', '~> 0.1.8'
19-
gem 'tag_columns', '~> 0.1.6'
20-
gem 'turbolinks', '~> 5'
21-
gem 'uglifier', '>= 1.3.0'
22-
gem 'webpacker', '~> 3.5'
8+
gem "active_link_to", "~> 1.0.5"
9+
gem "bootsnap", ">= 1.1.0", require: false
10+
gem "cable_ready", "~> 2.0.6"
11+
gem "country_select"
12+
gem "devise"
13+
gem "jbuilder", "~> 2.5"
14+
gem "pg", ">= 0.18", "< 2.0"
15+
gem "puma", "~> 3.11"
16+
gem "rails", "~> 5.2.1"
17+
gem "redis", "~> 4.0"
18+
gem "sass-rails", "~> 5.0"
19+
gem "simple_form", "~> 4.0"
20+
gem "stimulus_reflex", "~> 0.1.8"
21+
gem "tag_columns", "~> 0.1.6"
22+
gem "turbolinks", "~> 5"
23+
gem "uglifier", ">= 1.3.0"
24+
gem "webpacker", "~> 3.5"
2325

2426
group :development, :test do
25-
gem 'awesome_print'
26-
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
27-
gem 'dotenv'
28-
gem 'pry'
29-
gem 'pry-byebug'
30-
gem 'pry-rails'
27+
gem "awesome_print"
28+
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
29+
gem "dotenv"
30+
gem "pry"
31+
gem "pry-byebug"
32+
gem "pry-rails"
3133
end
3234

3335
group :development do
34-
#gem 'spring'
35-
#gem 'spring-watcher-listen', '~> 2.0.0'
36-
gem 'annotate'
37-
gem 'listen', '>= 3.0.5', '< 3.2'
38-
gem 'magic_frozen_string_literal'
39-
gem 'model_probe'
40-
gem 'rufo'
41-
gem 'teamocil'
42-
gem 'web-console', '>= 3.3.0'
36+
# gem 'spring'
37+
# gem 'spring-watcher-listen', '~> 2.0.0'
38+
gem "annotate"
39+
gem "listen", ">= 3.0.5", "< 3.2"
40+
gem "magic_frozen_string_literal"
41+
gem "model_probe"
42+
gem "rubocop"
43+
gem "rufo"
44+
gem "teamocil"
45+
gem "web-console", ">= 3.3.0"
4346
end
4447

4548
group :test do
46-
gem 'capybara', '>= 2.15'
47-
gem 'chromedriver-helper'
48-
gem 'selenium-webdriver'
49+
gem "capybara", ">= 2.15"
50+
gem "chromedriver-helper"
51+
gem "selenium-webdriver"
4952
end
5053

5154
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
52-
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
55+
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

Gemfile.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ GEM
5353
archive-zip (0.11.0)
5454
io-like (~> 0.3.0)
5555
arel (9.0.0)
56+
ast (2.4.0)
5657
awesome_print (1.8.0)
5758
bcrypt (3.1.12)
5859
bindex (0.5.0)
@@ -101,6 +102,7 @@ GEM
101102
concurrent-ruby (~> 1.0)
102103
i18n_data (0.8.0)
103104
io-like (0.3.0)
105+
jaro_winkler (1.5.1)
104106
jbuilder (2.7.0)
105107
activesupport (>= 4.2.0)
106108
multi_json (>= 1.2)
@@ -130,7 +132,11 @@ GEM
130132
nokogiri (1.8.5)
131133
mini_portile2 (~> 2.3.0)
132134
orm_adapter (0.5.0)
135+
parallel (1.12.1)
136+
parser (2.5.1.2)
137+
ast (~> 2.4.0)
133138
pg (1.1.3)
139+
powerpack (0.1.2)
134140
pry (0.11.3)
135141
coderay (~> 1.1.0)
136142
method_source (~> 0.9.0)
@@ -170,6 +176,7 @@ GEM
170176
method_source
171177
rake (>= 0.8.7)
172178
thor (>= 0.19.0, < 2.0)
179+
rainbow (3.0.0)
173180
rake (12.3.1)
174181
rb-fsevent (0.10.3)
175182
rb-inotify (0.9.10)
@@ -178,6 +185,15 @@ GEM
178185
responders (2.4.0)
179186
actionpack (>= 4.2.0, < 5.3)
180187
railties (>= 4.2.0, < 5.3)
188+
rubocop (0.59.2)
189+
jaro_winkler (~> 1.5.1)
190+
parallel (~> 1.10)
191+
parser (>= 2.5, != 2.5.1.1)
192+
powerpack (~> 0.1)
193+
rainbow (>= 2.2.2, < 4.0)
194+
ruby-progressbar (~> 1.7)
195+
unicode-display_width (~> 1.0, >= 1.0.1)
196+
ruby-progressbar (1.10.0)
181197
ruby_dep (1.5.0)
182198
rubyzip (1.2.2)
183199
rufo (0.4.0)
@@ -227,6 +243,7 @@ GEM
227243
thread_safe (~> 0.1)
228244
uglifier (4.1.19)
229245
execjs (>= 0.3.0, < 3)
246+
unicode-display_width (1.4.0)
230247
unicode_utils (1.4.0)
231248
warden (1.2.7)
232249
rack (>= 1.0)
@@ -271,6 +288,7 @@ DEPENDENCIES
271288
puma (~> 3.11)
272289
rails (~> 5.2.1)
273290
redis (~> 4.0)
291+
rubocop
274292
rufo
275293
sass-rails (~> 5.0)
276294
selenium-webdriver

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# Add your own tasks in files placed in lib/tasks ending in .rake,
44
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
55

6-
require_relative 'config/application'
6+
require_relative "config/application"
77

88
Rails.application.load_tasks

0 commit comments

Comments
 (0)