Skip to content
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

Conversation

hunyadi-dev
Copy link
Contributor

@hunyadi-dev hunyadi-dev commented May 20, 2020

Please pay special attention to the following commits on reviewing:

  • 1789ea5 MINIFICPP-1203 - Resolve include order linter recommendations
  • 4313831 MINIFICPP-1203 - Fix all leftover linter recommendations

🅰️ uto generated text, please do not waste your time reading this:

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:

  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file?
  • If applicable, have you updated the NOTICE file?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

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.

@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1203_enable_header_linting branch 13 times, most recently from 3d39c21 to a0dc345 Compare May 22, 2020 15:11
Copy link
Contributor

@arpadboda arpadboda left a 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.

extensions/standard-processors/CPPLINT.cfg Show resolved Hide resolved
extensions/standard-processors/processors/ListenSyslog.h Outdated Show resolved Hide resolved
generateVersion.sh Show resolved Hide resolved
libminifi/include/c2/C2Payload.h Show resolved Hide resolved
libminifi/include/c2/C2Protocol.h Show resolved Hide resolved
libminifi/include/core/Processor.h Show resolved Hide resolved
libminifi/include/core/state/Value.h Show resolved Hide resolved
libminifi/include/processors/ProcessorUtils.h Show resolved Hide resolved
libminifi/include/sitetosite/RawSocketProtocol.h Outdated Show resolved Hide resolved
libminifi/include/sitetosite/SiteToSite.h Outdated Show resolved Hide resolved
Copy link
Member

@szaszm szaszm left a 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.

generateVersion.sh Show resolved Hide resolved
libminifi/include/RemoteProcessorGroupPort.h Outdated Show resolved Hide resolved
libminifi/include/c2/C2Callback.h Outdated Show resolved Hide resolved
libminifi/include/c2/ControllerSocketProtocol.h Outdated Show resolved Hide resolved
libminifi/include/utils/Id.h Outdated Show resolved Hide resolved
libminifi/include/utils/MinifiConcurrentQueue.h Outdated Show resolved Hide resolved
libminifi/include/utils/file/FileUtils.h Show resolved Hide resolved
libminifi/include/utils/file/FileManager.h Outdated Show resolved Hide resolved
libminifi/include/utils/file/FileManager.h Outdated Show resolved Hide resolved
@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1203_enable_header_linting branch 4 times, most recently from 24abdc4 to 1ef4094 Compare June 4, 2020 09:39
@hunyadi-dev
Copy link
Contributor Author

Corrected all explicit additions and checked @szaszm -s comments one by one.

Copy link
Member

@szaszm szaszm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

libminifi/include/core/ClassLoader.h Outdated Show resolved Hide resolved
libminifi/include/sitetosite/SiteToSiteClient.h Outdated Show resolved Hide resolved
@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1203_enable_header_linting branch from 8edeec4 to d412c60 Compare June 5, 2020 11:22
…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
@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1203_enable_header_linting branch from d412c60 to ab4cea9 Compare June 12, 2020 12:57
@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1203_enable_header_linting branch from b45c7c7 to 7aedb2e Compare June 12, 2020 15:38
@hunyadi-dev
Copy link
Contributor Author

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:

manual_changelist.diff.zip

Comment on lines +46 to +47
// Without puttng this into its own namespace, the code would export already defined symbols.
namespace { // NOLINT
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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) {
Copy link
Member

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)

Suggested change
: Processor(name, uuid) {
: Processor(name, uuid) {


#include <memory>
#include <type_traits>
#include <utility>
#include <functional>

#include "gsl.h"
#include "gsl.h" // NOLINT
Copy link
Member

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?

Copy link
Contributor Author

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.

@hunyadi-dev hunyadi-dev force-pushed the MINIFICPP-1203_enable_header_linting branch from 7aedb2e to 2be2aec Compare June 12, 2020 17:57
@arpadboda arpadboda closed this in 2362fff Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants