Add Herb linting and formatting
Used 3 times
A
Andy Waite
Usage
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/V4YsWY"
Template Source
Review the code before running this template on your machine.
run "npm install --save-dev @herb-tools/linter @herb-tools/formatter"
run "npx herb-lint --init"
gsub_file ".herb.yml", /^ enabled: false$/, " enabled: true"
run "git add .herb.yml package.json package-lock.json"
run 'git commit -m "Add Herb linting and formatting"'
if yes?("Would you like Herb to autocorrect lint offenses?")
run "npx herb-lint --fix"
run "git add ."
run 'git commit -m "Autocorrect Herb lint offenses"'
end
if yes?("Would you like Herb to apply unsafe lint fixes?")
run "npx herb-lint --fix-unsafely"
run "git add ."
run 'git commit -m "Apply unsafe Herb lint fixes"'
end
if yes?("Would you like Herb to format the templates?")
run "npx herb-format ."
run "git add ."
run 'git commit -m "Format templates with Herb"'
end
if yes?("Would you like to add Herb checks to CI?")
insert_into_file ".github/workflows/ci.yml", <<-YAML, before: " test:\n"
- name: Install JavaScript dependencies
run: npm ci
- name: Lint HTML+ERB templates
run: npx @herb-tools/linter
- name: Check HTML+ERB formatting
run: npx @herb-tools/formatter --check
YAML
run "git add .github/workflows/ci.yml"
run 'git commit -m "Add Herb checks to CI"'
end
run "npx herb-lint"
run "npx herb-format --check ."