From 9d0d4a16d820c076e8ea5f96f40d8c1c5418133a Mon Sep 17 00:00:00 2001 From: Nyakku Shigure Date: Mon, 19 Sep 2022 15:14:11 +0800 Subject: [PATCH] [CodeStyle] fix cpplint hook not working on CI (#46136) * update cpplint hook script * update pre-commit config * try trigger cpplint on ci * Revert "try trigger cpplint on ci" This reverts commit 895853453c5f68b587914713e313c92abb69fc45. * empty commit, test=document_fix --- .pre-commit-config.yaml | 4 ++++ tools/codestyle/cpplint_pre_commit.hook | 25 ++----------------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 768f0222f5..a8d34f8b04 100755 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -51,6 +51,10 @@ repos: entry: bash ./tools/codestyle/cpplint_pre_commit.hook language: system files: \.(c|cc|cxx|cpp|cu|h|hpp|hxx)$ + args: + - --extensions=c,cc,cxx,cpp,cu,cuh,h,hpp,hxx,kps + - --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens + - --quiet - repo: local hooks: - id: pylint-doc-string diff --git a/tools/codestyle/cpplint_pre_commit.hook b/tools/codestyle/cpplint_pre_commit.hook index fdda83610f..f755557c65 100755 --- a/tools/codestyle/cpplint_pre_commit.hook +++ b/tools/codestyle/cpplint_pre_commit.hook @@ -1,32 +1,11 @@ #!/bin/bash -TOTAL_ERRORS=0 - readonly VERSION="1.6.0" version=$(cpplint --version) -if [[ ! $TRAVIS_BRANCH ]]; then - # install cpplint on local machine. - if ! [[ $version == *"$VERSION"* ]]; then +if ! [[ $version == *"$VERSION"* ]]; then pip install cpplint==1.6.0 - fi - # diff files on local machine. - files=$(git diff --cached --name-status | awk '$1 != "D" {print $2}') -else - # diff files between PR and latest commit on Travis CI. - branch_ref=$(git rev-parse "$TRAVIS_BRANCH") - head_ref=$(git rev-parse HEAD) - files=$(git diff --name-status $branch_ref $head_ref | awk '$1 != "D" {print $2}') fi -# The trick to remove deleted files: https://stackoverflow.com/a/2413151 -for file in $files; do - if [[ $file =~ ^(patches/.*) ]]; then - continue; - else - cpplint --filter=-readability/fn_size,-build/include_what_you_use,-build/c++11,-whitespace/parens $file; - TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?); - fi -done -exit $TOTAL_ERRORS +cpplint $@ -- GitLab