Skip to content

Commit

Permalink
Merge pull request #370 from Color-Of-Code/fix/368-params-count
Browse files Browse the repository at this point in the history
fix: Do not count `void` as a parameter (C/C++)
  • Loading branch information
terryyin authored Apr 25, 2024
2 parents 384d0cc + 9cff977 commit 7b47f88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lizard_languages/clike.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def _state_dec(self, token):
else:
self.next(self._state_global)
elif len(self.bracket_stack) == 1:
self.context.parameter(token)
if token != 'void': # void is a reserved keyword, meaning no parameters
self.context.parameter(token)
return
self.context.add_to_long_function_name(token)

Expand Down
8 changes: 6 additions & 2 deletions test/test_languages/testCAndCPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,21 @@ def test_double_slash_within_string(self):
result = get_cpp_function_list("""int fun(){char *a="\\\\";}""")
self.assertEqual(1, len(result))

def test_number_with_thousands_seperator_since_cpp14(self):
def test_number_with_thousands_separator_since_cpp14(self):
result = get_cpp_function_list("""int fun(){
int a= 100'000; if(b) c; return 123'456'789;
}""")
self.assertEqual(1, len(result))
self.assertEqual(2, result[0].cyclomatic_complexity)

def test_function_with_no_param(self):
def test_function_with_no_param_omitted(self):
result = get_cpp_function_list("int fun(){}")
self.assertEqual(0, result[0].parameter_count)

def test_function_with_no_param_void(self):
result = get_cpp_function_list("int fun(void){}")
self.assertEqual(0, result[0].parameter_count)

def test_function_with_1_param(self):
result = get_cpp_function_list("int fun(aa bb){}")
self.assertEqual(1, result[0].parameter_count)
Expand Down

0 comments on commit 7b47f88

Please sign in to comment.