Skip to content

Commit

Permalink
[DX][Recipe] Set up ocercommit
Browse files Browse the repository at this point in the history
Set up/configure overcommit with

- rubocop
- erb_lint
- better_html
  • Loading branch information
trinitytakei committed Jun 28, 2024
1 parent 94a9573 commit d66c7d6
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .better-html.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
allow_single_quoted_attributes: false
allow_unquoted_attributes: false
46 changes: 46 additions & 0 deletions .erb-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
glob: "**/app/**/*.{html,turbo_stream,js}{+*,}.erb"
exclude:
- '*vendor/*'
- '*app/views/svg/*'
linters:
AllowedScriptType:
enabled: true
ClosingErbTagIndent:
enabled: true
DeprecatedClasses:
enabled: true
ErbSafety:
enabled: true
better_html_config: .better-html.yml
ExtraNewline:
enabled: true
FinalNewline:
enabled: true
HardCodedString:
enabled: false
NoJavascriptTagHelper:
enabled: true
ParserErrors:
enabled: true
RightTrim:
enabled: false
RequireInputAutocomplete:
enabled: false
RubocopText:
enabled: true
Rubocop:
enabled: true
rubocop_config:
inherit_from:
- .rubocop.yml
SelfClosingTag:
enabled: false
SpaceAroundErbTag:
enabled: true
SpaceInHtmlTag:
enabled: true
SpaceIndentation:
enabled: true
TrailingWhitespace:
enabled: true
41 changes: 41 additions & 0 deletions .overcommit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Use this file to configure the Overcommit hooks you wish to use. This will
# extend the default configuration defined in:
# https://github.com/sds/overcommit/blob/master/config/default.yml
#
# At the topmost level of this YAML file is a key representing type of hook
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
# customize each hook, such as whether to only run it on certain files (via
# `include`), whether to only display output if it fails (via `quiet`), etc.
#
# For a complete list of hooks, see:
# https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
#
# For a complete list of options that you can use to customize hooks, see:
# https://github.com/sds/overcommit#configuration
#
# Uncomment the following lines to make the configuration take effect.

verify_signatures: false

PreCommit:
Rubocop:
enabled: true
required: true
command: ['bundle', 'exec', 'rubocop', '-A']
ErbLint:
enabled: true
required: true
command: ['bundle', 'exec', 'erblint', '--lint-all', '-a']

# PrePush:
# RSpec:
# enabled: true
# required: true
# command: ['bundle', 'exec', 'rspec']
#
# PostCheckout:
# ALL: # Special hook name that customizes all hooks of this type
# quiet: true # Change all post-checkout hooks to only display output on failure
#
# IndexTags:
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
25 changes: 25 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,28 @@ inherit_gem: { rubocop-rails-omakase: rubocop.yml }
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
# Layout/SpaceInsideArrayLiteralBrackets:
# Enabled: false
#
# Temp solution for now, need to look into it
# The gist is that by default, this
#
# <%= yield %>
#
# caused
#
# Layout/TrailingEmptyLines: Final newline missing.
# In file: app/views/layouts/application.html.erb
#
# The autofix resulted in
# <%= yield
# %>
#
# which is not desirable.
#
# Not sure if this happens due to some exotic combo of
# erb_lint + rubocop + better_html or what, but
# I don't feel like researching right now
#
Layout/TrailingEmptyLines:
Enabled: true
Exclude:
- "**/app/**/*.{html,turbo_stream,js}{+*,}.erb"
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ gem "puma", ">= 5.0"
gem "redis", ">= 4.0.1"

group :development do
gem "better_html", require: false
gem "erb_lint", require: false
gem "overcommit", require: false
gem "web-console"
end

Expand Down
25 changes: 24 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ GEM
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
better_html (2.1.1)
actionview (>= 6.0)
activesupport (>= 6.0)
ast (~> 2.0)
erubi (~> 1.4)
parser (>= 2.4)
smart_properties
bigdecimal (3.1.8)
bindex (0.8.1)
bootsnap (1.18.3)
Expand All @@ -89,6 +96,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (5.0.0)
concurrent-ruby (1.3.3)
connection_pool (2.4.1)
crass (1.0.6)
Expand All @@ -99,11 +107,19 @@ GEM
irb (~> 1.10)
reline (>= 0.3.8)
drb (2.2.1)
erb_lint (0.5.0)
activesupport
better_html (>= 2.0.1)
parser (>= 2.7.1.4)
rainbow
rubocop
smart_properties
erubi (1.13.0)
globalid (1.2.1)
activesupport (>= 6.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
iniparse (1.5.0)
io-console (0.7.2)
irb (1.13.2)
rdoc (>= 4.0.0)
Expand Down Expand Up @@ -148,6 +164,10 @@ GEM
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
racc (~> 1.4)
overcommit (0.63.0)
childprocess (>= 0.6.3, < 6)
iniparse (~> 1.4)
rexml (~> 3.2)
parallel (1.25.1)
parser (3.3.3.0)
ast (~> 2.4.1)
Expand Down Expand Up @@ -250,6 +270,7 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
smart_properties (1.17.0)
sqlite3 (2.0.2-aarch64-linux-gnu)
sqlite3 (2.0.2-aarch64-linux-musl)
sqlite3 (2.0.2-arm-linux-gnu)
Expand Down Expand Up @@ -305,12 +326,15 @@ PLATFORMS
x86_64-linux-musl

DEPENDENCIES
better_html
bootsnap
brakeman
capybara
cssbundling-rails
debug
erb_lint
jsbundling-rails
overcommit
propshaft
puma (>= 5.0)
rails (~> 7.2.0.beta2)
Expand All @@ -320,7 +344,6 @@ DEPENDENCIES
sqlite3 (>= 1.4)
stimulus-rails
turbo-rails
tzinfo-data
web-console

BUNDLED WITH
Expand Down

0 comments on commit d66c7d6

Please sign in to comment.