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

Cpplint fix #342

Merged
merged 30 commits into from
Dec 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
497c692
No spaces around assignment operator
peterschrammel Dec 8, 2016
3fb7b1f
Improved wording
peterschrammel Dec 8, 2016
eb4e348
Pre-commit hook to run cpplint
peterschrammel Dec 8, 2016
ddd871c
Fix false alarm on preincrement
peterschrammel Dec 9, 2016
50eac16
Fixed linter bug where was thinking catch was a C style cast
Dec 8, 2016
9078c92
Corrected lint error on classes decl that have space after identifier
Dec 16, 2016
08bdc6e
Don't trigger the multi-line parameter warning in comments
Dec 16, 2016
d1af0e1
Added regression test for the prefix iterator in for loop
Dec 19, 2016
c50e81d
Adding missed make file
Dec 19, 2016
19876f5
Linter doesn't wrong warn about empty do while statement
Dec 19, 2016
19f29a3
Check for while is on the same line as closing brace in do-while
Dec 19, 2016
cca2e2d
Handle template argument lists that run on to multiple lines
Dec 19, 2016
0a1383c
Removed code that wasn't being used
Dec 20, 2016
773cdb7
Else statement with brace on same line
Dec 20, 2016
df109bc
Further developments on if lint checking
Dec 20, 2016
edcb06a
Fixing whitespace errors in the script
Dec 20, 2016
e6a5093
Disabled test for redundant override final specifier
Dec 20, 2016
13b7639
Don't demand removing space if operator starts a line
Dec 20, 2016
4f803c6
Added test for spacing error that wasn't being triggered
Dec 20, 2016
76193a2
Use elided lines when checking bracket indentation
Dec 20, 2016
60cb406
Don't warn about spacing around << as difficult to know if we should
Dec 20, 2016
e24f045
Lint script checks for the function comment header
Dec 21, 2016
6c7fe16
Addded description of the function comment header to coding standard
Dec 21, 2016
1418410
Reduced restrictions on the function comment header
Dec 21, 2016
0b35b4f
Extended coding guidelines to cover auto and forward declarations
Dec 21, 2016
9a6ea45
Added more explicit rules for breaking long lines
Dec 21, 2016
fa53b71
Removing tests for indentation
Dec 22, 2016
7638907
Don't include * or & in function name
Dec 22, 2016
7374c77
Handle operator functions when looking for function comment headers
Dec 22, 2016
d590db4
Don't think function declarations should have function header comments
Dec 22, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .githooks/pre-commit
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
51 changes: 44 additions & 7 deletions CODING_STANDARD
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@ Here a few minimalistic coding rules for the CPROVER source tree.
Whitespaces:
- Use 2 spaces indent, no tabs.
- No lines wider than 80 chars.
- When line is wider, do the following:
- Subsequent lines should be indented two more than the initial line
- Break after = if it is part of an assignment
- For chained calls, prefer immediately before .
- For other operators (e.g. &&, +) prefer immediately after the operator
- For brackets, break after the bracket
- In the case of function calls, put each argument on a separate line if
they do not fit after one line break
- If a method is bigger than 50 lines, break it into parts.
- Put matching { } into the same column.
- No spaces around operators, except &&, ||, and <<
- Spaces after , and ; inside 'for'
- No spaces around operators (=, +, ==, ...)
Exceptions: Spaces around &&, || and <<
- Space after comma (parameter lists, argument lists, ...)
- Space after colon inside 'for'
- No whitespaces at end of line
- No whitespaces in blank lines
- Put argument lists on next line (and ident 2 spaces) if too long
- Put parameters on separate lines (and ident 2 spaces) if too long
- No whitespaces around colon for inheritance,
Expand All @@ -16,8 +28,6 @@ Whitespaces:
- if(...), else, for(...), do, and while(...) are always in a separate line
- Break expressions in if, for, while if necessary and align them
with the first character following the opening parenthesis
- No whitespaces at end of line
- Avoid whitespaces in blank lines
- Use {} instead of ; for the empty statement
- Single line blocks without { } are allowed,
but put braces around multi-line blocks
Expand All @@ -29,9 +39,31 @@ Comments:
- Do not use /* */ except for file and function comment blocks
- Each source and header file must start with a comment block
stating the Module name and Author [will be changed when we roll out doxygen]
- Each function in the source file (not the header) is preceded
by a comment block stating Name, Inputs, Outputs and Purpose [will be changed
when we roll out doxygen]
- Each function in the source file (not the header) is preceded
by a function comment header consisting of a comment block stating
Name, Inputs, Outputs and Purpose [will be changed when we roll
out doxygen]
- It should look like this:
```
/*******************************************************************\

Function: class_namet::function_name

Inputs:
arg_name - Description of its purpose
long_arg_name - Descriptions should be indented
to match the first line of the
description

Outputs: A description of what the function returns

Purpose: A description of what the function does.
Again, indentation with the line above

\*******************************************************************/
```
- An empty line should appear between the bottom of the function comment header
and the function.
- Put comments on a separate line
- Use comments to explain the non-obvious
- Use #if 0 for commenting out source code
Expand All @@ -51,6 +83,8 @@ Naming:

Header files:
- Avoid unnecessary #includes, especially in header files
- Prefer forward declaration to includes, but forward declare at the top
of the header file rather than in line
- Guard headers with #ifndef CPROVER_DIRECTORIES_FILE_H, etc

C++ features:
Expand Down Expand Up @@ -85,6 +119,9 @@ C++ features:
- We allow to use 3rd-party libraries directly.
No wrapper matching the coding rules is required.
Allowed libraries are: STL.
- Use the auto keyword if and only if one of the following
- The type is explictly repeated on the RHS (e.g. a constructor call)
- Adding the type will increase confusion (e.g. iterators, function pointers)

Architecture-specific code:
- Avoid if possible.
Expand Down
20 changes: 20 additions & 0 deletions regression/cpp-linter/Makefile
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;
24 changes: 24 additions & 0 deletions regression/cpp-linter/catch-cast/main.cpp
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)
}
6 changes: 6 additions & 0 deletions regression/cpp-linter/catch-cast/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CORE
main.cpp

^EXIT=0$
^SIGNAL=0$
--
10 changes: 10 additions & 0 deletions regression/cpp-linter/class-decl-space/main.cpp
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
{}
7 changes: 7 additions & 0 deletions regression/cpp-linter/class-decl-space/test.desc
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$
--
39 changes: 39 additions & 0 deletions regression/cpp-linter/do-while1/main.cpp
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);
}
8 changes: 8 additions & 0 deletions regression/cpp-linter/do-while1/test.desc
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$
--
27 changes: 27 additions & 0 deletions regression/cpp-linter/do-while2/main.cpp
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);
}
7 changes: 7 additions & 0 deletions regression/cpp-linter/do-while2/test.desc
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$
--
30 changes: 30 additions & 0 deletions regression/cpp-linter/function-comment-header1/main.cpp
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();
}
8 changes: 8 additions & 0 deletions regression/cpp-linter/function-comment-header1/test.desc
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$
--
18 changes: 18 additions & 0 deletions regression/cpp-linter/function-comment-header2/main.cpp
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();
}
9 changes: 9 additions & 0 deletions regression/cpp-linter/function-comment-header2/test.desc
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$
--
23 changes: 23 additions & 0 deletions regression/cpp-linter/function-comment-header3/main.cpp
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();
}
7 changes: 7 additions & 0 deletions regression/cpp-linter/function-comment-header3/test.desc
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$
--
Loading