Skip to content

Fix false positive for indented parameters in namespaces #304

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

Merged
merged 1 commit into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog
*********

2.0.1 (2025-01-??)
==================

Yet another overdue... hotfix. Sorry this took so long.

* The false positive for indented function parameters in namespaces was eradicated.

2.0 (2024-10-06)
================

Expand Down
12 changes: 11 additions & 1 deletion cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,11 @@ def __init__(self):
# the full nesting stack would slow down cpplint by ~10%.
self.previous_stack_top = []

# The number of open parentheses in the previous stack top before the last update.
# Used to prevent false indentation detection when e.g. a function parameter is indented.
# We can't use previous_stack_top, a shallow copy whose open_parentheses value is updated.
self.previous_open_parentheses = 0

# Stack of _PreprocessorInfo objects.
self.pp_stack = []

Expand Down Expand Up @@ -3206,6 +3211,7 @@ def Update(self, filename, clean_lines, linenum, error):
# deepcopy would slow down cpplint by ~28%.
if self.stack:
self.previous_stack_top = self.stack[-1]
self.previous_open_parentheses = self.stack[-1].open_parentheses
else:
self.previous_stack_top = None

Expand Down Expand Up @@ -6372,7 +6378,7 @@ def IsBlockInNameSpace(nesting_state, is_forward_declaration):
return False


