Skip to content

Say where an association's reference is, and split out list-references' violations - #80

Merged
dduugg merged 2 commits into
mainfrom
list-references-tidy
Oct 13, 2026
Merged

dduugg merged 2 commits into
mainfrom
list-references-tidy

Conversation

@dduugg

@dduugg dduugg commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two things left over from #71's review.

  • schema/list-references-output.json now says that a reference pks infers from an association, as has_many :tacos gives ::Taco, is at the start of the call, where no constant is written. A class_name: option names the constant only in a string. query_packwerk's file cache looks for the constant's node in the file and finds none there. The description also says the source may write a constant relatively, as Bar inside module Foo.
  • The loop that collects a reference's violations moves out of list into violations_of, which takes the nested loops out of list. The output is the same. The comment on the copies it merges now says that only the experimental parser makes them.

The expect on the defining pack stays. between_packs drops constants that no pack defines, and carrying each reference's defining pack beside it would change what between_packs returns to rm too, which doesn't need it. The message now names between_packs.

Test plan

  • cargo test (375 passed), cargo fmt --check, and cargo clippy --all-targets --all-features -- -Dwarnings.
  • test_list_references_from_associations pins ::Census and ::Taco at carrier.rb:2:2 and :3:2 in app_with_rails_relationships, where the source has only has_many :censuses and has_many :tacos.

…s' violations

A reference that pks infers from an association, as `has_many :tacos`
gives `::Taco`, is at the association, so `Taco` isn't written at its
line and column, or anywhere in the file. A consumer that looks for the
constant in the file, as query_packwerk's file cache does, finds nothing.
The schema's `constant_name` now says so.

The loop that collects a reference's violations moves out of `list` into
`violations`, which takes two levels of nesting out of `list`. The output
is the same.

The `expect` on the defining pack stays. `between_packs` drops constants
that no pack defines, and carrying each reference's defining pack beside
it would change what `between_packs` returns to `rm` too, which doesn't
need it. The message now names `between_packs`.
@dduugg
dduugg requested a review from a team as a code owner October 13, 2026 21:14
A reference that pks infers from an association is at the start of the
call, where no constant is written. A `class_name: "Taco"` option names
the constant there only in a string, and the file may write the constant
elsewhere, so the previous commit's "or anywhere in the file" went too
far. The schema's `constant_name` now says where the reference is, that
`class_name:` takes a string, and that the source may write a constant
relatively. A test pins the associations' references in
app_with_rails_relationships at the start of their calls.

`violations` is now `violations_of`, like `files_of`, so its local
`violations` no longer shadows it. The comment on the copies of a
reference that it merges now says that only the experimental parser
makes them.
@dduugg
dduugg merged commit b849447 into main Oct 13, 2026
21 checks passed
@dduugg
dduugg deleted the list-references-tidy branch October 13, 2026 22:09
@github-project-automation github-project-automation Bot moved this from Triage to Done in Modularity Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant