-
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 #415 from thk123/feature/lint-check-multi-line-fun…
…ction-call Lint checks nested function calls broken over multiple lines
- Loading branch information
Showing
8 changed files
with
320 additions
and
3 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
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,88 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
// Correct | ||
foo( | ||
x, | ||
y); | ||
|
||
// Incorrect, x should be on the next line | ||
foo(x, | ||
y); | ||
|
||
// Incorrect indent should be only 2 | ||
foo( | ||
x, | ||
y); | ||
|
||
// Correct | ||
int x=bar( | ||
x, | ||
y); | ||
|
||
// Incorrect, x should be on the next line | ||
int x=bar(x, | ||
y); | ||
|
||
// Incorrect indent should be only 2 | ||
int x=bar( | ||
x, | ||
y); | ||
|
||
// Correct | ||
*model=baz( | ||
x, | ||
y); | ||
|
||
// Incorrect, x should be on the next line | ||
*model=baz(x, | ||
y); | ||
|
||
// Incorrect indent should be only 2 | ||
*model=baz( | ||
x, | ||
y); | ||
|
||
// Correct | ||
var->fun( | ||
x, | ||
y); | ||
|
||
// Incorrect, x should be on the next line | ||
var->fun(x, | ||
y); | ||
|
||
// Incorrect indent should be only 2 | ||
var->fun( | ||
x, | ||
y); | ||
|
||
// Incorrect | ||
fun( | ||
x, y); | ||
|
||
// Incorrect | ||
fun( | ||
x, y, | ||
z); | ||
} | ||
|
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,17 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:29: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\] | ||
^main\.cpp:34: Indent of wrapped parenthesized expression or parameter or argument list should be 2 \[whitespace/indent\] \[4\] | ||
^main\.cpp:43: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\] | ||
^main\.cpp:48: Indent of wrapped parenthesized expression or parameter or argument list should be 2 \[whitespace/indent\] \[4\] | ||
^main\.cpp:57: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\] | ||
^main\.cpp:62: Indent of wrapped parenthesized expression or parameter or argument list should be 2 \[whitespace/indent\] \[4\] | ||
^main\.cpp:71: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\] | ||
^main\.cpp:76: Indent of wrapped parenthesized expression or parameter or argument list should be 2 \[whitespace/indent\] \[4\] | ||
^main\.cpp:81: If parameters or arguments require a line break, the closing bracket should be on the same line as the final parameter \[whitespace/indent\] \[4\] | ||
^main\.cpp:85: If parameters or arguments require a line break, each parameter should be put on its own line. \[whitespace/indent\] \[4\] | ||
^Total errors found: 10$ | ||
^EXIT=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,67 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
// Incorrect, call should be on a new line | ||
nested(call(), | ||
another_param); | ||
|
||
// Incorrect - should be indented by 2 | ||
nested( | ||
call(), | ||
another_param); | ||
|
||
// Correct | ||
nested( | ||
call(), | ||
another_param); | ||
|
||
// Correct | ||
twice( | ||
nested( | ||
call( | ||
param1), | ||
param2), | ||
param3) | ||
|
||
// Correct | ||
foo( | ||
bar(x, y), | ||
z); | ||
|
||
// Correct | ||
foo( | ||
bar( | ||
x, | ||
y), | ||
z); | ||
|
||
// Incorrect, the bar arguments have been split up therefore | ||
// they all should be split up | ||
foo( | ||
bar(x, | ||
y), | ||
z); | ||
|
||
// Incorrect bar should be on the next line | ||
foo(bar(x, y), | ||
z); | ||
} |
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,11 @@ | ||
CORE | ||
main.cpp | ||
|
||
^main\.cpp:24: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\] | ||
^main\.cpp:29: Indent of wrapped parenthesized expression or parameter or argument list should be 2 \[whitespace/indent\] \[4\] | ||
^main\.cpp:60: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\] | ||
^main\.cpp:65: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\] | ||
^Total errors found: 4$ | ||
^EXIT=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,55 @@ | ||
/*******************************************************************\ | ||
Module: Lint Examples | ||
Author: Thomas Kiley, [email protected] | ||
\*******************************************************************/ | ||
|
||
/*******************************************************************\ | ||
Function: fun | ||
Inputs: | ||
Outputs: | ||
Purpose: | ||
\*******************************************************************/ | ||
|
||
static void fun() | ||
{ | ||
// Correct as for loop not function | ||
for(int x=0; | ||
x<10; | ||
++x) | ||
{} | ||
|
||
// Correct as an if statement not a function | ||
if(a==b || | ||
c==d) | ||
{ | ||
do_something(); | ||
} | ||
|
||
// Correct as ranged based for loop not function | ||
for(x: | ||
list) | ||
{} | ||
|
||
// Correct since if statement | ||
if(some_check(with, params)== | ||
some_value) | ||
{ | ||
do_something(); | ||
} | ||
|
||
// Correct since if statement | ||
if(condition_a&& | ||
(condition_b|| | ||
condition_c)) | ||
{ | ||
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 | ||
|
||
^Total errors found: 0$ | ||
^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