Skip to content

Commit eb57342

Browse files
committed
[DX][Recipe] Set up overcommit
Set up/configure overcommit with - rubocop - erb_lint - better_html
1 parent 94a9573 commit eb57342

File tree

6 files changed

+142
-1
lines changed

6 files changed

+142
-1
lines changed

Diff for: .better-html.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
allow_single_quoted_attributes: false
3+
allow_unquoted_attributes: false

Diff for: .erb-lint.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
glob: "**/app/**/*.{html,turbo_stream,js}{+*,}.erb"
3+
exclude:
4+
- '*vendor/*'
5+
- '*app/views/svg/*'
6+
linters:
7+
AllowedScriptType:
8+
enabled: true
9+
ClosingErbTagIndent:
10+
enabled: true
11+
DeprecatedClasses:
12+
enabled: true
13+
ErbSafety:
14+
enabled: true
15+
better_html_config: .better-html.yml
16+
ExtraNewline:
17+
enabled: true
18+
FinalNewline:
19+
enabled: true
20+
HardCodedString:
21+
enabled: false
22+
NoJavascriptTagHelper:
23+
enabled: true
24+
ParserErrors:
25+
enabled: true
26+
RightTrim:
27+
enabled: false
28+
RequireInputAutocomplete:
29+
enabled: false
30+
RubocopText:
31+
enabled: true
32+
Rubocop:
33+
enabled: true
34+
rubocop_config:
35+
inherit_from:
36+
- .rubocop.yml
37+
SelfClosingTag:
38+
enabled: false
39+
SpaceAroundErbTag:
40+
enabled: true
41+
SpaceInHtmlTag:
42+
enabled: true
43+
SpaceIndentation:
44+
enabled: true
45+
TrailingWhitespace:
46+
enabled: true

Diff for: .overcommit.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Use this file to configure the Overcommit hooks you wish to use. This will
2+
# extend the default configuration defined in:
3+
# https://github.com/sds/overcommit/blob/master/config/default.yml
4+
#
5+
# At the topmost level of this YAML file is a key representing type of hook
6+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
7+
# customize each hook, such as whether to only run it on certain files (via
8+
# `include`), whether to only display output if it fails (via `quiet`), etc.
9+
#
10+
# For a complete list of hooks, see:
11+
# https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
12+
#
13+
# For a complete list of options that you can use to customize hooks, see:
14+
# https://github.com/sds/overcommit#configuration
15+
#
16+
# Uncomment the following lines to make the configuration take effect.
17+
18+
verify_signatures: false
19+
20+
PreCommit:
21+
Rubocop:
22+
enabled: true
23+
required: true
24+
command: ['bundle', 'exec', 'rubocop', '-A']
25+
ErbLint:
26+
enabled: true
27+
required: true
28+
command: ['bundle', 'exec', 'erblint', '--lint-all', '-a']
29+
30+
# PrePush:
31+
# RSpec:
32+
# enabled: true
33+
# required: true
34+
# command: ['bundle', 'exec', 'rspec']
35+
#
36+
# PostCheckout:
37+
# ALL: # Special hook name that customizes all hooks of this type
38+
# quiet: true # Change all post-checkout hooks to only display output on failure
39+
#
40+
# IndexTags:
41+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes

Diff for: .rubocop.yml

+25
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,28 @@ inherit_gem: { rubocop-rails-omakase: rubocop.yml }
66
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
77
# Layout/SpaceInsideArrayLiteralBrackets:
88
# Enabled: false
9+
#
10+
# Temp solution for now, need to look into it
11+
# The gist is that by default, this
12+
#
13+
# <%= yield %>
14+
#
15+
# caused
16+
#
17+
# Layout/TrailingEmptyLines: Final newline missing.
18+
# In file: app/views/layouts/application.html.erb
19+
#
20+
# The autofix resulted in
21+
# <%= yield
22+
# %>
23+
#
24+
# which is not desirable.
25+
#
26+
# Not sure if this happens due to some exotic combo of
27+
# erb_lint + rubocop + better_html or what, but
28+
# I don't feel like researching right now
29+
#
30+
Layout/TrailingEmptyLines:
31+
Enabled: true
32+
Exclude:
33+
- "**/app/**/*.{html,turbo_stream,js}{+*,}.erb"

