add util/check-format.pl for checking adherence to C coding style#10363
add util/check-format.pl for checking adherence to C coding style#10363DDvO wants to merge 115 commits intoopenssl:masterfrom
Conversation
|
Cool! I think part of this PR should be to remove the old script. |
|
Nice! |
|
I agree with @richsalz |
|
Pleased to hear! |
|
I tried it on Here's the line with a bit of context: openssl/crypto/store/loader_file.c Lines 224 to 226 in 6af1b11 So it seems that this scripts want to make the extra indent "mandatory", while this isn't policy (and is still subject for debate). We allow that extra indentation, so this script should currently accept both styles, i.e. both this: if (PKCS12_verify_mac(p12, "", 0)
|| PKCS12_verify_mac(p12, NULL, 0)) {
pass = "";and this: if (PKCS12_verify_mac(p12, "", 0)
|| PKCS12_verify_mac(p12, NULL, 0)) {
pass = "";We have this kind of hanging indent of labels all over the place, i.e. a hang back of 3 columns, not 4. This came to be with our Line 15 in 6af1b11 The indent manual explains it like this:
Why this was a good idea at the time, I cannot remember. So this is a complete mystery to me. This is the line with a bit of context: openssl/crypto/store/loader_file.c Lines 1106 to 1110 in 6af1b11 This seems to be some kind of fault in how indentation is calculated. Here are those lines plus a little extra: openssl/crypto/store/loader_file.c Lines 1417 to 1430 in 6af1b11 So er, the actual complaint would really be that the braces are on a line of their own... right? |
Thanks for trying it out and your detailed feedback!
Done.
I've relaxed the check for label indents to allow them both at column 1 and (current_indent-3).
This was a false positive and went away with my today's improvements.
This was due to incomplete detection of complex multi-line assignments involving braces; I've strongly improved this (also for the rare case of constant value decls within |
|
This work is amazing. |
|
Great job! |
|
Thanks! |
|
I've just fixed two small further issues, |
|
I've improved the handling of comments and string literals |
|
Note: looking at the util directory, many of the scripts are named using imperative style ("find doc nits", "merge err lines", "format source", "find unused errs", etc.) and not a (typical german?) nominal style as in "openssl format check". Also most of those scripts don't have a .pl extension. How about just calling it |
|
Or |
|
I like |
|
Should I remove the |
|
Is there sufficient agreement to remove the old script ( |
|
I've meanwhile resolved the TODOs on handling multi-line string literals. |
It‘s not a request, only a suggestion based on recent habits. Unless the script works and is intended to be used on Windows too, I see no reason to keep it. |
|
I think the "openssl-" prefix wastes needless space. After all, this is in the openssl source distribution. :) I like "check-formatting" or something like that. Yes, remove the .pl extension. As for removing the old file, an OMC member said yes; #10363 (comment) |
|
So my proposal is to go for |
|
One last attempt on the .pl extension: Most development is on unix-like platforms; those windows developers can put "perl" in front of the command-line. :) |
O.k. It does have the advantage that the script can be invoked on Windows without prefixing it with |
|
I'm also quite in favor of not putting an extra burden on those poor guys (sometimes including myself) developing in Windows ;) For Unix use, we have the first line referring to Perl, and on Windows the name extension usually does the trick. |
|
:) |
|
cool. Adding a unit test for a utility script seems to be unprecedented. |
|
Yeah, given the non-trivial nature of the thing, BTW, meanwhile I've further reduced both false positives and false negatives; some more of this is to come. |
|
@levitte, should I add a report for one-letter names other than |
|
BTW, this PR is still waiting for a formal review. |
|
I only looked at this one to understand what you were on to in #10363 (comment) |
No, I think that's a bit over the top. There's more over the place, such as the local pointers |
|
We could automatically check for names that definitely should not be used, as mentioned by @bernd-edlinger: #10725 (comment), namely |
|
That, I think is a better idea. Advice against specifics instead of disallowing all but just a few. Yes. |
|
Done. The tool now reports 5 one-letter variables ' |
Don't forget |
There is also |
|
See "etc" 😉 |
|
I don't like those one-char variable names at all: |
|
So maybe don't worry about one-character variables for now. The phrase "diminishing returns" comes to mind. |
Noted. |
Or |
|
Sorry to disappoint your creativity 😉
(Yet surely this is something a tool cannot check.) |
levitte
left a comment
There was a problem hiding this comment.
On pure principle, we should have this script. It's possible that it needs another tweak or two, I don't know and haven't really checked thoroughly, but...
|
This pull request is ready to merge |
aims at checking most of https://www.openssl.org/policies/codingstyle.html and various requirements not yet explicitly stated there - see also #10725 add util/check-format.pl and its self-tests in util/check-format-test-{positives,negatives}.c remove util/openssl-format-source Reviewed-by: Richard Levitte <[email protected]> Reviewed-by: David von Oheimb <[email protected]> (Merged from #10363)
|
Pushed (using Thanks for all feedback by @levitte and many others. |
When contributing PRs to OpenSSL it typically happens that the code does not (fully) adhere to the coding style guidelines at https://www.openssl.org/policies/codingstyle.html and to further implicit conventions that are not (yet) part of the rules stated there.
In particular when we contributed larger chunks of code, reviewers typically found many formatting issues that are usually trivial to resolve but tend to cause extra overhead and distract from more important issues.
There is already a tool that is supposed to automatically (re-)format code:
util/openssl-format-source, yet this appears rather outdated and not really practical to use.So I spent some effort on a new Perl tool that aims at checking adherence at least to most of the OpenSSL formatting rules we are aware of.
This new tool is in preliminary state: it is incomplete and yields some false positives.
Still it has already proved pretty useful for detecting most typical formatting glitches.