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

update PatchCop to support spanning errors #79

Merged
merged 3 commits into from
Jan 17, 2023
Merged

update PatchCop to support spanning errors #79

merged 3 commits into from
Jan 17, 2023

Conversation

nevinera
Copy link
Contributor

@nevinera nevinera commented Dec 5, 2022

Purpose

Currently, if a changeset appends a bunch of logic to a large method, and the resulting method is "too complex", rubocop will complain, but pronto-rubocop will not notice. This is because we're comparing the offense.line against the patch to see if that line is part of the changes being checked.. but the offense.line is actually offense.location.first_line, which can be outside the changes, despite the violation being introduced.

Implementation

  • Update PatchCop to look for the the lines where the offense-range includes the changed line
  • Switch from select to detect - the prior implementation only ever hit a given offense once, since it only traversed each line-number once. But now it's possible (likely) to hit the same offense multiple times on consecutive lines, and we're only interested in the first time the offense was affected.
  • Add a test to cover the new case in patch_cop_spec.rb.

We want to keep an error if it _includes_ any lines in a given patch. We also
want only the first such line, since it likely includes more than one (this
singularism was implicit before, because each line was only passed through once)
@nevinera nevinera marked this pull request as ready for review December 5, 2022 23:05
@nevinera nevinera requested a review from a team as a code owner December 5, 2022 23:05
Copy link
Member

@ashkulz ashkulz left a comment

Choose a reason for hiding this comment

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

@nevinera can you merge/rebase with master to pick up 36c6acc?

@nevinera
Copy link
Contributor Author

nevinera commented Jan 4, 2023

@nevinera can you merge/rebase with master to pick up 36c6acc?

Absolutely, sorry for the turn-around time. Holidays and all :-)

Copy link
Member

@ashkulz ashkulz left a comment

Choose a reason for hiding this comment

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

Sorry for the late review!

lib/pronto/rubocop/patch_cop.rb Outdated Show resolved Hide resolved
@nevinera nevinera requested a review from ashkulz January 16, 2023 12:30
@ashkulz ashkulz merged commit 6e1703c into prontolabs:master Jan 17, 2023
@ashkulz
Copy link
Member

ashkulz commented Jan 17, 2023

Thanks for the contribution, @nevinera! I'll wait to see if #35 can also be merged before a release -- if there's no action there for a week I'll cut a release to RubyGems 👍

@nevinera
Copy link
Contributor Author

Thank you sir! No rush, we have a workaround in place :-)

@ashkulz
Copy link
Member

ashkulz commented Jan 20, 2023

This has been pushed to RubyGems 🎉

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.

2 participants