-
Notifications
You must be signed in to change notification settings - Fork 5
Add linting with clang tidy #39
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
base: develop
Are you sure you want to change the base?
Conversation
@alexander-novo, could you explain what this PR accomplishes? |
I ran lint and got ~6,000 lines of suggestions, most of them actually very helpful. Thanks, @alexander-novo! I can see one possible showstopper: Enforcing variable names to abide by the style guidelines works strict to the letter, but in some cases it would be good to have exceptions. For example, variables @abirchfield, please chime in. |
I would say that mathematical nature of the code would be the reason to eliminate all magic numbers. We want all numbers to be defined before we use them. But, I can also see how it can backfire. Lint could catch on ,e.g., constexpr real_type ONE_HALF = static_cast<real_type>(0.5);
(...)
e_k = ONE_HALF * m * v * v Perhaps we can live with this? |
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.
I am OK with this. Most of this is a matter of preference. My preference would be to write 0.5 rather than ONE_HALF, and to align variable capitalization with modeling conventions. But it looks like we can add exceptions as needed.
It is possible to disable checking of identifier names which match a certain regular expression, so we could set this regular expression which matches any identifier which begins with a capital letter. But I really think variables really should start with a lowercase letter - when I see an identifier that begins with a capital letter, I think that it refers to a class or struct. Also, ignoring a variable name will also disable other checks, such as ensuring that member variables have an underscore suffix. We could also introduce a prefix such as, for instance, I also worry that there are plenty of math notations that we wouldn't be able to accurately represent in a variable name, so it may be better to go with the prefix |
Constants 2.0 and 0.5 are ignored, since these are common and self-explanatory constants in many formulae.
Using |
I added an exceptional local variable name |
Was unfortunately unable to find a lint that enforced the
MicroGrid
namespace, but I'll keep looking.There are a lot of things that need to be fixed. I'll fix them as a separate pull request.
I turned off the "magic numbers" lint just because I think the mathematical nature of the code will require some magic numbers. I also turned off the "easily swappable parameters" lint because it seemed too burdensome to fix properly, although please check the documentation for the lint and let me know if it's something we should have on.
I don't currently have any "modernize" lints on (lints which encourage using more modern features of C++ over older methods), but I have considered enabling the following:
modernize-use-emplace
modernize-use-nullptr
modernize-use-override
modernize-use-using
Closes #34