def ShouldCheckNamespaceIndentation(nesting_state, is_namespace_indent_item,
def ShouldCheckNamespaceIndentation(nesting_state: NestingState, is_namespace_indent_item,
raw_lines_no_comments, linenum):
"""This method determines if we should apply our namespace indentation check.

Expand All @@ -6399,6 +6405,10 @@ def ShouldCheckNamespaceIndentation(nesting_state, is_namespace_indent_item,
if IsMacroDefinition(raw_lines_no_comments, linenum):
return False

# Skip if we are inside an open parenthesis block (e.g. function parameters).
if nesting_state.previous_stack_top and nesting_state.previous_open_parentheses > 0:
return False

return IsBlockInNameSpace(nesting_state, is_forward_declaration)


Expand Down
5 changes: 3 additions & 2 deletions cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,10 @@ def testNamespaceIndentationForClass(self):
'Do not indent within a namespace. '
' [whitespace/indent_namespace] [4]'])

def testNamespaceIndentationNoError(self):
def testNamespaceIndentationIndentedParameter(self):
lines = ['namespace Test {',
'void foo() { }',
'void foo('
' SuperLongTypeName d = 418) { }',
'} // namespace Test']

results = self.GetNamespaceResults(lines)
Expand Down
7 changes: 1 addition & 6 deletions samples/boost-sample/exclude.def
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
4
Done processing src/inspect/unnamed_namespace_check.hpp
Done processing src/tr1/c_policy.hpp
Total errors found: 126
Total errors found: 121

src/inspect/unnamed_namespace_check.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_INSPECT_UNNAMED_NAMESPACE_CHECK_HPP_ [build/header_guard] [5]
src/inspect/unnamed_namespace_check.hpp:11: Include the directory when naming header files [build/include_subdir] [4]
src/inspect/unnamed_namespace_check.hpp:14: Do not use unnamed namespaces in header files. See https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces for more information. [build/namespaces_headers] [4]
src/inspect/unnamed_namespace_check.hpp:17: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:18: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:18: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:19: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:19: Closing ) should be moved to the previous line [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:21: Anonymous namespace should be terminated with "// namespace" [readability/namespace] [5]
src/inspect/unnamed_namespace_check.hpp:21: At least two spaces is best between code and comments [whitespace/comments] [2]
Expand Down Expand Up @@ -44,9 +42,6 @@ src/inspect/unnamed_namespace_check.hpp:38: Do not indent within a namespace.
src/inspect/unnamed_namespace_check.hpp:38: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:40: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:40: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:41: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:42: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:43: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:44: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:44: { should almost always be at the end of the previous line [whitespace/braces] [4]
src/inspect/unnamed_namespace_check.hpp:48: Lines should be <= 80 characters long [whitespace/line_length] [2]
Expand Down
7 changes: 1 addition & 6 deletions samples/boost-sample/headers_inspect.def
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ src/inspect/*
1
3
Done processing src/inspect/unnamed_namespace_check.hpp
Total errors found: 55
Total errors found: 50

src/inspect/unnamed_namespace_check.hpp:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_BOOST_SAMPLE_SRC_INSPECT_UNNAMED_NAMESPACE_CHECK_HPP_ [build/header_guard] [5]
src/inspect/unnamed_namespace_check.hpp:11: Include the directory when naming header files [build/include_subdir] [4]
src/inspect/unnamed_namespace_check.hpp:14: Do not use unnamed namespaces in header files. See https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Namespaces for more information. [build/namespaces_headers] [4]
src/inspect/unnamed_namespace_check.hpp:17: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:18: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:18: At least two spaces is best between code and comments [whitespace/comments] [2]
src/inspect/unnamed_namespace_check.hpp:19: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:19: Closing ) should be moved to the previous line [whitespace/parens] [2]
src/inspect/unnamed_namespace_check.hpp:21: Anonymous namespace should be terminated with "// namespace" [readability/namespace] [5]
src/inspect/unnamed_namespace_check.hpp:21: At least two spaces is best between code and comments [whitespace/comments] [2]
Expand Down Expand Up @@ -43,9 +41,6 @@ src/inspect/unnamed_namespace_check.hpp:38: Do not indent within a namespace.
src/inspect/unnamed_namespace_check.hpp:38: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:40: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:40: Weird number of spaces at line-start. Are you using a 2-space indent? [whitespace/indent] [3]
src/inspect/unnamed_namespace_check.hpp:41: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:42: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:43: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:44: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/inspect/unnamed_namespace_check.hpp:44: { should almost always be at the end of the previous line [whitespace/braces] [4]
src/inspect/unnamed_namespace_check.hpp:48: Lines should be <= 80 characters long [whitespace/line_length] [2]
Expand Down
26 changes: 1 addition & 25 deletions samples/boost-sample/simple.def
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include/boost/math/*
1
3
Done processing include/boost/math/octonion.hpp
Total errors found: 2924
Total errors found: 2900

include/boost/math/octonion.hpp:11: #ifndef header guard has wrong style, please use: SAMPLES_BOOST_SAMPLE_INCLUDE_BOOST_MATH_OCTONION_HPP_ [build/header_guard] [5]
include/boost/math/octonion.hpp:4250: #endif line should be "#endif // SAMPLES_BOOST_SAMPLE_INCLUDE_BOOST_MATH_OCTONION_HPP_" [build/header_guard] [5]
Expand Down Expand Up @@ -1167,7 +1167,6 @@ include/boost/math/octonion.hpp:1711: Do not indent within a namespace. [white
include/boost/math/octonion.hpp:1711: Lines should be <= 80 characters long [whitespace/line_length] [2]
include/boost/math/octonion.hpp:1711: Missing space after , [whitespace/comma] [3]
include/boost/math/octonion.hpp:1711: Extra space after ( [whitespace/parens] [2]
include/boost/math/octonion.hpp:1712: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:1713: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:1713: { should almost always be at the end of the previous line [whitespace/braces] [4]
include/boost/math/octonion.hpp:1716: Lines should be <= 80 characters long [whitespace/line_length] [2]
Expand Down Expand Up @@ -2616,7 +2615,6 @@ include/boost/math/octonion.hpp:3856: Do not indent within a namespace. [white
include/boost/math/octonion.hpp:3856: Lines should be <= 80 characters long [whitespace/line_length] [2]
include/boost/math/octonion.hpp:3856: Missing space after , [whitespace/comma] [3]
include/boost/math/octonion.hpp:3856: Extra space after ( [whitespace/parens] [2]
include/boost/math/octonion.hpp:3857: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:3857: Lines should be <= 80 characters long [whitespace/line_length] [2]
include/boost/math/octonion.hpp:3858: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:3858: { should almost always be at the end of the previous line [whitespace/braces] [4]
Expand Down Expand Up @@ -2728,13 +2726,6 @@ include/boost/math/octonion.hpp:3999: Do not indent within a namespace. [white
include/boost/math/octonion.hpp:3999: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
include/boost/math/octonion.hpp:4000: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4001: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4002: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4003: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4004: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4005: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4006: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4007: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4008: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4009: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4009: { should almost always be at the end of the previous line [whitespace/braces] [4]
include/boost/math/octonion.hpp:4012: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
Expand Down Expand Up @@ -2772,13 +2763,6 @@ include/boost/math/octonion.hpp:4054: Do not indent within a namespace. [white
include/boost/math/octonion.hpp:4054: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
include/boost/math/octonion.hpp:4055: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4056: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4057: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4058: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4059: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4060: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4061: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4062: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4063: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4064: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4064: { should almost always be at the end of the previous line [whitespace/braces] [4]
include/boost/math/octonion.hpp:4067: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
Expand All @@ -2791,13 +2775,6 @@ include/boost/math/octonion.hpp:4080: Do not indent within a namespace. [white
include/boost/math/octonion.hpp:4080: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
include/boost/math/octonion.hpp:4081: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4082: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4083: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4084: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4085: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4086: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4087: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4088: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4089: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4090: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4090: { should almost always be at the end of the previous line [whitespace/braces] [4]
include/boost/math/octonion.hpp:4093: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
Expand Down Expand Up @@ -2886,7 +2863,6 @@ include/boost/math/octonion.hpp:4192: Do not indent within a namespace. [white
include/boost/math/octonion.hpp:4192: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4]
include/boost/math/octonion.hpp:4193: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4194: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4195: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4196: Do not indent within a namespace. [whitespace/indent_namespace] [4]
include/boost/math/octonion.hpp:4196: { should almost always be at the end of the previous line [whitespace/braces] [4]
include/boost/math/octonion.hpp:4198: { should almost always be at the end of the previous line [whitespace/braces] [4]
Expand Down
9 changes: 1 addition & 8 deletions samples/chromium-sample/simple.def
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ Done processing src/chrome_content_renderer_client.cc
Done processing src/chrome_content_renderer_client.h
Done processing src/io_thread.cc
Done processing src/io_thread.h
Total errors found: 25
Total errors found: 18

src/chrome_content_renderer_client.cc:303: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/chrome_content_renderer_client.cc:308: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/chrome_content_renderer_client.cc:309: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/chrome_content_renderer_client.cc:310: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/chrome_content_renderer_client.cc:308: Add #include <vector> for vector<> [build/include_what_you_use] [4]
src/chrome_content_renderer_client.cc:1540: Add #include <set> for set<> [build/include_what_you_use] [4]
src/chrome_content_renderer_client.cc:1841: Add #include <string> for string [build/include_what_you_use] [4]
Expand All @@ -19,10 +16,6 @@ src/chrome_content_renderer_client.h:5: #ifndef header guard has wrong style, p
src/chrome_content_renderer_client.h:225: #endif line should be "#endif // SAMPLES_CHROMIUM_SAMPLE_SRC_CHROME_CONTENT_RENDERER_CLIENT_H_" [build/header_guard] [5]
src/chrome_content_renderer_client.h:115: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4]
src/chrome_content_renderer_client.h:117: Use int16_t/int64_t/etc, rather than the C type long [runtime/int] [4]
src/io_thread.cc:242: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/io_thread.cc:286: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/io_thread.cc:298: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/io_thread.cc:299: Do not indent within a namespace. [whitespace/indent_namespace] [4]
src/io_thread.cc:1148: Closing ) should be moved to the previous line [whitespace/parens] [2]
src/io_thread.cc:1547: Missing space around colon in range-based for loop [whitespace/forcolon] [2]
src/io_thread.cc:651: Add #include <map> for map<> [build/include_what_you_use] [4]
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy