From f2ced939ebbe0fb491f0d306f01b7353c6896bd8 Mon Sep 17 00:00:00 2001 From: Piotr Semenov Date: Fri, 20 May 2016 18:39:34 +0300 Subject: [PATCH 1/3] [FIX] Bug: NOLINT, NOLINTNEXTLINE has no effect if used for the closing-brace line "};" in the lambda declaration. --- cpplint/cpplint.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 94913206f..079f61d57 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -3884,6 +3884,14 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error): # outputting warnings for the matching closing brace, if there are # nested blocks with trailing semicolons, we will get the error # messages in reversed order. + + # We need to check the line forward for NOLINT + raw_lines = clean_lines.raw_lines + ParseNolintSuppressions(filename, raw_lines[endlinenum-1], endlinenum-1, + error) + ParseNolintSuppressions(filename, raw_lines[endlinenum], endlinenum, + error) + error(filename, endlinenum, 'readability/braces', 4, "You don't need a ; after a }") From b7e2ef6de289468b1e767fdbb10ecd92ba06f895 Mon Sep 17 00:00:00 2001 From: Piotr Semenov Date: Fri, 20 May 2016 18:39:34 +0300 Subject: [PATCH 2/3] [FIX] Bug: NOLINT, NOLINTNEXTLINE has no effect for "};". --- cpplint/cpplint.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cpplint/cpplint.py b/cpplint/cpplint.py index 94913206f..079f61d57 100755 --- a/cpplint/cpplint.py +++ b/cpplint/cpplint.py @@ -3884,6 +3884,14 @@ def CheckTrailingSemicolon(filename, clean_lines, linenum, error): # outputting warnings for the matching closing brace, if there are # nested blocks with trailing semicolons, we will get the error # messages in reversed order. + + # We need to check the line forward for NOLINT + raw_lines = clean_lines.raw_lines + ParseNolintSuppressions(filename, raw_lines[endlinenum-1], endlinenum-1, + error) + ParseNolintSuppressions(filename, raw_lines[endlinenum], endlinenum, + error) + error(filename, endlinenum, 'readability/braces', 4, "You don't need a ; after a }") From a3c36d93d236c8c4c1d8263e99edf70d24a043f4 Mon Sep 17 00:00:00 2001 From: Piotr Semenov Date: Thu, 30 Jun 2016 11:45:37 +0300 Subject: [PATCH 3/3] [FEATURE] Adds the unit-test for case "NOLINT, NOLINTNEXTLINE works for };". --- cpplint/cpplint_unittest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cpplint/cpplint_unittest.py b/cpplint/cpplint_unittest.py index fd059fb01..07a443f61 100755 --- a/cpplint/cpplint_unittest.py +++ b/cpplint/cpplint_unittest.py @@ -521,6 +521,21 @@ def testErrorSuppression(self): ''], error_collector) self.assertEquals('', error_collector.Results()) + # NOLINT, NOLINTNEXTLINE silences the readability/braces warning for "};". + error_collector = ErrorCollector(self.assert_) + cpplint.ProcessFileData('test.cc', 'cc', + ['// Copyright 2014 Your Company.', + 'for (int i = 0; i != 100; ++i) {', + '\tstd::cout << i << std::endl;', + '}; // NOLINT', + 'for (int i = 0; i != 100; ++i) {', + '\tstd::cout << i << std::endl;', + '// NOLINTNEXTLINE', + '};', + '// LINT_KERNEL_FILE', + ''], + error_collector) + self.assertEquals('', error_collector.Results()) # Test Variable Declarations. def testVariableDeclarations(self):