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
MINIFICPP-1203 - Enable header linting in include directories and resolve linter recommendations #789
MINIFICPP-1203 - Enable header linting in include directories and resolve linter recommendations #789
Conversation
3d39c21
to
a0dc345
Compare
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 lot of good changes, thanks!
I don't like the mixed comment ending at namespace closing, otherwise mostly looks good.
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.
My feelings are mixed about this contribution.
Positive:
I like changes like these that get the low hanging fruit by fixing the easy issues for a larger benefit. Thanks for taking the time to improve the code quality. 👍
Negative:
Many of the opened issues are obvious when looking at the code. I'd like to kindly ask you to review your changes before or shortly after submitting them, to respect the time of the reviewers and to avoid having the important issues getting lost in the noise.
Other notes:
We try to follow semver with libminifi, meaning we don't break API in minor versions. While normally single-parameter constructors should be explicit, we must consider not breaking third-party code when fixing those issues.
I commented to most of the changes that marked single-parameter constructors explicit
, even if in some cases they are unlikely to be used outside of libminifi. I suggest staying on the safe side and reverting those changes, except when they affect relatively new code (e.g. WindowsEventLogSink) or anything related to ThreadPool which was recently substantially changed anyway due to a serious bug.
24abdc4
to
1ef4094
Compare
Corrected all |
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.
👍
8edeec4
to
d412c60
Compare
…r corresponding .cpp files
…s-specific symbol imports
…er recommendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "endif line should be" | tr ":" " " | cut -d" " -f1,2,9-12 | xargs -n 3 sh -c 'sed -i "" "$2s;.*;$3;" $1' sh | less
…lowing each other This can only be solved by removing the first visibility modifier, because otherwise either a ... followed by a blank line or a ... should be preceded by a blank line error occurs Script used (after all the aforementioned errors were cleared): make linter |& egrep -v '^Done processing|^Ignoring' | grep "Do not leave a blank line after" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2d" $1 && sed -i "" "$(expr $2 - 1)d" $1' sh
…mmendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "Line contains only semicolon." | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/[[:blank:]]*;/;/" $1 && perl -pi -e "s/\\n// if $. == $2 - 1" $1&& sed -i "" "$(expr $2 - 1)s/;;$/;/" $1' sh
…inter recommendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "should be indented +1" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/^/ /" $1' sh Manual edit in: libminifi/include/core/logging/WindowsEventLogSink.h libminifi/include/core/repository/AtomicRepoEntries.h
…o linter recommendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "Extra space before last semicolon" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/ ;$/;/" $1' sh
…recommendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "Extra space after (" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/( /(/g" $1' sh make linter |& egrep -v '^Done processing|^Ignoring' | grep "Extra space before )" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/ )/)/g" $1' sh make linter |& egrep -v '^Done processing|^Ignoring' | grep "Extra space before (" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/ (/(/g" $1' sh
Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "<= 200 characters long" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s;$; // NOLINT;" $1' sh
…ndations Script used (until no more errors returned): make linter |& egrep -v '^Done processing|^Ignoring' | grep "Tab found; better to use spaces" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'perl -pi -e "s/\t/ /g if $. == $2" $1' sh
…ter recommendation Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "(^M) found" | tr ":" " " | cut -d" " -f1 | sort | uniq | xargs dos2unix --
…rding to linter recommendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "Weird number of spaces at line-start" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/^ //" $1' sh
…linter recommendation Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "An else should appear on the same line as the preceding }" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/[[:blank:]]*else/else/" $1 && perl -pi -e "s/\\n/ / if $. == $2 - 1" $1' sh
…rding to linter recommendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "Namespace should be terminated with" | tr ":" " " | tr -d '"'| cut -d" " -f1,2,12 | xargs -n 3 sh -c 'sed -i "" "$2s;$; // namespace $3;" $1 && sed -i "" "$2s;/[*] names[ap][ap]ce .*[*]/ //;//;g" $1' sh make linter |& egrep -v '^Done processing|^Ignoring' | grep "Anonymous namespace should be terminated with" | tr ":" " " | cut -d" " -f1,2 | xargs -n 2 sh -c 'sed -i "" "$2s;$; // namespace;" $1' sh
…ations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "You don't need a ;" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s/;$//" $1' sh Manual edits: libminifi/include/utils/file/FileUtils.h libminifi/include/agent/build_description.h
…ions Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "build/include_what_you_use" | tr ":" " " | cut -d" " -f1,7 | sort -rn -k1 -k2 | uniq | xargs -n 2 sh -c 'perl -pi -e "s/#pragma once/#pragma once\n\n#include $2/" $1' sh make linter |& egrep -v '^Done processing|^Ignoring' | grep "build/include_what_you_use" | tr ":" " " | cut -d" " -f1,7 | sort -rn -k1 -k2 | uniq | xargs -n 2 sh -c 'perl -pi -e "BEGIN { undef $/; } s/#ifndef (.*)\n#define \1/#ifndef \1\n#define \1\n\n#include $2/" $1' sh
Tool used: https://github.com/TheOstrichIO/cpplint/tree/nitpick-sort-includes/cpplint Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "build/include_order" | tr ":" " " | cut -d" " -f1 | sort -rn -k1 -k2 | uniq | xargs python nitpick.py style
… linter recommendations Script used: make linter |& egrep -v '^Done processing|^Ignoring' | grep "At least two spaces is best between code and comments" | tr ":" " " | cut -d" " -f1,2 | sort -rn -k1 -k2 | xargs -n 2 sh -c 'sed -i "" "$2s;//; //;" $1' sh
Script used (ran until it performed no new changes): git diff --name-only master...$(git branch --show-current) | xargs perl -0777 -ne 'print "$ARGV $1\n" while /^(#include \<.*(?<!\.h)\>)\n\n(#include \<.*(?<!\.h)\>)$/mg' | xargs -n 3 sh -c 'perl -pi -e "s/$2 $3\n/$2 $3/g" $1' sh
…stent Also, fix incorrect header guard closing #endifs that were not reported due linter becoming confused on /* style comments Script used: git diff --name-only master...$(git branch --show-current) | xargs perl -0777 -pi -e 's/^(\s*}) \/\* namespace (.*) \*\/ *$/$1 \/\/ namespace $2/mg' make linter |& egrep -v '^Done processing|^Ignoring' |& grep -v "Done proces" | grep "endif line should be" | tr ":" " " | cut -d" " -f1,2,9-12 | xargs -n 3 sh -c 'sed -i "" "$2s;.*;$3;" $1' sh | less
…r comments, add NOLINT to non-explicit ctors mentioned by the linter
…e API breaking explicit
d412c60
to
ab4cea9
Compare
b45c7c7
to
7aedb2e
Compare
As I had to rebase on master unsafely, I decided to repeat the non-manual steps on resolving linter errors on top of branch. After doing so, I compared the resulting HEAD with the tip of the current branch, here is the diff file which I confirmed to contain manual style changes only: |
// Without puttng this into its own namespace, the code would export already defined symbols. | ||
namespace { // NOLINT |
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.
Note: we should eventually fix this by marking the implementations inline
or by moving them to impl files, and not using static linkage.
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.
Agreed and noted here:
https://issues.apache.org/jira/browse/MINIFICPP-1258
@@ -136,8 +138,7 @@ class HashContent : public core::Processor { | |||
* Create a new processor | |||
*/ | |||
explicit HashContent(std::string name, utils::Identifier uuid = utils::Identifier()) | |||
: Processor(name, uuid) | |||
{ | |||
: Processor(name, uuid) { |
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.
there should be a continuation indentation (+4 spaces)
: Processor(name, uuid) { | |
: Processor(name, uuid) { |
|
||
#include <memory> | ||
#include <type_traits> | ||
#include <utility> | ||
#include <functional> | ||
|
||
#include "gsl.h" | ||
#include "gsl.h" // NOLINT |
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.
what's the issue here?
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.
Same as before, libraries that are not in subdirectories included in ""
are recognized as C system headers for some reason.
…ing, fix incorrect ctr explicitness
7aedb2e
to
2be2aec
Compare
Please pay special attention to the following commits on reviewing:
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically master)?
Is your initial contribution a single, squashed commit?
For code changes:
For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.