Skip to content

Commit 1342002

Browse files
authored
Merge pull request google#169 from arames/gh-pages
Fix the `cpplint.py` `build/endif_comment` check.
2 parents 6d3a7d8 + f558944 commit 1342002

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

cpplint/cpplint.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2683,6 +2683,11 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum,
26832683
filename, line number, error level, and message
26842684
"""
26852685

2686+
line = clean_lines.lines_without_raw_strings[linenum]
2687+
if Match(r'\s*#\s*endif\s*([^/\s]|/[^/]|$)', line):
2688+
error(filename, linenum, 'build/endif_comment', 5,
2689+
'Uncommented text after #endif is non-standard. Use a comment.')
2690+
26862691
# Remove comments from the line, but leave in strings for now.
26872692
line = clean_lines.lines[linenum]
26882693

@@ -2713,10 +2718,6 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum,
27132718
'Storage-class specifier (static, extern, typedef, etc) should be '
27142719
'at the beginning of the declaration.')
27152720

2716-
if Match(r'\s*#\s*endif\s*[^/\s]+', line):
2717-
error(filename, linenum, 'build/endif_comment', 5,
2718-
'Uncommented text after #endif is non-standard. Use a comment.')
2719-
27202721
if Match(r'\s*class\s+(\w+\s*::\s*)+\w+\s*;', line):
27212722
error(filename, linenum, 'build/forward_decl', 5,
27222723
'Inner-style forward declarations are invalid. Remove this line.')

cpplint/cpplint_unittest.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3754,7 +3754,7 @@ def testConditionals(self):
37543754
#else
37553755
baz;
37563756
qux;
3757-
#endif""",
3757+
#endif // foo""",
37583758
'')
37593759
self.TestMultiLineLint(
37603760
"""void F() {
@@ -3910,7 +3910,7 @@ def testDuplicateHeader(self):
39103910
'#include "path/unique.h"',
39113911
'#else',
39123912
'#include "path/unique.h"',
3913-
'#endif',
3913+
'#endif // MACRO',
39143914
''],
39153915
error_collector)
39163916
self.assertEquals(
@@ -3959,7 +3959,7 @@ def testBuildClass(self):
39593959
struct Foo : public Goo {
39603960
#else
39613961
struct Foo : public Hoo {
3962-
#endif
3962+
#endif // DERIVE_FROM_GOO
39633963
};""",
39643964
'')
39653965
self.TestMultiLineLint(
@@ -3969,7 +3969,7 @@ class Foo
39693969
: public Goo {
39703970
#else
39713971
: public Hoo {
3972-
#endif
3972+
#endif // DERIVE_FROM_GOO
39733973
};""",
39743974
'')
39753975
# Test incomplete class
@@ -3987,6 +3987,27 @@ def testBuildEndComment(self):
39873987
'Uncommented text after #endif is non-standard. Use a comment.'
39883988
' [build/endif_comment] [5]')
39893989

3990+
correct_lines = [
3991+
'#endif // text',
3992+
'#endif //'
3993+
]
3994+
3995+
for line in correct_lines:
3996+
self.TestLint(line, '')
3997+
3998+
incorrect_lines = [
3999+
'#endif',
4000+
'#endif Not a comment',
4001+
'#endif / One `/` is not enough to start a comment'
4002+
]
4003+
4004+
for line in incorrect_lines:
4005+
self.TestLint(
4006+
line,
4007+
'Uncommented text after #endif is non-standard. Use a comment.'
4008+
' [build/endif_comment] [5]')
4009+
4010+
39904011
def testBuildForwardDecl(self):
39914012
# The crosstool compiler we currently use will fail to compile the
39924013
# code in this test, so we might consider removing the lint check.

0 commit comments

Comments
 (0)