[ci] [c++] use 'pre-commit' to run 'cpplint', upgrade to 'cpplint' 2.0.2 #7002
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contributes to #6949 and #6901, by moving more logic out of
test.sh.Proposes moving C++ linting into
pre-commit:cpplintgrepfor OpenMP pragmas calling the LightGBM-specific thread-control macrosAlso proposes upgrading from
cpplint1.6.0 to 2.0.2 (the latest version), and fixes one type of formatting warning it raises.Notes for Reviewers
Why also upgrade
cpplint?Looks like there was a
cpplint2.0 release about a year ago: https://github.com/cpplint/cpplint/releases/tag/2.0.0But we haven't been taking advantage of all those new checks here, because we install
cpplintwithcondaand theconda-forgefeedstock is not being actively maintained. See all the unmerged PRs here: https://github.com/conda-forge/cpplint-feedstock/pullsThis new
cpplintversion suggests hundreds of changes, in roughly 4 different categories:1. "Controlled statements inside brackets of while clause should be on a separate line [whitespace/newline]"
2. "Add `#include ` for `pair<>` [build/include_what_you_use]`
This is implementing some degree of include-what-you-use, to ensure headers aren't relying on transitive includes! (ref: #6284).
3. "Do not indent within a namespace. [whitespace/indent_namespace]"
4. "Using C-style cast. Use `static_cast(...)` instead [readability/casting]"
Proposing:
whitespace/newline: fix in this PRbuild/include_what_you_use: fix in followup PRswhitespace/indent_namespace: ignore indefinitelyreadability/casting: fix in this PRfull list of 333 warnings (click me)