Skip to content

Python: Function/Class Naming Convention (Syntax)#3810

Merged
RasmusWL merged 6 commits into
github:mainfrom
dilanbhalla:syntaxpython
Apr 12, 2021
Merged

Python: Function/Class Naming Convention (Syntax)#3810
RasmusWL merged 6 commits into
github:mainfrom
dilanbhalla:syntaxpython

Conversation

@dilanbhalla

Copy link
Copy Markdown
Contributor

A minor addition for maintaining standard coding practices when naming functions/classes in python. The two queries simply warn against function names that are capitalized or classes that are not. It is a small/simple addition but important practice that is especially helpful for readability purposes when sharing code with peers.

@dilanbhalla dilanbhalla requested review from a team and felicitymay as code owners June 25, 2020 18:47

@RasmusWL RasmusWL left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your submission @dilanbhalla 👍

Overall I think these cases are better handled by a linter (and pylint does mark these with the invalid-name rule), but I also don't see anything wrong with adding these queries. There is a few minor changes I would like to see just quickly looking over the code.

@tausbn how do you feel about adding these queires?

Comment thread python/ql/src/Functions/NamingConventionsFunctions.qhelp
Comment thread python/ql/src/Functions/NamingConventionsFunctions.qhelp
Comment thread python/ql/src/Classes/NamingConventionsClasses.ql Outdated
Comment thread python/ql/src/Functions/NamingConventionsFunctions.ql Outdated
@dilanbhalla

dilanbhalla commented Jul 1, 2020 via email

Copy link
Copy Markdown
Contributor Author

@dilanbhalla

dilanbhalla commented Jul 1, 2020 via email

Copy link
Copy Markdown
Contributor Author

@tausbn tausbn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your contribution.

I ran these queries against a couple of large/popular projects here:

Class names: https://lgtm.com/query/6870760152721696664/
Function names: https://lgtm.com/query/1144809513175497672/

I sampled a random selection of results, but none of them looked like true positives to me. Here I mean "true positive" in the sense that this would be something a developer would be inclined to fix upon seeing the alert. From this point of view, these queries are much too noisy to run automatically (though they may be of use to people who wish to enforce coding standards).

One possible improvement would be to also look at the context in which these declarations appear. For instance, if all (or most) classes in a given file are "illegally" named, then probably this was intended. I would be curious to see how many false positives this would eliminate.

Comment thread python/ql/src/experimental/Classes/NamingConventionsClasses.qhelp Outdated
Comment thread python/ql/src/experimental/Classes/NamingConventionsClasses.ql Outdated
Comment thread python/ql/src/experimental/Classes/NamingConventionsClasses.ql Outdated
Comment thread python/ql/src/experimental/Functions/NamingConventionsFunctions.qhelp Outdated
Comment thread python/ql/src/experimental/Functions/NamingConventionsFunctions.ql Outdated
Comment thread python/ql/src/experimental/Functions/NamingConventionsFunctions.ql Outdated
@felicitymay felicitymay removed their request for review July 9, 2020 07:46
@dilanbhalla dilanbhalla requested review from RasmusWL and tausbn July 12, 2020 21:34
@RasmusWL RasmusWL requested review from a team and removed request for RasmusWL July 15, 2020 08:33
@adityasharad adityasharad changed the base branch from master to main August 14, 2020 18:34

@tausbn tausbn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello! Thank you for your patience. I have made a few suggestions, two for the .qhelp files which had incorrect closing tags, and two for the queries themselves. I think this looks pretty close to being mergeable.

(And as you can tell, we're slowly getting back to reviewing external contributions again. We'll be revisiting the rest of your contributions in the near future.)

Comment thread python/ql/src/experimental/Classes/NamingConventionsClasses.qhelp Outdated
Comment thread python/ql/src/experimental/Functions/NamingConventionsFunctions.qhelp Outdated
Comment thread python/ql/src/experimental/Classes/NamingConventionsClasses.ql Outdated
Comment thread python/ql/src/experimental/Functions/NamingConventionsFunctions.ql Outdated
@dilanbhalla

dilanbhalla commented Mar 19, 2021

Copy link
Copy Markdown
Contributor Author

Apologies for the delay, and thanks for all of your comments! I incorporated all of the fixes.

@tausbn tausbn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this looks good to merge. However, it's currently failing the autoformatting CI check, and that's preventing us from merging. You'll need to autoformat the two .ql files and push the changes.

@dilanbhalla

Copy link
Copy Markdown
Contributor Author

Fixed

@dilanbhalla dilanbhalla requested a review from tausbn April 7, 2021 22:19
@tausbn

tausbn commented Apr 8, 2021

Copy link
Copy Markdown
Contributor

The CI is still complaining:

ql/python/ql/src/experimental/Functions/NamingConventionsFunctions.ql would change by autoformatting.

@dilanbhalla

Copy link
Copy Markdown
Contributor Author

That's super weird. I autoformatted and pushed changes for both but looks like only one changed looking back at the commit. I autoformatted the second and pushed, hopefully it is okay now.

@tausbn

tausbn commented Apr 9, 2021

Copy link
Copy Markdown
Contributor

@tausbn how do you feel about adding these queires?

I think these are fine to merge in their present form. With the addition of looking at the surrounding context and the functions and classes defined there, I think this might actually be a useful check to have. I don't know of any linters that do this, at any rate.

@tausbn tausbn requested a review from RasmusWL April 9, 2021 08:54

@RasmusWL RasmusWL left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, this looks fine to me 👍

@RasmusWL RasmusWL merged commit 364d489 into github:main Apr 12, 2021
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