fix: repair broken Prettier plugin in Ruby/Rails templates - #49
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prettier was broken in nearly every Rails project generated by Initium. The root cause:
package.jsoninstalled the unscopedprettier-plugin-rubyfrom a GitHub tarball, while.prettierrcreferenced the scoped@prettier/plugin-ruby. The plugin ids never matched, so Prettier silently failed to format Ruby. This ports the fixes fromz19r/cooper-and-wrightPR #6 into the templates and adjusts Prettier wherever else it makes sense.Changes
@prettier/plugin-ruby@^4.0.4(published, scoped npm package) across all Ruby templates via a sharedruby_prettier_deps()helper. Rails additionally gets@4az/prettier-plugin-html-erb@^0.0.7for ERB views.rubySingleQuote: truealongsidesingleQuote: true. Previouslywith_ruby_pluginforcedsingle_quote = false, contradicting the house rule that Prettier is the single-quote source of truth.Style/StringLiterals,StringLiteralsInInterpolation, the threeTrailingComma*,Layout/SpaceInsideArrayLiteralBrackets) instead of enforcingsingle_quotes.fmt/fmt-checkrecipes (npx prettier --write/--check .) to every Ruby template.@prettier/plugin-rubyv4 needs:npm install,bundle add syntax_tree prettier_print --group development,test,bundle install, thenjust 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 -- --checkcleancargo clippy --all-targets --all-features -- -D warningscleaninitium ruby --template railsand verified.prettierrc,.prettierignore,package.json,.rubocop.yml,justfile, and the Next steps message end-to-end.prettierignorefor non-Ruby (Go)