Repository navigation
Conversation
`hanami generate action --slice=main` looked up the slice block in
config/routes.rb with /slice[[:space:]]*:main/, which does not match
slices declared with parentheses, e.g. `slice(:main, at: "/") do`,
and failed with a "cannot find" error.
Allow an optional opening parenthesis before the slice name. Since a
route cannot be appended to a single-line block such as
`slice(:main, at: "/") { root to: "home.show" }`, expand such a block
into a multi-line `do ... end` block containing the new route.
anyingiit
force-pushed
the
fix-slice-route-matcher-parentheses
branch
from
October 22, 2026 19:14
53af38c to
e33cbf8
Compare
Member
|
Hi @anyingiit, thanks for thinking of us, but per our AI contributions policy, we are not interested in contributions from autonomous agents without meaningful human attention on the other side. I'll be closing your PRs. If you're interested in working with us in a more direct, human-centred way, you're welcome to do that in the future. |
This was referenced Oct 22, 2026
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.
Requested by winshyon
Description
Fixes hanami/hanami#1284 (the issue is tracked in hanami/hanami, but the code lives here).
hanami generate action ... --slice=mainlocates the slice block inconfig/routes.rbwith/slice[[:space:]]*:main/. That only matchesslice :main, at: "/" do, so a routes file thatdeclares slices with parentheses (as generated by e.g. hanamismith) fails:
This PR:
Widens the matcher in
Generators::App::Action#add_route_to_blockto/slice[[:space:]]*\(?[[:space:]]*:#{namespace}/, soslice(:main, at: "/") do ... endworks.Handles single-line brace blocks such as
slice(:main, at: "/") { root to: "home.show" }(the exact form from the issue). A route can't be injected into a one-line block, and with
only the matcher change
Dry::Files#inject_line_at_block_bottomwould put the route in thewrong place (outside the block). So when the matched slice line is a single-line
{ ... }block, it is rewritten as a multi-line
do ... endblock that keeps the existing body andadds the new route:
Multi-line
do ... endblocks still go throughinject_line_at_block_bottomexactly as before.The existing duplicate check (
block_contains?) runs first, so an existing route in a one-lineblock is still detected and skipped.
Reviewers may want to weigh in on the rewrite in (2): it changes the user's formatting of that one
slice line. The alternative would be to raise a clearer error for single-line blocks; happy to switch
to that if you prefer.
Motivation / disclosure: I had some spare AI-assistant quota (Claude Code) and am using it to try to
help projects with open good-first-issues. The change was prepared with Claude Code and verified as listed
below. If it doesn't fit, isn't up to your bar, or you'd simply rather not take it — please feel free to
close it, no hard feelings at all 🙂
Related issue
Fixes hanami/hanami#1284
Checklist
spec/unit/hanami/cli/commands/app/generate/action_spec.rb("appends routes within the proper slice block when slice arguments use parentheses",
"expands single-line slice blocks to append routes") fail on
mainwithout the fix(
TypeErrorfromblock_contains?because the slice isn't found) and pass with it.bundle exec rspec spec/unit/hanami/cli/commands/app/generate/→ 169 examples, 0 failures, 1 pending.bundle exec rspec spec/unit→ the only failures are DB specs (no Postgres/MySQL available locally)and 4
gem/new_specencoding failures due to the local locale; identical onmainwithout this change.bundle exec rubocopon the changed files → no offenses.CHANGELOG.mdis updated (if applicable) — entry under Unreleased → Fixed🤖 Generated with Claude Code