mirror of
https://github.com/google/styleguide.git
synced 2024-03-22 13:11:43 +08:00
Improve the error message for when #ifndef guards don't match the #define.
Patch from <csharp@google.com>
This commit is contained in:
parent
3dc7426aed
commit
dc28970e18
14
cpplint/cpplint.py
vendored
14
cpplint/cpplint.py
vendored
|
@ -1071,12 +1071,18 @@ def CheckForHeaderGuard(filename, lines, error):
|
||||||
endif = line
|
endif = line
|
||||||
endif_linenum = linenum
|
endif_linenum = linenum
|
||||||
|
|
||||||
if not ifndef or not define or ifndef != define:
|
if not ifndef:
|
||||||
error(filename, 0, 'build/header_guard', 5,
|
error(filename, 0, 'build/header_guard', 5,
|
||||||
'No #ifndef header guard found, suggested CPP variable is: %s' %
|
'No #ifndef header guard found, suggested CPP variable is: %s' %
|
||||||
cppvar)
|
cppvar)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not define:
|
||||||
|
error(filename, 0, 'build/header_guard', 5,
|
||||||
|
'No #define header guard found, suggested CPP variable is: %s' %
|
||||||
|
cppvar)
|
||||||
|
return
|
||||||
|
|
||||||
# The guard should be PATH_FILE_H_, but we also allow PATH_FILE_H__
|
# The guard should be PATH_FILE_H_, but we also allow PATH_FILE_H__
|
||||||
# for backward compatibility.
|
# for backward compatibility.
|
||||||
if ifndef != cppvar:
|
if ifndef != cppvar:
|
||||||
|
@ -1089,6 +1095,12 @@ def CheckForHeaderGuard(filename, lines, error):
|
||||||
error(filename, ifndef_linenum, 'build/header_guard', error_level,
|
error(filename, ifndef_linenum, 'build/header_guard', error_level,
|
||||||
'#ifndef header guard has wrong style, please use: %s' % cppvar)
|
'#ifndef header guard has wrong style, please use: %s' % cppvar)
|
||||||
|
|
||||||
|
if define != ifndef:
|
||||||
|
error(filename, 0, 'build/header_guard', 5,
|
||||||
|
'#ifndef and #define don\'t match, suggested CPP variable is: %s' %
|
||||||
|
cppvar)
|
||||||
|
return
|
||||||
|
|
||||||
if endif != ('#endif // %s' % cppvar):
|
if endif != ('#endif // %s' % cppvar):
|
||||||
error_level = 0
|
error_level = 0
|
||||||
if endif != ('#endif // %s' % (cppvar + '_')):
|
if endif != ('#endif // %s' % (cppvar + '_')):
|
||||||
|
|
|
@ -2054,7 +2054,7 @@ class CpplintTest(CpplintTestBase):
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
1,
|
1,
|
||||||
error_collector.ResultList().count(
|
error_collector.ResultList().count(
|
||||||
'No #ifndef header guard found, suggested CPP variable is: %s'
|
'No #define header guard found, suggested CPP variable is: %s'
|
||||||
' [build/header_guard] [5]' % expected_guard),
|
' [build/header_guard] [5]' % expected_guard),
|
||||||
error_collector.ResultList())
|
error_collector.ResultList())
|
||||||
|
|
||||||
|
@ -2067,7 +2067,7 @@ class CpplintTest(CpplintTestBase):
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
1,
|
1,
|
||||||
error_collector.ResultList().count(
|
error_collector.ResultList().count(
|
||||||
'No #ifndef header guard found, suggested CPP variable is: %s'
|
'#ifndef and #define don\'t match, suggested CPP variable is: %s'
|
||||||
' [build/header_guard] [5]' % expected_guard),
|
' [build/header_guard] [5]' % expected_guard),
|
||||||
error_collector.ResultList())
|
error_collector.ResultList())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user