Skip to content

Commit

Permalink
Merge pull request google#169 from arames/gh-pages
Browse files Browse the repository at this point in the history
Fix the `cpplint.py` `build/endif_comment` check.
  • Loading branch information
eglaysher authored Sep 21, 2016
2 parents 6d3a7d8 + f558944 commit 1342002
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
9 changes: 5 additions & 4 deletions cpplint/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,11 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum,
filename, line number, error level, and message
"""

line = clean_lines.lines_without_raw_strings[linenum]
if Match(r'\s*#\s*endif\s*([^/\s]|/[^/]|$)', line):
error(filename, linenum, 'build/endif_comment', 5,
'Uncommented text after #endif is non-standard. Use a comment.')

# Remove comments from the line, but leave in strings for now.
line = clean_lines.lines[linenum]

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

if Match(r'\s*#\s*endif\s*[^/\s]+', line):
error(filename, linenum, 'build/endif_comment', 5,
'Uncommented text after #endif is non-standard. Use a comment.')

if Match(r'\s*class\s+(\w+\s*::\s*)+\w+\s*;', line):
error(filename, linenum, 'build/forward_decl', 5,
'Inner-style forward declarations are invalid. Remove this line.')
Expand Down
29 changes: 25 additions & 4 deletions cpplint/cpplint_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,7 @@ def testConditionals(self):
#else
baz;
qux;
#endif""",
#endif // foo""",
'')
self.TestMultiLineLint(
"""void F() {
Expand Down Expand Up @@ -3910,7 +3910,7 @@ def testDuplicateHeader(self):
'#include "path/unique.h"',
'#else',
'#include "path/unique.h"',
'#endif',
'#endif // MACRO',
''],
error_collector)
self.assertEquals(
Expand Down Expand Up @@ -3959,7 +3959,7 @@ def testBuildClass(self):
struct Foo : public Goo {
#else
struct Foo : public Hoo {
#endif
#endif // DERIVE_FROM_GOO
};""",
'')
self.TestMultiLineLint(
Expand All @@ -3969,7 +3969,7 @@ class Foo
: public Goo {
#else
: public Hoo {
#endif
#endif // DERIVE_FROM_GOO
};""",
'')
# Test incomplete class
Expand All @@ -3987,6 +3987,27 @@ def testBuildEndComment(self):
'Uncommented text after #endif is non-standard. Use a comment.'
' [build/endif_comment] [5]')

correct_lines = [
'#endif // text',
'#endif //'
]

for line in correct_lines:
self.TestLint(line, '')

incorrect_lines = [
'#endif',
'#endif Not a comment',
'#endif / One `/` is not enough to start a comment'
]

for line in incorrect_lines:
self.TestLint(
line,
'Uncommented text after #endif is non-standard. Use a comment.'
' [build/endif_comment] [5]')


def testBuildForwardDecl(self):
# The crosstool compiler we currently use will fail to compile the
# code in this test, so we might consider removing the lint check.
Expand Down

0 comments on commit 1342002

Please sign in to comment.