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

Add cop against .void.checked(:tests) #196

Merged
merged 6 commits into from
Feb 9, 2024

Conversation

jez
Copy link
Contributor

@jez jez commented Dec 30, 2023

I think I regenerated all the files that need to be regenerated but let me know if anything is missing.

@jez jez requested a review from a team as a code owner December 30, 2023 23:41
@jez jez requested review from andyw8 and st0012 December 30, 2023 23:41
@jez
Copy link
Contributor Author

jez commented Dec 30, 2023

I have signed the CLA!

@jez jez marked this pull request as draft January 2, 2024 17:36
@jez
Copy link
Contributor Author

jez commented Jan 2, 2024

@andyw8
Copy link
Contributor

andyw8 commented Jan 2, 2024

(for Shopifolk: I see only 3 instances of this across all our code).

@andyw8 andyw8 removed their request for review January 5, 2024 18:30
@jez jez marked this pull request as ready for review January 9, 2024 00:41
@Morriar
Copy link
Contributor

Morriar commented Jan 19, 2024

@jez
Copy link
Contributor Author

jez commented Jan 22, 2024

Lint errors should be fixed, thanks for the heads up


if (parent = node.parent) && (sibling_index = node.sibling_index)
later_siblings = parent.children[(sibling_index + 1)..]
if (def_node = later_siblings.find { |sibling| sibling.is_a?(RuboCop::AST::DefNode) })
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this lead to miss cases like this one?

sig { params(foo: Integer).void.checked(:tests)
attr_writer :foo 

def initialize; end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good catch. In this case, it would default to no error (false negative) rather than a spurious, false positive error.

The specific reason why I implemented this was because it appears that Sorbet is fine with

sig { void }
X = 1
def foo; end

which is weird, and happened once in Stripe's codebase.

An alternative would be to put it back to what I was originally doing, and only report the error if the next sibling node is a def node. That would lead to even more false negatives, I think, but maybe it would be easier to understand how to cop works.

Copy link
Contributor

Choose a reason for hiding this comment

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

The attr case should be relatively unfrequent, I think we can go with the current implementation 👍


if (parent = node.parent) && (sibling_index = node.sibling_index)
later_siblings = parent.children[(sibling_index + 1)..]
if (def_node = later_siblings.find { |sibling| sibling.is_a?(RuboCop::AST::DefNode) })
Copy link
Contributor

Choose a reason for hiding this comment

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

The attr case should be relatively unfrequent, I think we can go with the current implementation 👍

@Morriar Morriar merged commit 608f21b into Shopify:main Feb 9, 2024
6 checks passed
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.

3 participants