Revert "Revert "Fix the cpplint.py build/endif_comment check.""

This reverts commit ae11811f81.

As described in pull request 169, users should chose to enable or
disable this check using `build/endif_comment`. As the code is, that
check is never exercised.
This commit is contained in:
Alexandre Rames 2016-10-12 16:39:51 +01:00 committed by Alexandre Rames
parent 71ec7f1e52
commit 3f5a86f426
2 changed files with 30 additions and 8 deletions

9
cpplint/cpplint.py vendored
View File

@ -2710,6 +2710,11 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum,
filename, line number, error level, and message 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. # Remove comments from the line, but leave in strings for now.
line = clean_lines.lines[linenum] line = clean_lines.lines[linenum]
@ -2740,10 +2745,6 @@ def CheckForNonStandardConstructs(filename, clean_lines, linenum,
'Storage-class specifier (static, extern, typedef, etc) should be ' 'Storage-class specifier (static, extern, typedef, etc) should be '
'at the beginning of the declaration.') '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): if Match(r'\s*class\s+(\w+\s*::\s*)+\w+\s*;', line):
error(filename, linenum, 'build/forward_decl', 5, error(filename, linenum, 'build/forward_decl', 5,
'Inner-style forward declarations are invalid. Remove this line.') 'Inner-style forward declarations are invalid. Remove this line.')

View File

@ -3754,7 +3754,7 @@ class CpplintTest(CpplintTestBase):
#else #else
baz; baz;
qux; qux;
#endif""", #endif // foo""",
'') '')
self.TestMultiLineLint( self.TestMultiLineLint(
"""void F() { """void F() {
@ -3920,7 +3920,7 @@ class CpplintTest(CpplintTestBase):
'#include "path/unique.h"', '#include "path/unique.h"',
'#else', '#else',
'#include "path/unique.h"', '#include "path/unique.h"',
'#endif', '#endif // MACRO',
''], ''],
error_collector) error_collector)
self.assertEquals( self.assertEquals(
@ -3969,7 +3969,7 @@ class CpplintTest(CpplintTestBase):
struct Foo : public Goo { struct Foo : public Goo {
#else #else
struct Foo : public Hoo { struct Foo : public Hoo {
#endif #endif // DERIVE_FROM_GOO
};""", };""",
'') '')
self.TestMultiLineLint( self.TestMultiLineLint(
@ -3979,7 +3979,7 @@ class CpplintTest(CpplintTestBase):
: public Goo { : public Goo {
#else #else
: public Hoo { : public Hoo {
#endif #endif // DERIVE_FROM_GOO
};""", };""",
'') '')
# Test incomplete class # Test incomplete class
@ -3997,6 +3997,27 @@ class CpplintTest(CpplintTestBase):
'Uncommented text after #endif is non-standard. Use a comment.' 'Uncommented text after #endif is non-standard. Use a comment.'
' [build/endif_comment] [5]') ' [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): def testBuildForwardDecl(self):
# The crosstool compiler we currently use will fail to compile the # The crosstool compiler we currently use will fail to compile the
# code in this test, so we might consider removing the lint check. # code in this test, so we might consider removing the lint check.