Skip to content

Commit 3c48404

Browse files
author
thk123
committed
Deal with multi-line function calls with nothing on the first line
Previously the regex was checking for the first parameter being on the first line, but this isn't required for the function call to be wrong. Added the check for each of the lines if there is no nested function call.
1 parent eb4597d commit 3c48404

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

regression/cpp-linter/multi-line-function-call1/main.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,14 @@ static void fun()
7575
var->fun(
7676
x,
7777
y);
78+
79+
// Incorrect
80+
fun(
81+
x, y);
82+
83+
// Incorrect
84+
fun(
85+
x, y,
86+
z);
7887
}
7988

regression/cpp-linter/multi-line-function-call1/test.desc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ main.cpp
99
^main\.cpp:62: Indent of wrapped parenthesized expression or parameter or argument list should be 2 \[whitespace/indent\] \[4\]
1010
^main\.cpp:71: If parameters or arguments require a line break, each parameter should be put on its own line\. \[whitespace/indent\] \[4\]
1111
^main\.cpp:76: Indent of wrapped parenthesized expression or parameter or argument list should be 2 \[whitespace/indent\] \[4\]
12-
^Total errors found: 8$
12+
^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\]
13+
^main\.cpp:85: If parameters or arguments require a line break, each parameter should be put on its own line. \[whitespace/indent\] \[4\]
14+
^Total errors found: 10$
1315
^EXIT=1$
1416
^SIGNAL=0$
1517
--

scripts/cpplint.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4696,7 +4696,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
46964696
# - ignore the line if it is a for/if etc since rules are different
46974697

46984698
# Look for an opening bracket that doesn't have a semi-colon on the same line
4699-
bracket_search = Search(r'(?P<bracket>\()[^;]*,[^;]*$', elided_line)
4699+
bracket_search = Search(r'(?P<bracket>\()[^;]*$', elided_line)
47004700

47014701
# Exclude the check if any of these keywords are present
47024702
# They could trip us up as they have different formatting rules to functions
@@ -4737,6 +4737,10 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
47374737
'If parameters or arguments require a line break, each parameter should be put on its own line.')
47384738
# Skip to the end of the bracket
47394739
start_linenum = nested_close_linenum
4740+
else:
4741+
if(not Match('^\s*[^,]+,$', arg_line)):
4742+
error(filename, start_linenum, 'whitespace/indent', 4,
4743+
'If parameters or arguments require a line break, each parameter should be put on its own line.')
47404744

47414745
start_linenum+=1
47424746
# For the final line we also need to check one parameter on it

0 commit comments

Comments
 (0)