Skip to content

fix: repair broken Prettier plugin in Ruby/Rails templates - #49

Merged
zackkitzmiller merged 1 commit into
mainfrom
fix/rails-prettier-plugin
Jul 24, 2026
Merged

fix: repair broken Prettier plugin in Ruby/Rails templates#49
zackkitzmiller merged 1 commit into
mainfrom
fix/rails-prettier-plugin

Conversation

@zackkitzmiller

Copy link
Copy Markdown
Member

Summary

Prettier was broken in nearly every Rails project generated by Initium. The root cause: package.json installed the unscoped prettier-plugin-ruby from a GitHub tarball, while .prettierrc referenced the scoped @prettier/plugin-ruby. The plugin ids never matched, so Prettier silently failed to format Ruby. This ports the fixes from z19r/cooper-and-wright PR #6 into the templates and adjusts Prettier wherever else it makes sense.

Changes

  • package.json — pin @prettier/plugin-ruby@^4.0.4 (published, scoped npm package) across all Ruby templates via a shared ruby_prettier_deps() helper. Rails additionally gets @4az/prettier-plugin-html-erb@^0.0.7 for ERB views.
  • PrettierConfig — emit rubySingleQuote: true alongside singleQuote: true. Previously with_ruby_plugin forced single_quote = false, contradicting the house rule that Prettier is the single-quote source of truth.
  • .rubocop.yml — disable the cops that fight Prettier (Style/StringLiterals, StringLiteralsInInterpolation, the three TrailingComma*, Layout/SpaceInsideArrayLiteralBrackets) instead of enforcing single_quotes.
  • .prettierignore — now populated: Rails-aware list (vendor/tmp/log/storage/public/assets…) for Ruby templates, a generic list otherwise (was empty).
  • justfile — add fmt / fmt-check recipes (npx prettier --write/--check .) to every Ruby template.
  • Post-install message — after generation, Ruby and Node runs print a "Next steps" block. Since Initium doesn't manage the Gemfile, the Ruby message surfaces the gems @prettier/plugin-ruby v4 needs: npm install, bundle add syntax_tree prettier_print --group development,test, bundle install, then just fmt.

Test plan

  • cargo test — 153 passing (updated 2 integration assertions, added 6 unit tests: scoped package, ERB plugin scoping, rubySingleQuote, non-Ruby exclusion)
  • cargo fmt --all -- --check clean
  • cargo clippy --all-targets --all-features -- -D warnings clean
  • Ran initium ruby --template rails and verified .prettierrc, .prettierignore, package.json, .rubocop.yml, justfile, and the Next steps message end-to-end
  • Verified Node next-steps message and generic .prettierignore for non-Ruby (Go)

Initium's package.json installed the unscoped `prettier-plugin-ruby`
GitHub tarball while .prettierrc referenced the scoped
`@prettier/plugin-ruby`. The ids never matched, so Prettier could not
load the plugin — the reason Prettier is broken in nearly every
generated Rails project.

- package.json: pin `@prettier/plugin-ruby@^4.0.4` (scoped npm package);
  Rails additionally gets `@4az/prettier-plugin-html-erb@^0.0.7`
- PrettierConfig: emit `rubySingleQuote: true` with `singleQuote: true`
  (was erroneously `single_quote = false`)
- .rubocop.yml: disable cops that fight Prettier (StringLiterals,
  TrailingComma*, SpaceInsideArrayLiteralBrackets) instead of enforcing
  single_quotes
- .prettierignore: populate with Rails-aware ignores (generic elsewhere)
- justfile: add `fmt` / `fmt-check` recipes for Ruby templates
- commands: print a post-generation "Next steps" message telling users to
  run `npm install`, `bundle add syntax_tree prettier_print`, and
  `bundle install` for the deps we inject (v4 needs the Syntax Tree gems)

Update integration tests and add unit tests covering the scoped package,
ERB plugin scoping, rubySingleQuote, and non-Ruby exclusion.
@zackkitzmiller
zackkitzmiller merged commit 0344025 into main Jul 24, 2026
6 checks passed
@zackkitzmiller
zackkitzmiller deleted the fix/rails-prettier-plugin branch July 24, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant