style-check/vera++: add style validator and scripts#9778
style-check/vera++: add style validator and scripts#9778smlng merged 4 commits intoRIOT-OS:masterfrom
Conversation
|
This is how it looks |
|
From how I interpret the coding conventions, line length >80 should be a warning, >100 should be an error. Is that possible to implement with Vera++? |
You are right. This is not possible directly, but can be solved adding a Then, it's required to execute vera++ 2 times (one with warnings and the other one with errors). What do you think? |
|
So vera complains but cannot not reformat automatically? |
Yes it can. There are some default transformations we might use (trailing whitespaces, etc) |
|
IMO uncrustify was a good idea. See #8519 (comment). |
|
@jia200x @miri64 If we are willing to modify the TCL files, the warning on line length >80 and throwing an error on length > 100 should be perfectly possible. Vera has only one "report" function, and it's up to the user to define a convention for report lines (something like Also, if I understand correctly, each script is run independently, meaning each file is traversed multiple times? @jia200x I suggest we include a few example configurations for popular editors, so that people can run Vera/Uncrustify while they are editing the file. It should encourage people to not wait till the last moment to fix the source. |
True
Not sure, but tend to think yes. I will check.
That's a nice idea. It's like what some editors do with PEP8 in Python. Pointing out errors is exactly a Vera++ job, because Uncrustify can only show the diff and not the reason (e.g |
On second thoughts, I think it parses/tokenizes first and then run all scripts at token level. |
My point is, if vim is so cool as it's followers claim it should be 100% possible to run Vera in "lint mode" (i.e. visually mark lines that are problematic). I don't use vim so I don't know. |
Yes, it's possible |
Should be possible, and I imagine, that popular linter-plugins like |
|
From the vera README:
Looking at the API, though, this statement may be a bit exaggerated. AFAICT vera only tokenizes the files. Any parsing is done by the scripts with ad-hoc state machines (like RIOT/dist/tools/vera++/rules/M001.tcl Line 19 in dde4d8b |
Yes, I think they refer to "interpreting" the C++ code into tokens. It's similar to what Uncrustify does |
daf1b22 to
5a246fe
Compare
|
What is the testing procedure for this one with https://github.com/RIOT-OS/riotdocker/pull/49 ? |
|
@cladmi I forgot to add it. Just updated it in the description. For testing, run |
|
I pushed the v1.2.1 files within the last commit, so it's compatible with the binary package shipped in Ubuntu |
|
@smlng @aabadie @kaspar030 I just fixed an error with the check script and now static tests pass. In theory this would be ready to be merged and would finally add some exhaustive lint checks to our C code. |
|
ping |
| #!/usr/bin/tclsh | ||
|
|
||
| set rules { | ||
| L004 |
There was a problem hiding this comment.
this is also in the force profile, to me it seems like either this or the other profile but not both, right?
There was a problem hiding this comment.
ah sorry, just saw that this goes with the parameter below, so please ignore
smlng
left a comment
There was a problem hiding this comment.
to me this looks good, and any additional auto check can only help.
one minor note: in the profile file one cannot infer what a rule does just by its number, e.g. L004, one always needs to lookup the rule file and see code and comments there. Maybe add short comment in the profile which rules are active, e.g.
L004 # max line length
But that's not a blocker, just something I found
It makes sense. I will |
|
@smlng done! |
|
(btw I couldn't add inline comments. They seems to be invalid in the TCL parser :( ) |
|
@smlng may I rebase? |
|
yes please rebase (and squash if needed) |
|
rebased and squashed! |
|
@smlng all test passed :) |
|
thanks! Can someone merge then? :) |
|
done |
|
thanks! |
|
Hm did you check how many errors vera++ reports for the existing code? |
Hmmm if it's being a problem, maybe we can try to set them to warnings and fix those errors in parallel? Then we can re-enable Vera++ errors |
Contribution description
This PR adds configuration files and a check script for using Vera++ in RIOT. This tool does C/C++ style checks with a given set of rules. The difference to other tools (like Uncrustify) is the fact this is not a code beautifier but a code validator.
New rules can be added in TCL, Python or LUA. The tool defines a "profile" which consists in a set of rules to be applied and some rule-specific parameters. A default
riotprofile was added.This PR also adds a
excludefile for excluding source files based on regular expressions (see--exclusionscommand here)The
riotprofile enables all rules except:And also defines some parameters for certain rules:
I also enabled "T008 Keywords catch, for, if, switch and while should be followed by a single space" but not sure if it's intended.
All feedback is more than welcome!
Check README.md file for more details.
Test procedure
Run
dist/tools/vera++/check.shIssues/PRs references
#8519 (which could be dropped if this one gets merged)