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

Detect deleted files as stale violations #332

Merged
merged 6 commits into from
Mar 21, 2023
Merged

Conversation

gmcgibbon
Copy link
Member

@gmcgibbon gmcgibbon commented Mar 14, 2023

What are you trying to accomplish?

Closes #298

Detect files deleted in old TODO entries as stale. Also some refactorings along the way.

What approach did you choose and why?

I took the new and old entries and mapped their files to see the paths that exist in the old TODO, but not the new TODO and added them to the stale check list of files.

What should reviewers focus on?

Does this make sense?

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.

Breaking it up into private methods for easier readability.
Also rename todo_list to old_entries (to contrast with new_entries),
drop Type postfix from TODO entry types, and remove extra file entry
from test/fixtures/package_todo.yml to make an existing stale check test
pass.
@gmcgibbon gmcgibbon requested a review from a team as a code owner March 14, 2023 06:06
@gmcgibbon
Copy link
Member Author

gmcgibbon commented Mar 14, 2023

A quick benchmark:

This patch:

📦 Finished in 17.95 seconds

No offenses detected
No stale violations detected
bin/packwerk check  0.28s user 0.08s system 0% cpu 57.987 total

Main:

📦 Finished in 17.92 seconds

No offenses detected
No stale violations detected
bin/packwerk check  0.29s user 0.08s system 0% cpu 50.910 total

So this may add a slight performance regression when calculating deleted files (at a large scale). I don't see a clear way around mapping old entries without changing the serialization format, but we don't have to map new ones (we can instead keep a list of files added as an array). I'll give this some more thought before merging.

Copy link
Contributor

@alexevanczuk alexevanczuk left a comment

Choose a reason for hiding this comment

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

I took the new and old entries and mapped their files to see the paths that exist in the old TODO, but not the new TODO and added them to the stale check list of files. After implementing this, stale violation checks mean a lot of things, so I think this is a new feature and not a bug.

What other meanings could it have? It still seems like a stale violation if a file is deleted that once contained violations but I'm probably missing something.

@@ -37,61 +41,39 @@ def listed?(reference, violation_type:)
params(reference: Packwerk::Reference, violation_type: String).returns(T::Boolean)
end
def add_entries(reference, violation_type)
package_violations = @new_entries.fetch(reference.constant.package.name, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe not necessary as part of this PR, but wondering if we might want to convert the hash types used for old and new entries to a proper object at some point. Besides more ergonomic typing, the operations on it could be a bit more domain/object oriented.

Copy link
Member Author

@gmcgibbon gmcgibbon Mar 14, 2023

Choose a reason for hiding this comment

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

Agree. I looked into this but it seemed too complicated for what I was trying to solve. We still need as hash of hashes, and that's where most of the complexity comes from. We may be able to cache file path state in these objects too to cut down on time to find deleted files.

@gmcgibbon
Copy link
Member Author

What other meanings could it have? It still seems like a stale violation if a file is deleted that once contained violations but I'm probably missing something.

You are correct, I am just basing what our previous definition of what stale meant (a changed violation type or a fixed violation), but I guess everyone I have chatted with also assumed deleted files should be counted too. I'll change the PR to classify this as a bugfix. 👍

@gmcgibbon gmcgibbon merged commit 17e0313 into main Mar 21, 2023
@gmcgibbon gmcgibbon deleted the fix_stale_violations branch March 21, 2023 00:54
@shopify-shipit shopify-shipit bot temporarily deployed to rubygems August 8, 2023 20:48 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.

[Bug Report] Stale violations on deleted files
2 participants