Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate filtering from reference extraction #9

Open
wildmaples opened this issue Sep 25, 2020 · 0 comments
Open

Separate filtering from reference extraction #9

wildmaples opened this issue Sep 25, 2020 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@wildmaples
Copy link
Contributor

wildmaples commented Sep 25, 2020

We currently extract + filter references all in one step, which can sometimes be a point of confusion.

In particular, we do a lot of filtering:

def reference_from_constant(constant_name, node:, ancestors:, file_path:)
namespace_path = Node.enclosing_namespace_path(node, ancestors: ancestors)
return if local_reference?(constant_name, Node.name_location(node), namespace_path)
constant =
@context_provider.context_for(
constant_name,
current_namespace_path: namespace_path
)
return if constant&.package.nil?
relative_path =
Pathname.new(file_path)
.relative_path_from(@root_path).to_s
source_package = @context_provider.package_from_path(relative_path)
return if source_package == constant.package
Reference.new(source_package, relative_path, constant)
end

You can see we remove

  • locally referenced constants,
  • references to constants packwerk is unable to resolve, or unable to resolve to a package, and
  • references to constants in the same package as the source package of the reference.

There could be a light refactor here so that we can extract all references, followed by another layer to do the filtering. It should lend itself to easier testing and a lighter set of test suites.

@wildmaples wildmaples added enhancement New feature or request good first issue Good for newcomers labels Sep 25, 2020
shioyama pushed a commit that referenced this issue May 21, 2021
Add packerk/cop for convenience
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant