From 9b9297936c4180e9526d078e9765c47b7a01d3e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Mon, 19 Oct 2015 09:44:54 +1100 Subject: [PATCH 01/11] break the linter --- lib/url.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/url.js b/lib/url.js index 45155fee936bbf..9c17a57b7f46b3 100644 --- a/lib/url.js +++ b/lib/url.js @@ -9,6 +9,7 @@ exports.format = urlFormat; exports.Url = Url; +// Here's a very long line we should ask linter about. Suggesting it won't be very pleased. function Url() { this.protocol = null; this.slashes = null; From e769c1bbc8a241dac154f8b68f4be139eaa58a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Mon, 19 Oct 2015 11:49:55 +1100 Subject: [PATCH 02/11] write tap outout from eslint --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 02619fac98ddd7..c244188f61256c 100644 --- a/Makefile +++ b/Makefile @@ -506,7 +506,7 @@ bench-idle: $(NODE) benchmark/idle_clients.js & jslint: - $(NODE) tools/eslint/bin/eslint.js src lib test tools/eslint-rules \ + $(NODE) tools/eslint/bin/eslint.js -f tap src lib test tools/eslint-rules \ --rulesdir tools/eslint-rules --reset --quiet CPPLINT_EXCLUDE ?= From f8a858b403964afbaae1ef94003e1789ec672e56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Mon, 19 Oct 2015 16:28:32 +1100 Subject: [PATCH 03/11] fix: write to file --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c244188f61256c..c02c2145562305 100644 --- a/Makefile +++ b/Makefile @@ -506,7 +506,7 @@ bench-idle: $(NODE) benchmark/idle_clients.js & jslint: - $(NODE) tools/eslint/bin/eslint.js -f tap src lib test tools/eslint-rules \ + $(NODE) tools/eslint/bin/eslint.js src lib test tools/eslint-rules \ --rulesdir tools/eslint-rules --reset --quiet CPPLINT_EXCLUDE ?= @@ -536,6 +536,10 @@ cpplint: lint: jslint cpplint +lint-ci: cpplint + $(NODE) tools/eslint/bin/eslint.js -f tap -o test.tap src lib test + tools/eslint-rules --rulesdir tools/eslint-rules --reset --quiet + .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \ check uninstall install install-includes install-bin all staticlib \ dynamiclib test test-all test-addons build-addons website-upload pkg \ From 3a0289827e9a157e09f0f7c335563181f49b8dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 12:16:15 +1100 Subject: [PATCH 04/11] make linters produce tap output --- .gitignore | 2 +- Makefile | 5 ++-- tools/cpplint.py | 59 +++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 18240c442e00cf..12598e03a8194f 100644 --- a/.gitignore +++ b/.gitignore @@ -82,7 +82,7 @@ deps/npm/node_modules/.bin/ # test artifacts tools/faketime icu_config.gypi -test.tap +test*.tap # Xcode workspaces and project folders *.xcodeproj diff --git a/Makefile b/Makefile index c02c2145562305..1b39ce0726df47 100644 --- a/Makefile +++ b/Makefile @@ -536,9 +536,10 @@ cpplint: lint: jslint cpplint -lint-ci: cpplint - $(NODE) tools/eslint/bin/eslint.js -f tap -o test.tap src lib test +lint-ci: + $(NODE) tools/eslint/bin/eslint.js -f tap -o test-eslint.tap src lib test \ tools/eslint-rules --rulesdir tools/eslint-rules --reset --quiet + $(PYTHON) tools/cpplint.py --output=tap --logfile=test-cpp.tap $(CPPLINT_FILES) .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \ check uninstall install install-includes install-bin all staticlib \ diff --git a/tools/cpplint.py b/tools/cpplint.py index 4c4f577b34c9d7..4b25b22b94d44b 100644 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -1,4 +1,4 @@ -#!/usr/bin/python2.4 +#!/usr/bin/env python # # Copyright (c) 2009 Google Inc. All rights reserved. # @@ -88,7 +88,8 @@ import string import sys import unicodedata - +import logging +logger = logging.getLogger('testrunner') _USAGE = """ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] @@ -139,6 +140,9 @@ the top-level categories like 'build' and 'whitespace' will also be printed. If 'detailed' is provided, then a count is provided for each category like 'build/class'. + + logfile=filename + Write TAP output to a logfile. """ # We categorize each error message we print. Here are the categories. @@ -541,6 +545,11 @@ def SetFilters(self, filters): raise ValueError('Every filter in --filters must start with + or -' ' (%s does not)' % filt) + def setOutputFile(self, filename): + """attempts to create a file which we write output to.""" + fh = logging.FileHandler(filename, mode='wb') + logger.addHandler(fh) + def ResetErrorCounts(self): """Sets the module's error statistic back to zero.""" self.error_count = 0 @@ -558,10 +567,11 @@ def IncrementErrorCount(self, category): def PrintErrorCounts(self): """Print a summary of errors by category, and the total.""" - for category, count in self.errors_by_category.iteritems(): - sys.stderr.write('Category \'%s\' errors found: %d\n' % - (category, count)) - sys.stderr.write('Total errors found: %d\n' % self.error_count) + if not _cpplint_state.output_format == 'tap': + for category, count in self.errors_by_category.iteritems(): + sys.stderr.write('Category \'%s\' errors found: %d\n' % + (category, count)) + sys.stderr.write('Total errors found: %d\n' % self.error_count) _cpplint_state = _CppLintState() @@ -608,6 +618,9 @@ def _SetFilters(filters): """ _cpplint_state.SetFilters(filters) +def _setOutputFile(filename): + _cpplint_state.setOutputFile(filename) + class _FunctionState(object): """Tracks current function name and the number of lines in its body.""" @@ -786,6 +799,15 @@ def Error(filename, linenum, category, confidence, message): if _cpplint_state.output_format == 'vs7': sys.stderr.write('%s(%s): %s [%s] [%d]\n' % ( filename, linenum, message, category, confidence)) + elif _cpplint_state.output_format == 'tap': + template = ("not ok %s\n" + " ---\n" + " message: %s\n" + " data:\n" + " line: %d\n" + " ruleId: %s\n" + " ...") + logger.info(template % (filename, message, linenum, category)) else: sys.stderr.write('%s:%s: %s [%s] [%d]\n' % ( filename, linenum, message, category, confidence)) @@ -2069,7 +2091,7 @@ def CheckStyle(filename, clean_lines, linenum, file_extension, error): initial_spaces += 1 if line and line[-1].isspace(): error(filename, linenum, 'whitespace/end_of_line', 4, - 'Line ends in whitespace. Consider deleting these extra spaces.') + 'Line ends in whitespace. Consider deleting these extra spaces.') # There are certain situations we allow one space, notably for labels elif ((initial_spaces == 1 or initial_spaces == 3) and not Match(r'\s*\w+\s*:\s*$', cleansed_line)): @@ -3002,7 +3024,8 @@ def ProcessFile(filename, vlevel): 'One or more unexpected \\r (^M) found;' 'better to use only a \\n') - sys.stderr.write('Done processing %s\n' % filename) + if not _cpplint_state.output_format == 'tap': + sys.stderr.write('Done processing %s\n' % filename) def PrintUsage(message): @@ -3041,7 +3064,8 @@ def ParseArguments(args): try: (opts, filenames) = getopt.getopt(args, '', ['help', 'output=', 'verbose=', 'counting=', - 'filter=']) + 'filter=', + 'logfile=']) except getopt.GetoptError: PrintUsage('Invalid arguments.') @@ -3049,13 +3073,14 @@ def ParseArguments(args): output_format = _OutputFormat() filters = '' counting_style = '' + output_filename = '' for (opt, val) in opts: if opt == '--help': PrintUsage(None) elif opt == '--output': - if not val in ('emacs', 'vs7'): - PrintUsage('The only allowed output formats are emacs and vs7.') + if not val in ('emacs', 'vs7', 'tap'): + PrintUsage('The only allowed output formats are emacs, vs7 and tap.') output_format = val elif opt == '--verbose': verbosity = int(val) @@ -3067,6 +3092,8 @@ def ParseArguments(args): if val not in ('total', 'toplevel', 'detailed'): PrintUsage('Valid counting options are total, toplevel, and detailed') counting_style = val + elif opt == '--logfile': + output_filename = val if not filenames: PrintUsage('No files were specified.') @@ -3075,6 +3102,8 @@ def ParseArguments(args): _SetVerboseLevel(verbosity) _SetFilters(filters) _SetCountingStyle(counting_style) + if output_filename: + _setOutputFile(output_filename) return filenames @@ -3089,6 +3118,14 @@ def main(): codecs.getwriter('utf8'), 'replace') + + ch = logging.StreamHandler(sys.stdout) + logger.addHandler(ch) + logger.setLevel(logging.INFO) + + if _cpplint_state.output_format == 'tap': + logger.info('TAP Version 13') + _cpplint_state.ResetErrorCounts() for filename in filenames: ProcessFile(filename, _cpplint_state.verbose_level) From 0eca04047e18eba9ed1d42529d4d5fb934cdcbf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 12:22:40 +1100 Subject: [PATCH 05/11] split up eslint/cpplint so both are always executed --- Makefile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1b39ce0726df47..9cb81b2d4380c3 100644 --- a/Makefile +++ b/Makefile @@ -536,14 +536,18 @@ cpplint: lint: jslint cpplint -lint-ci: - $(NODE) tools/eslint/bin/eslint.js -f tap -o test-eslint.tap src lib test \ - tools/eslint-rules --rulesdir tools/eslint-rules --reset --quiet - $(PYTHON) tools/cpplint.py --output=tap --logfile=test-cpp.tap $(CPPLINT_FILES) +eslint-ci: + @$(NODE) tools/eslint/bin/eslint.js -f tap -o test-eslint.tap src lib test \ + tools/eslint-rules --rulesdir tools/eslint-rules --reset --quiet + +cpplint-ci: + @$(PYTHON) tools/cpplint.py --output=tap \ + --logfile=test-cpp.tap $(CPPLINT_FILES) + .PHONY: lint cpplint jslint bench clean docopen docclean doc dist distclean \ check uninstall install install-includes install-bin all staticlib \ dynamiclib test test-all test-addons build-addons website-upload pkg \ blog blogclean tar binary release-only bench-http-simple bench-idle \ bench-all bench bench-misc bench-array bench-buffer bench-net \ - bench-http bench-fs bench-tls cctest run-ci + bench-http bench-fs bench-tls cctest run-ci eslint-ci cpplint-ci From 7bf5090f25e333fb936ed34197ae89aaa65740f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 12:26:33 +1100 Subject: [PATCH 06/11] concat linter results so jenkins can pick it up --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 9cb81b2d4380c3..4d6cfcd75e254b 100644 --- a/Makefile +++ b/Makefile @@ -536,6 +536,9 @@ cpplint: lint: jslint cpplint +lint-ci: eslint-ci cpplint-ci + cat test-eslint.tap test-cpp.tap > test.tap + eslint-ci: @$(NODE) tools/eslint/bin/eslint.js -f tap -o test-eslint.tap src lib test \ tools/eslint-rules --rulesdir tools/eslint-rules --reset --quiet From 2c7c640f7b90f8b9fb2de0dbcda5eac3494afdb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 12:28:44 +1100 Subject: [PATCH 07/11] run jobs separately instead --- Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Makefile b/Makefile index 4d6cfcd75e254b..9cb81b2d4380c3 100644 --- a/Makefile +++ b/Makefile @@ -536,9 +536,6 @@ cpplint: lint: jslint cpplint -lint-ci: eslint-ci cpplint-ci - cat test-eslint.tap test-cpp.tap > test.tap - eslint-ci: @$(NODE) tools/eslint/bin/eslint.js -f tap -o test-eslint.tap src lib test \ tools/eslint-rules --rulesdir tools/eslint-rules --reset --quiet From b18f32c67c304b098e6de841b111576b7cfb425e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 13:15:09 +1100 Subject: [PATCH 08/11] fix build --- lib/url.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/url.js b/lib/url.js index 9c17a57b7f46b3..45155fee936bbf 100644 --- a/lib/url.js +++ b/lib/url.js @@ -9,7 +9,6 @@ exports.format = urlFormat; exports.Url = Url; -// Here's a very long line we should ask linter about. Suggesting it won't be very pleased. function Url() { this.protocol = null; this.slashes = null; From 4d949119daff9f05eb5d8ceaa669748756cd7a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 14:11:10 +1100 Subject: [PATCH 09/11] lets break it --- lib/url.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/url.js b/lib/url.js index 45155fee936bbf..ece42164d4c4ad 100644 --- a/lib/url.js +++ b/lib/url.js @@ -9,6 +9,7 @@ exports.format = urlFormat; exports.Url = Url; +// lets break this again and again and again and again and again and again and again and again and again function Url() { this.protocol = null; this.slashes = null; From fb41ac364109199f1477aaf0d7b28f52f778b98d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 14:14:24 +1100 Subject: [PATCH 10/11] more breakage --- lib/util.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/util.js b/lib/util.js index 399a4ee0a23828..b9d512910c436a 100644 --- a/lib/util.js +++ b/lib/util.js @@ -7,14 +7,19 @@ const binding = process.binding('util'); var Debug; +// lets break this again and again and again and again and again and again and again and again and again + const formatRegExp = /%[sdj%]/g; exports.format = function(f) { + + if (typeof f !== 'string') { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(inspect(arguments[i])); } return objects.join(' '); + } if (arguments.length === 1) return f; From 42d605992c8bdb73d5b0d1fd8bbc92e3670d9e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Bergstr=C3=B6m?= Date: Tue, 20 Oct 2015 14:22:21 +1100 Subject: [PATCH 11/11] ..and fix it again --- lib/url.js | 1 - lib/util.js | 5 ----- 2 files changed, 6 deletions(-) diff --git a/lib/url.js b/lib/url.js index ece42164d4c4ad..45155fee936bbf 100644 --- a/lib/url.js +++ b/lib/url.js @@ -9,7 +9,6 @@ exports.format = urlFormat; exports.Url = Url; -// lets break this again and again and again and again and again and again and again and again and again function Url() { this.protocol = null; this.slashes = null; diff --git a/lib/util.js b/lib/util.js index b9d512910c436a..399a4ee0a23828 100644 --- a/lib/util.js +++ b/lib/util.js @@ -7,19 +7,14 @@ const binding = process.binding('util'); var Debug; -// lets break this again and again and again and again and again and again and again and again and again - const formatRegExp = /%[sdj%]/g; exports.format = function(f) { - - if (typeof f !== 'string') { var objects = []; for (var i = 0; i < arguments.length; i++) { objects.push(inspect(arguments[i])); } return objects.join(' '); - } if (arguments.length === 1) return f;