Diff for: Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ gem "puma", ">= 5.0"
1313
gem "redis", ">= 4.0.1"
1414

1515
group :development do
16+
gem "better_html", require: false
17+
gem "erb_lint", require: false
18+
gem "overcommit", require: false
1619
gem "web-console"
1720
end
1821

Diff for: Gemfile.lock

+24-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ GEM
7373
public_suffix (>= 2.0.2, < 7.0)
7474
ast (2.4.2)
7575
base64 (0.2.0)
76+
better_html (2.1.1)
77+
actionview (>= 6.0)
78+
activesupport (>= 6.0)
79+
ast (~> 2.0)
80+
erubi (~> 1.4)
81+
parser (>= 2.4)
82+
smart_properties
7683
bigdecimal (3.1.8)
7784
bindex (0.8.1)
7885
bootsnap (1.18.3)
@@ -89,6 +96,7 @@ GEM
8996
rack-test (>= 0.6.3)
9097
regexp_parser (>= 1.5, < 3.0)
9198
xpath (~> 3.2)
99+
childprocess (5.0.0)
92100
concurrent-ruby (1.3.3)
93101
connection_pool (2.4.1)
94102
crass (1.0.6)
@@ -99,11 +107,19 @@ GEM
99107
irb (~> 1.10)
100108
reline (>= 0.3.8)
101109
drb (2.2.1)
110+
erb_lint (0.5.0)
111+
activesupport
112+
better_html (>= 2.0.1)
113+
parser (>= 2.7.1.4)
114+
rainbow
115+
rubocop
116+
smart_properties
102117
erubi (1.13.0)
103118
globalid (1.2.1)
104119
activesupport (>= 6.1)
105120
i18n (1.14.5)
106121
concurrent-ruby (~> 1.0)
122+
iniparse (1.5.0)
107123
io-console (0.7.2)
108124
irb (1.13.2)
109125
rdoc (>= 4.0.0)
@@ -148,6 +164,10 @@ GEM
148164
racc (~> 1.4)
149165
nokogiri (1.16.6-x86_64-linux)
150166
racc (~> 1.4)
167+
overcommit (0.63.0)
168+
childprocess (>= 0.6.3, < 6)
169+
iniparse (~> 1.4)
170+
rexml (~> 3.2)
151171
parallel (1.25.1)
152172
parser (3.3.3.0)
153173
ast (~> 2.4.1)
@@ -250,6 +270,7 @@ GEM
250270
rexml (~> 3.2, >= 3.2.5)
251271
rubyzip (>= 1.2.2, < 3.0)
252272
websocket (~> 1.0)
273+
smart_properties (1.17.0)
253274
sqlite3 (2.0.2-aarch64-linux-gnu)
254275
sqlite3 (2.0.2-aarch64-linux-musl)
255276
sqlite3 (2.0.2-arm-linux-gnu)
@@ -305,12 +326,15 @@ PLATFORMS
305326
x86_64-linux-musl
306327

307328
DEPENDENCIES
329+
better_html
308330
bootsnap
309331
brakeman
310332
capybara
311333
cssbundling-rails
312334
debug
335+
erb_lint
313336
jsbundling-rails
337+
overcommit
314338
propshaft
315339
puma (>= 5.0)
316340
rails (~> 7.2.0.beta2)
@@ -320,7 +344,6 @@ DEPENDENCIES
320344
sqlite3 (>= 1.4)
321345
stimulus-rails
322346
turbo-rails
323-
tzinfo-data
324347
web-console
325348

326349
BUNDLED WITH

0 commit comments

Comments
 (0)