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 query to ensure predicates starting with 'get' return a value #18164

Merged

Conversation

Napalys
Copy link
Contributor

@Napalys Napalys commented Nov 29, 2024

This PR adds a new query to ensure that predicates starting with 'get' actually return a value. It includes the query definition, expected test results, and test cases to validate the functionality.

@Napalys Napalys force-pushed the napalys/ql-validate-predicate-get-returns branch from 85c922f to a763dd7 Compare November 29, 2024 13:58
@Napalys Napalys marked this pull request as ready for review November 29, 2024 14:05
@Napalys Napalys requested a review from a team as a code owner November 29, 2024 14:05
@Napalys Napalys force-pushed the napalys/ql-validate-predicate-get-returns branch from 5fa40c4 to a5521b9 Compare November 29, 2024 14:18
@Napalys Napalys requested a review from aschackmull November 29, 2024 14:29
isGetPredicate(pred) and
not hasReturnType(pred) and
not isAlias(pred)
select pred, "This predicate starts with 'get' but does not return a value."
Copy link
Contributor

Choose a reason for hiding this comment

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

This message is slightly inaccurate now 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

a462ec9 🙈

@Napalys Napalys force-pushed the napalys/ql-validate-predicate-get-returns branch from 1f3187b to a462ec9 Compare November 29, 2024 14:58
@Napalys Napalys requested a review from aschackmull November 29, 2024 15:01
@Napalys Napalys force-pushed the napalys/ql-validate-predicate-get-returns branch from 9b9581f to a908a44 Compare November 29, 2024 16:30
@Napalys Napalys force-pushed the napalys/ql-validate-predicate-get-returns branch from a908a44 to 7c1aa84 Compare November 29, 2024 16:38
/**
* Returns "get" if the predicate name starts with "get", otherwise "as".
*/
string getPrefix(Predicate pred) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's really no need for this predicate - just replace regexpMatch with regexpCapture in isGetPredicate and add the prefix column to that predicate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, that does make it cleaner!
67745e6

@Napalys Napalys requested a review from aschackmull December 2, 2024 08:26
where
isGetPredicate(pred, prefix) and
not hasReturnType(pred) and
not isAlias(pred)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we instead check that whatever it aliases has a return type?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's a very reasonable extension of this query, but I don't mind merging as-is, hence approved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this what you have had in mind 01b62ad ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, thanks for adding.

aschackmull
aschackmull previously approved these changes Dec 2, 2024
@Napalys Napalys force-pushed the napalys/ql-validate-predicate-get-returns branch from 01b62ad to 7db9b7d Compare December 2, 2024 11:51
@Napalys Napalys merged commit f56e337 into github:main Dec 2, 2024
11 checks passed
@Napalys Napalys deleted the napalys/ql-validate-predicate-get-returns branch December 2, 2024 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants