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

Refactor - simplify orchestration layer #147

Merged
merged 1 commit into from
Oct 16, 2021
Merged

Conversation

kenzan100
Copy link
Contributor

@kenzan100 kenzan100 commented Oct 14, 2021

What are you trying to accomplish?

First review-ready PR as an artefact of #145.
It's a part of Packwerk upkeep attempts.

What approach did you choose and why?

1. Extract checkers into its own module.

Biggest extractable seam/interface seems to be the implementation of Checkers: We have two default checkers: DependencyChecker and PrivacyChecker. They're extracted into its own namespace.

2. Decouple reference extraction from offence checks.

FileProcessor was having too much responsibilities, of converting file_path, into AST nodes, into a list of offences.
Now seams are clearer; file_path -(AST::Node)-> References -(ReferenceChecker)-> Offences.

What should reviewers focus on?

  1. Overall quality after the separation of concerns.
  2. Naming quality modules/methods.

There're self-annotated comments in the diff for one-off topics.

Type of Change

  • Bugfix
  • New feature
  • Non-breaking change (a change that doesn't alter functionality - i.e., code refactor, configs, etc.)

Additional Release Notes

  • Breaking change (fix or feature that would cause existing functionality to change)

Include any notes here to include in the release description. For example, if you selected "breaking change" above, leave notes on how users can transition to this version.

If no additional notes are necessary, delete this section or leave it unchanged.

Checklist

  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • It is safe to rollback this change.

T::Array[
T.any(
Packwerk::Reference,
Packwerk::Offense,
Copy link
Contributor Author

@kenzan100 kenzan100 Oct 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileProcessor still have chance to early-return Offence, in cases of UnknownFileTypeResult or ParseError.

I don't particularly like this shared responsibility of the class, and more than happy to revisit the further separation.

)
violations << offense
end
def call(node, ancestors)
Copy link
Contributor Author

@kenzan100 kenzan100 Oct 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Result of this change, identifies further refactoring opportunity;

NodeProcessor and its factory is becoming almost negligible wrapper on reference_extractor. To be worked on as a follow-up of this PR.

@kenzan100 kenzan100 requested a review from exterm October 14, 2021 19:39
lib/packwerk.rb Outdated Show resolved Hide resolved
params(
node: Parser::AST::Node,
ancestors: T::Array[Parser::AST::Node]
).returns(T.nilable(Packwerk::Reference))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

sharpening the definition of the node processor to only generate references - I love it

lib/packwerk/reference.rb Outdated Show resolved Hide resolved
@exterm
Copy link
Contributor

exterm commented Oct 14, 2021

Really cool refactor. It all makes sense to me. When you run this in core CI, could you also check the run times to make sure it isn't dramatically slower than the latest release?

@kenzan100 kenzan100 marked this pull request as ready for review October 14, 2021 21:38
@kenzan100 kenzan100 requested a review from a team as a code owner October 14, 2021 21:38
@kenzan100
Copy link
Contributor Author

Really cool refactor. It all makes sense to me. When you run this in core CI, could you also check the run times to make sure it isn't dramatically slower than the latest release?

I've create two branches in core CI, they're identical except for which branch/git source it uses for Packwerk.
Out of several runs to average out the statistics, this branch Packwerk was 1~2% (a few seconds) slower than the default Packwerk.

I don't think I'm doing anything obviously harmful for the Packwerk run-time.

(And ofc, all the packwerk scan passed on this branch 🎉)

@kenzan100 kenzan100 changed the title Yuta/simplify orchestration Refactor - simplify orchestration layer Oct 15, 2021
@exterm
Copy link
Contributor

exterm commented Oct 15, 2021

I don't think 1-2% are statistically significant, so all good

end

def parser_for(file_path)
@parser_factory.for_path(file_path)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this class looks so much better now.


module Packwerk
module ReferenceToOffense
class ReferenceChecker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit confusing that ReferenceChecker has a very similar name to PrivacyChecker and DependencyChecker yet is not a Checker.

I can't think of a good alternative name right now though...

@exterm
Copy link
Contributor

exterm commented Oct 15, 2021

Just the two names left that I'm not sure about, but I think this is otherwise ready to merge.

Copy link
Contributor

@dougedey-shopify dougedey-shopify left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, can you add a Changelog entry?

@rafaelfranca
Copy link
Member

looks good, can you add a Changelog entry?

Changelog entry for a refactor? If it needs a changelog entry it is not a refactor.

@kenzan100
Copy link
Contributor Author

looks good, can you add a Changelog entry?

Changelog entry for a refactor? If it needs a changelog entry it is not a refactor.

I've looked into https://github.com/Shopify/packwerk/blob/main/USAGE.md, but none of the change here, would affect public facing (a bit ambiguous term) functionality.

@rafaelfranca
Copy link
Member

LGTM, but you will need to clean those commits. Can you please squash/rename the commits so they makes sense?

- Extract checkers into its own namespace / module.
- Decouple reference extraction from offence checks.
@kenzan100 kenzan100 merged commit a15872d into main Oct 16, 2021
@kenzan100 kenzan100 deleted the yuta/simplify-orchestration branch October 16, 2021 05:17
@kenzan100
Copy link
Contributor Author

🎉 thank you so much for the reviewers.

@shopify-shipit shopify-shipit bot temporarily deployed to rubygems November 24, 2021 22:57 Inactive
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.

4 participants