From dc28970e18c72f39d1c465c72c372cb5b39ebc45 Mon Sep 17 00:00:00 2001 From: "erg@google.com" Date: Thu, 26 Jan 2012 20:30:03 +0000 Subject: [PATCH] Improve the error message for when #ifndef guards don't match the #define. Patch from --- cpplint/cpplint.py | 14 +++++++++++++- cpplint/cpplint_unittest.py | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 016116b..c985c5d 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -1071,12 +1071,18 @@ def CheckForHeaderGuard(filename, lines, error): endif = line endif_linenum = linenum - if not ifndef or not define or ifndef != define: + if not ifndef: error(filename, 0, 'build/header_guard', 5, 'No #ifndef header guard found, suggested CPP variable is: %s' % cppvar) 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__ # for backward compatibility. if ifndef != cppvar: @@ -1089,6 +1095,12 @@ def CheckForHeaderGuard(filename, lines, error): error(filename, ifndef_linenum, 'build/header_guard', error_level, '#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): error_level = 0 if endif != ('#endif // %s' % (cppvar + '_')): diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index 9903bc9..361629a 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -2054,7 +2054,7 @@ class CpplintTest(CpplintTestBase): self.assertEquals( 1, 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), error_collector.ResultList()) @@ -2067,7 +2067,7 @@ class CpplintTest(CpplintTestBase): self.assertEquals( 1, 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), error_collector.ResultList())