erb-lint
Set up erb-lint and better-html
Used 49 times
T
TobiasBales
Usage
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/zyvsPv"
Template Source
Review the code before running this template on your machine.
def create_bin(name, command = nil)
create_file "bin/#{name}" do <<~EOF
#!/usr/bin/env ruby
APP_ROOT = File.expand_path('..', __dir__)
Dir.chdir(APP_ROOT) do
begin
exec '#{command || name}'
rescue Errno::ENOENT
$stderr.puts "#{name} executable was not detected in the system."
exit 1
end
end
EOF
end
`chmod +x bin/#{name}`
end
gem 'better_html'
gem_group :development do
gem 'erb_lint'
end
Bundler.with_unbundled_env { run 'bundle install' }
create_file '.erb-lint.yml' do <<~YAML
---
EnableDefaultLinters: true
linters:
ErbSafety:
enabled: true
Rubocop:
enabled: true
rubocop_config:
inherit_from:
- .rubocop.yml
Style/FrozenStringLiteralComment:
Enabled: false
Layout/InitialIndentation:
Enabled: false
Layout/TrailingEmptyLines:
Enabled: false
YAML
end
create_bin 'erb_lint', 'erblint --lint-all'
create_bin 'erb_lint_fix', 'erblint --lint-all --autocorrect'
system('bin/erb_lint_fix')
Comments
Facundo Espinosa
Great template! I just tried in my project which is using standardrb directly, so no .rubocop.yml it's present and it's failing. Probably the template should check if rubocop it's present otherwise install or show a warning and not run the last script.