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

Amend regex to prevent incorrect boolean return type #129

Merged
merged 6 commits into from
Nov 19, 2019

Conversation

ImClarky
Copy link
Contributor

Currently, any method name beginning with can, is or has is assumed to return type boolean. However this is not always the case, as method names like cancel or hash will not necessarily return a boolean.

This PR updates the regex to look for an uppercase letter, or an underscore (for CodeIgniter for example), directly after can, is or has to assert that will probably return boolean.

The change also adds should as an boolean-y prefix.

I changed the regex to /^(is|has|can|should)[A-Z_]/ but this would not apply for methods literally called can, is, has or should. Could update to /^(is|has|can|should)(?:[A-Z_]|$)/

@ImClarky ImClarky changed the title Update bool return trigger Amend regex to prevent incorrect boolean return type Nov 13, 2019
@neild3r
Copy link
Owner

neild3r commented Nov 17, 2019

@ImClarky can you merge in master to get the builds going again and add some test cases for the the problem you encountered. I feel like we could also account for digits here as well

@neild3r neild3r changed the base branch from master to v2.1.0 November 19, 2019 10:54
@neild3r neild3r merged commit 07d1c91 into neild3r:v2.1.0 Nov 19, 2019
@ImClarky ImClarky deleted the update-bool-return-trigger branch December 1, 2019 15:44
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.

None yet

2 participants