-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #342 from peterschrammel/cpplint-fix
Cpplint fixes, regression tests for cpplint, and a pre-commit hook.
- Loading branch information
Showing
56 changed files
with
1,330 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# Runs scripts/cpplint.py on the modified files | ||
# Based on https://github.com/s0enke/git-hooks/ | ||
# | ||
# @author Peter Schrammel <[email protected]> | ||
|
||
gitRoot="$(dirname $0)/../.." | ||
|
||
# this is the magic: | ||
# retrieve all files in staging area that are added, modified or renamed | ||
# but no deletions etc | ||
files=$(git diff-index --name-only --cached --diff-filter=ACMR HEAD -- ) | ||
|
||
if [ "$files" == "" ]; then | ||
exit 0 | ||
fi | ||
|
||
# create temporary copy of staging area and delete upon exit | ||
cleanup() | ||
{ | ||
rm -rf $tmpStaging | ||
} | ||
|
||
trap cleanup EXIT | ||
|
||
tmpStaging=$(mktemp -d) | ||
|
||
# Copy contents of staged version of files to temporary staging area | ||
# because we only want the staged version that will be commited and not | ||
# the version in the working directory | ||
stagedFiles="" | ||
for file in $files | ||
do | ||
id=$(git diff-index --cached HEAD $file | cut -d " " -f4) | ||
|
||
# create staged version of file in temporary staging area with the same | ||
# path as the original file | ||
mkdir -p "$tmpStaging/$(dirname $file)" | ||
git cat-file blob $id > "$tmpStaging/$file" | ||
stagedFiles="$stagedFiles $tmpStaging/$file" | ||
done | ||
|
||
output=$(cd $gitRoot; python scripts/cpplint.py $stagedFiles 2>&1) | ||
retval=$? | ||
|
||
if [ $retval -ne 0 ] | ||
then | ||
echo "$output" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
default: tests.log | ||
|
||
test: | ||
@if ! ../test.pl -c python ../../../scripts/cpplint.py ; then \ | ||
../failed-tests-printer.pl ; \ | ||
exit 1 ; \ | ||
fi | ||
|
||
tests.log: ../test.pl | ||
@if ! ../test.pl -c "python ../../../scripts/cpplint.py" ; then \ | ||
../failed-tests-printer.pl ; \ | ||
exit 1 ; \ | ||
fi | ||
|
||
show: | ||
@for dir in *; do \ | ||
if [ -d "$$dir" ]; then \ | ||
vim -o "$$dir/*.c" "$$dir/*.out"; \ | ||
fi; \ | ||
done; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
catch(int) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CORE | ||
main.cpp | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
class temp_classt : public base_classt | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:9: There shouldn.t be a space between class identifier and : \[readability/identifiers\] \[4\]$ | ||
^Total errors found: 1$ | ||
^SIGNAL=0$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
// This should not produce a warning | ||
do | ||
{ | ||
int x=0; | ||
} | ||
while(a); | ||
|
||
// This should | ||
while(b); | ||
|
||
// As should this | ||
if(true) | ||
{ | ||
do_something(); | ||
} | ||
while(c); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:31: Empty loop bodies should use {} or continue \[whitespace/empty_loop_body\] \[5\]$ | ||
^main\.cpp:38: Empty loop bodies should use {} or continue \[whitespace/empty_loop_body\] \[5\]$ | ||
^Total errors found: 2$ | ||
^SIGNAL=0$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
do | ||
{ | ||
int x=0; | ||
} while(a); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:26: while statement of do...while loop should be on a separate line to the closing brace \[readability/braces\] \[4\] | ||
^Total errors found: 1$ | ||
^SIGNAL=0$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
do_something(); | ||
} | ||
|
||
static void foo() | ||
{ | ||
// No function header | ||
do_something(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:26: Could not find function header comment for foo \[readability/function_comment\] \[4\] | ||
^Total errors found: 1$ | ||
|
||
^SIGNAL=0$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
do_something(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CORE | ||
main.cpp | ||
|
||
main\.cpp:15: Function header for fun missing Inputs: \[readability/function_comment\] \[4\] | ||
main\.cpp:15: Function header for fun missing Outputs: \[readability/function_comment\] \[4\] | ||
main\.cpp:15: Function header for fun missing Purpose: \[readability/function_comment\] \[4\] | ||
^Total errors found: 3$ | ||
^SIGNAL=0$ | ||
-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
static void fun() | ||
{ | ||
do_something(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:20: Insert an empty line between function header comment and the function fun \[readability/function_comment\] \[4\]$ | ||
^Total errors found: 1$ | ||
^SIGNAL=0$ | ||
-- |
Oops, something went wrong.