You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ti...@apache.org on 2018/10/05 18:00:37 UTC
[mesos] 02/02: Updated cpplint.py to be less verbose when there is
no linting issue.
This is an automated email from the ASF dual-hosted git repository.
tillt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
commit c0f8f56d5a93f3fb870e448fedfd22f1491356ca
Author: Armand Grillet <ag...@mesosphere.io>
AuthorDate: Fri Oct 5 20:00:24 2018 +0200
Updated cpplint.py to be less verbose when there is no linting issue.
Review: https://reviews.apache.org/r/68939/
---
support/cpplint.patch | 111 +++++++++++++++++++++++++-------------------------
support/cpplint.py | 6 ++-
2 files changed, 60 insertions(+), 57 deletions(-)
diff --git a/support/cpplint.patch b/support/cpplint.patch
index 30778d9..2427be8 100644
--- a/support/cpplint.patch
+++ b/support/cpplint.patch
@@ -1,8 +1,8 @@
diff --git a/support/cpplint.py b/support/cpplint.py
-index 6d44d3165..5089d50a9 100644
+index 6d44d3165..b8b3b1a14 100644
--- a/support/cpplint.py
+++ b/support/cpplint.py
-@@ -28,6 +28,12 @@
+@@ -28,6 +28,13 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -10,12 +10,13 @@ index 6d44d3165..5089d50a9 100644
+# Modified by Avinash S (avinash@mesosphere.io) to check for at least
+# a __single__ space in comments is required for hpp and cpp files.
+# Modified by Tomek J (janiszt@gmail.com) to check for NULL usage.
-+# Modified by Armand G (agrillet@mesosphere.io) to skip file when linted.
++# Modified by Armand G (agrillet@mesosphere.io) to skip file when linted
++# and to not print anything if there is no error.
+
"""Does google-lint on c++ files.
The goal of this script is to identify places in the code that *may*
-@@ -40,6 +46,7 @@ In particular, we can get very confused by /* and // inside strings!
+@@ -40,6 +47,7 @@ In particular, we can get very confused by /* and // inside strings!
We do a small hack, which is to ignore //'s with "'s after them on the
same line, but it is far from perfect (in either direction).
"""
@@ -23,7 +24,32 @@ index 6d44d3165..5089d50a9 100644
import codecs
import copy
-@@ -216,6 +223,7 @@ _ERROR_CATEGORIES = [
+@@ -57,6 +65,24 @@ try:
+ xrange # Python 2
+ except NameError:
+ xrange = range # Python 3
++ unicode = str
++ def iteritems(d):
++ return d.items()
++ def itervalues(d):
++ return d.values()
++else:
++ # Python 2
++ def iteritems(d):
++ return d.iteritems()
++ def itervalues(d):
++ return d.itervalues()
++ # Change stderr to write with replacement characters so we don't die
++ # if we try to print something containing non-ASCII characters.
++ sys.stderr = codecs.StreamReaderWriter(sys.stderr,
++ codecs.getreader('utf8'),
++ codecs.getwriter('utf8'),
++ 'replace')
++
+
+
+ _USAGE = """
+@@ -216,6 +242,7 @@ _ERROR_CATEGORIES = [
'build/include_order',
'build/include_what_you_use',
'build/namespaces',
@@ -31,7 +57,7 @@ index 6d44d3165..5089d50a9 100644
'build/printf_format',
'build/storage_class',
'legal/copyright',
-@@ -558,7 +566,7 @@ _line_length = 80
+@@ -558,7 +585,7 @@ _line_length = 80
# The allowed extensions for file names
# This is set by --extensions flag.
@@ -40,7 +66,21 @@ index 6d44d3165..5089d50a9 100644
# Treat all headers starting with 'h' equally: .h, .hpp, .hxx etc.
# This is set by --headers flag.
-@@ -2370,14 +2378,14 @@ class _NamespaceInfo(_BlockInfo):
+@@ -952,10 +979,11 @@ class _CppLintState(object):
+
+ def PrintErrorCounts(self):
+ """Print a summary of errors by category, and the total."""
+- for category, count in self.errors_by_category.iteritems():
++ for category, count in iteritems(self.errors_by_category):
+ sys.stderr.write('Category \'%s\' errors found: %d\n' %
+ (category, count))
+- sys.stdout.write('Total errors found: %d\n' % self.error_count)
++ if self.error_count > 0:
++ sys.stdout.write('Total errors found: %d\n' % self.error_count)
+
+ _cpplint_state = _CppLintState()
+
+@@ -2370,14 +2398,14 @@ class _NamespaceInfo(_BlockInfo):
if self.name:
# Named namespace
if not Match((r'^\s*};*\s*(//|/\*).*\bnamespace\s+' +
@@ -58,7 +98,7 @@ index 6d44d3165..5089d50a9 100644
# If "// namespace anonymous" or "// anonymous namespace (more text)",
# mention "// anonymous namespace" as an acceptable form
if Match(r'^\s*}.*\b(namespace anonymous|anonymous namespace)\b', line):
-@@ -2386,7 +2394,7 @@ class _NamespaceInfo(_BlockInfo):
+@@ -2386,7 +2414,7 @@ class _NamespaceInfo(_BlockInfo):
' or "// anonymous namespace"')
else:
error(filename, linenum, 'readability/namespace', 5,
@@ -67,7 +107,7 @@ index 6d44d3165..5089d50a9 100644
class _PreprocessorInfo(object):
-@@ -2688,11 +2696,9 @@ class NestingState(object):
+@@ -2688,11 +2716,9 @@ class NestingState(object):
if access_match:
classinfo.access = access_match.group(2)
@@ -81,7 +121,7 @@ index 6d44d3165..5089d50a9 100644
if classinfo.is_struct:
parent = 'struct ' + classinfo.name
else:
-@@ -2701,7 +2707,7 @@ class NestingState(object):
+@@ -2701,7 +2727,7 @@ class NestingState(object):
if access_match.group(3):
slots = access_match.group(3)
error(filename, linenum, 'whitespace/indent', 3,
@@ -90,7 +130,7 @@ index 6d44d3165..5089d50a9 100644
access_match.group(2), slots, parent))
# Consume braces or semicolons from what's left of the line
-@@ -3129,13 +3135,10 @@ def CheckComment(line, filename, linenum, next_line_start, error):
+@@ -3129,13 +3155,10 @@ def CheckComment(line, filename, linenum, next_line_start, error):
# Check if the // may be in quotes. If so, ignore it
if re.sub(r'\\.', '', line[0:commentpos]).count('"') % 2 == 0:
# Allow one space for new scopes, two spaces otherwise:
@@ -107,7 +147,7 @@ index 6d44d3165..5089d50a9 100644
# Checks for common mistakes in TODO comments.
comment = line[commentpos:]
-@@ -3383,7 +3386,7 @@ def CheckOperatorSpacing(filename, clean_lines, linenum, error):
+@@ -3383,7 +3406,7 @@ def CheckOperatorSpacing(filename, clean_lines, linenum, error):
# those tend to be macros that deal with operators.
match = Search(r'(operator|[^\s(<])(?:L|UL|LL|ULL|l|ul|ll|ull)?<<([^\s,=<])', line)
if (match and not (match.group(1).isdigit() and match.group(2).isdigit()) and
@@ -116,7 +156,7 @@ index 6d44d3165..5089d50a9 100644
error(filename, linenum, 'whitespace/operators', 3,
'Missing spaces around <<')
-@@ -4410,6 +4413,10 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
+@@ -4410,6 +4433,10 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
error(filename, linenum, 'whitespace/newline', 0,
'More than one command on the same line')
@@ -127,46 +167,7 @@ index 6d44d3165..5089d50a9 100644
# Some more style checks
CheckBraces(filename, clean_lines, linenum, error)
CheckTrailingSemicolon(filename, clean_lines, linenum, error)
-
-diff --git a/support/cpplint.py b/support/cpplint.py
-index 42a3dda20..c5a45f760 100644
---- a/support/cpplint.py
-+++ b/support/cpplint.py
-@@ -64,6 +64,24 @@ try:
- xrange # Python 2
- except NameError:
- xrange = range # Python 3
-+ unicode = str
-+ def iteritems(d):
-+ return d.items()
-+ def itervalues(d):
-+ return d.values()
-+else:
-+ # Python 2
-+ def iteritems(d):
-+ return d.iteritems()
-+ def itervalues(d):
-+ return d.itervalues()
-+ # Change stderr to write with replacement characters so we don't die
-+ # if we try to print something containing non-ASCII characters.
-+ sys.stderr = codecs.StreamReaderWriter(sys.stderr,
-+ codecs.getreader('utf8'),
-+ codecs.getwriter('utf8'),
-+ 'replace')
-+
-
-
- _USAGE = """
-@@ -960,7 +978,7 @@ class _CppLintState(object):
-
- def PrintErrorCounts(self):
- """Print a summary of errors by category, and the total."""
-- for category, count in self.errors_by_category.iteritems():
-+ for category, count in iteritems(self.errors_by_category):
- sys.stderr.write('Category \'%s\' errors found: %d\n' %
- (category, count))
- sys.stdout.write('Total errors found: %d\n' % self.error_count)
-@@ -4629,7 +4647,7 @@ def _GetTextInside(text, start_pattern):
+@@ -4622,7 +4649,7 @@ def _GetTextInside(text, start_pattern):
# Give opening punctuations to get the matching close-punctuations.
matching_punctuation = {'(': ')', '{': '}', '[': ']'}
@@ -175,7 +176,7 @@ index 42a3dda20..c5a45f760 100644
# Find the position to start extracting text.
match = re.search(start_pattern, text, re.M)
-@@ -5577,7 +5595,7 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
+@@ -5570,7 +5597,7 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
# include_dict is modified during iteration, so we iterate over a copy of
# the keys.
@@ -184,7 +185,7 @@ index 42a3dda20..c5a45f760 100644
for header in header_keys:
(same_module, common_path) = FilesBelongToSameModule(abs_filename, header)
fullpath = common_path + header
-@@ -6230,13 +6248,6 @@ def ParseArguments(args):
+@@ -6223,13 +6250,6 @@ def ParseArguments(args):
def main():
filenames = ParseArguments(sys.argv[1:])
diff --git a/support/cpplint.py b/support/cpplint.py
index c5a45f7..b8b3b1a 100644
--- a/support/cpplint.py
+++ b/support/cpplint.py
@@ -32,7 +32,8 @@
# Modified by Avinash S (avinash@mesosphere.io) to check for at least
# a __single__ space in comments is required for hpp and cpp files.
# Modified by Tomek J (janiszt@gmail.com) to check for NULL usage.
-# Modified by Armand G (agrillet@mesosphere.io) to skip file when linted.
+# Modified by Armand G (agrillet@mesosphere.io) to skip file when linted
+# and to not print anything if there is no error.
"""Does google-lint on c++ files.
@@ -981,7 +982,8 @@ class _CppLintState(object):
for category, count in iteritems(self.errors_by_category):
sys.stderr.write('Category \'%s\' errors found: %d\n' %
(category, count))
- sys.stdout.write('Total errors found: %d\n' % self.error_count)
+ if self.error_count > 0:
+ sys.stdout.write('Total errors found: %d\n' % self.error_count)
_cpplint_state = _CppLintState()