-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 clint for checking coding style #192
Conversation
Done:
Some observations:
To doMoving opening braces onto the next lineThis might be non-trivial due to the way that cpplint checks for braces. It checks whether there is an opening brace on its own line and errors out. It only allows this case if:
I do not want to make significant arbitrary changes, but I think given that we want to finish this as soon as possible and that the very close second and third choices put the brace at the end of the function declaration, if modifying cpplint for this turns out to be too difficult Trial conversionsI'm going to do trial conversions of a few files to determine whether additional modifications are necessary. I see that some files have gotos but have yet to see whether this will fail lint since the style guide does not mention goto. |
Just remove the check for |
Good idea. :) Changed. All of the 3 modifications are now covered. I'll look for any additional cases that need to be handled. |
AIUI this PR is a work in progress and needs to be finished before being merged, is that correct or have I misunderstood the "To do" secion? |
The PR is a work in progress; I opened it early for discussion. The first to do item is done. The remaining item is to see whether there are any more obvious cases that require modifying the lint script in order to handle. |
@davidzchen Thanks for clarifying. When it's ready, could you @-mention one of people with merge access so we know when to look over it? I like the idea of something which can check the code style which has been agreed on. (Think: the |
@rjw57 Thanks. Will do. Some common errorsI have run
The Google C++ coding style specifies that source code under
This error is raised due to usage of
Does neovim have a copyright owner? Are we planning to change the header comment in the source files? If we are not, I'll suppress this error. Other observations
|
@tarruda, @simendsjo, @rjw57 Thoughts on the above? |
Just a general note: I think it's fine to remove rules from the linter, especially in a (long) transition period. We should pick up this thread again after uncrustify has been run. @davidzchen You are writing the uncrustify config too? |
@davidzchen that's great. At first I thought about using uncrustify for checking style(apply and if it differs generate an error) but this is much better as it will report the exact errors. |
@davidzchen Just an FYI, when trying to use uncrustify a couple years ago I ran into a number of edge cases it didn't handle well. Just be careful using it, and make sure to go over the results. |
Thanks. I'll suppress the three errors I listed above. When we decide to clean those up, we can enable them individually for checking those tasks. I have been experimenting with uncrustify. It's a neat tool, but as @jszakmeister mentioned, there are certain edge cases that it does not handle very well. One of the issues I have been running into is caused by the fact that many comments are currently at the end of a line. There might be a configuration option that would help, but I am still going through all the options. Once I have an uncrustify config that works, I'll add it, as well as some documentation changes to CONTRIBUTING.md. |
I have added my in-progress uncrustify.cfg. I have most of the wrinkles smoothed out. There are a few remaining issues such as variable declarations with Once I'm done, I'll squash all of these changes using rebase. |
Users of syntastic might find this useful: https://gist.github.com/gilligan/9326904 It adds clint as a possible checker for c files. Note that |
I think the uncrustify.cfg is as good as it gets for now without spending a further inordinate amount of time on it. I have squashed all of my commits and rebased on master. I think this PR is ready to be merged. Once this is merged, I will use uncrustify.cfg to make an initial style cleanup pass and submit that as a separate PR. |
This pull is for both |
Yes, this is for That is interesting. What is your input file? I downloaded the |
Maybe I'm not using
|
That is interesting. This is the output I get:
Do you get output when you run |
That's bold. How about
|
@davidzchen : ➜ ~ python --version
Python 3.3.4
➜ ~ python2 --version
Python 2.7.6 |
@mahkoh Apparently Google uses Python 2.x internally. @simendsjo If you change the shebang to |
On 03/04/2014 06:57 PM, David Z. Chen wrote:
Yes, it works with python2 |
Is there a way to ensure that this script will be run using python2 for users who have selected Python 3 as their primary Python version without changing the shebang to |
I think this PR is ready to be merged. I have not implemented checking for braces for control structures in clint, but the combination of that and testing is non-trivial and uncrustify will automatically insert braces anyway. Likewise, clint also does not check for the opening brace for function declarations being on the next line, but as @simendsjo mentioned earlier in this thread, these changes can come later. After this PR is merged, I would like to make an initial cleanup pass with uncrustify and will submit that as a separate PR. |
# True=indent the 'if' one level | ||
indent_else_if = false # false/true | ||
|
||
# Amount to indent variable declarations after a open brace. neg=relative, pos=absolute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a open brace → an open brace
# This is generally a bad idea, as it may break your code. | ||
mod_sort_include = false # false/true | ||
|
||
# If TRUE, it will move a 'break' that appears after a fully braced 'case' before the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preceeded → preceded
@dpelle I appreciate your diligence, but these comments are actually automatically generated by |
@simendsjo @tarruda Do you have any more feedback on this before it can be merged? |
One thing I noticed is that it complains about variables named |
@davidzchen this looks good to me. Can you rebase on top of master? Also make sure any necessary dependencies for travis are installed(before_install in travis.yml) |
…uting documentation on coding style.
Thanks @tarruda. I have rebased on top of master. I want to make an initial pass with uncrustify in a separate PR after this. Because clint will throw a large number of errors right now, I have not integrated clint with the build system and as a result, there are no changes to travis needed at this point. |
Merged. @davidzchen I think before merging clint you will need to pipe all files through uncrustify right? |
There are some false positives. If you don't mind, I'm going to remove the parts that don't apply to C code (templates, references, etc.) |
@tarruda Correct. Before we integrate clint into any sort of automation, we should at least do an initial clean-up pass. I have started doing an initial clean-up using uncrustify and will send a separate PR for that soon. @mahkoh That sounds good. I'd be fine with the UNIX "do one thing and do it well" principle and have clint.py be specific to C. If we decide to start adding C++ to the codebase in the future, we can re-import cpplint.py and use that script specifically for the C++ code. |
Adding a lint script for checking source files for coding style.
The new neovim coding style, as decided in the poll in #104, is a modification of the Google C++ coding style with the following modifications:
lower_case
rather thanPascalCase
struct lower_case
andenum lower_case
.This PR is for adding Google's cpplint.py lint script and modifying it with the above changes. We will also do some trial conversions of some source files to determine whether additional tweaks are required. Due to the additional time required to make modifications to cpplint.py, these additional tweaks should be limited and in favor of adhering more closely to the Google convention than diverging from it.