From 9a5306ab8f27023aff23e78c7b18a4b9ad78a8db Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Fri, 8 Apr 2016 00:26:05 +0530 Subject: [PATCH 1/3] tools: rewrite check-install.sh in python As it is, check-install.sh does not show more helpful error messages, and supporting various shells could be a problem. This patch rewrites the same in Python. --- tools/check-imports.py | 42 ++++++++++++++++++++++++++++++++++++++++++ tools/check-imports.sh | 36 ------------------------------------ 2 files changed, 42 insertions(+), 36 deletions(-) create mode 100755 tools/check-imports.py delete mode 100755 tools/check-imports.sh diff --git a/tools/check-imports.py b/tools/check-imports.py new file mode 100755 index 00000000000000..cb1c16eac4410a --- /dev/null +++ b/tools/check-imports.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python + +from __future__ import print_function +import glob +import re +import sys + + +def do_exist(file_name, lines, imported): + if not any(not re.match('using \w+::{0};'.format(imported), line) and + re.search(imported, line) for line in lines): + print('File "{0}" does not use "{1}"'.format(file_name, imported)) + return False + return True + + +def is_valid(file_name): + with open(file_name) as source_file: + lines = [line.strip() for line in source_file] + + usings, importeds, line_numbers, valid = [], [], [], True + for idx, line in enumerate(lines, 1): + matches = re.search(r'^using (\w+::(\w+));$', line) + if matches: + line_numbers.append(idx) + usings.append(matches.group(1)) + importeds.append(matches.group(2)) + + valid = all([do_exist(file_name, lines, imported) for imported in importeds]) + + sorted_usings = sorted(usings, key=lambda x: x.lower()) + if sorted_usings != usings: + print("using statements aren't sorted in '{0}'.".format(file)) + for num, actual, expected in zip(line_numbers, usings, sorted_usings): + if actual != expected: + print('\tLine {0}: Actual: {1}, Expected: {2}' + .format(num, actual, expected)) + return False + else: + return valid + +sys.exit(0 if all(map(is_valid, glob.iglob('src/*.cc'))) else 1) diff --git a/tools/check-imports.sh b/tools/check-imports.sh deleted file mode 100755 index 2fb263f2115c2b..00000000000000 --- a/tools/check-imports.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh - -# Copyright (c) 2013, 2014, Ben Noordhuis -# -# Permission to use, copy, modify, and/or distribute this software for any -# purpose with or without fee is hereby granted, provided that the above -# copyright notice and this permission notice appear in all copies. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -SED=sed -UNAME=`uname` - -if [ "$UNAME" = Darwin ] || [ "$UNAME" = FreeBSD ]; then - SED=gsed -fi - -cd `dirname "$0"`/../ - -for FILE in src/*.cc; do - $SED -rne 's/^using (\w+::\w+);$/\1/p' $FILE | sort -c || echo "in $FILE" -done - -for FILE in src/*.cc; do - for IMPORT in `$SED -rne 's/^using (\w+)::(\w+);$/\2/p' $FILE`; do - if ! $SED -re '/^using (\w+)::(\w+);$/d' $FILE | grep -q "$IMPORT"; then - echo "$IMPORT unused in $FILE" - fi - done -done From c62876c92b8e33e77c53e74321bcf6ec960db1c5 Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Fri, 8 Apr 2016 00:38:21 +0530 Subject: [PATCH 2/3] tools: enable check-imports.py in linter This patch simply enables check-imports.py in the linting process --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 401464c87a6960..890c431eac0556 100644 --- a/Makefile +++ b/Makefile @@ -630,6 +630,7 @@ CPPLINT_FILES = $(filter-out $(CPPLINT_EXCLUDE), $(wildcard \ cpplint: @$(PYTHON) tools/cpplint.py $(CPPLINT_FILES) + @$(PYTHON) tools/check-imports.py ifneq ("","$(wildcard tools/eslint/bin/eslint.js)") lint: jslint cpplint From e6e37d311fbd2b95c4c9932eddd2f19aa9982fba Mon Sep 17 00:00:00 2001 From: Sakthipriyan Vairamani Date: Thu, 7 Apr 2016 21:31:11 +0530 Subject: [PATCH 3/3] src: fix check-imports.py linter errors --- src/async-wrap.cc | 1 - src/env.cc | 1 - src/handle_wrap.cc | 1 - src/node.cc | 2 -- src/node_buffer.cc | 1 - src/node_contextify.cc | 2 -- src/node_v8.cc | 1 - src/node_watchdog.cc | 3 --- src/pipe_wrap.cc | 1 - src/stream_wrap.cc | 5 ----- src/string_bytes.cc | 2 +- src/tcp_wrap.cc | 1 - src/tls_wrap.cc | 4 +--- src/tty_wrap.cc | 1 - src/util.cc | 2 +- src/uv.cc | 2 +- 16 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/async-wrap.cc b/src/async-wrap.cc index 8129500a922d97..79631b1ec14f4e 100644 --- a/src/async-wrap.cc +++ b/src/async-wrap.cc @@ -8,7 +8,6 @@ #include "v8.h" #include "v8-profiler.h" -using v8::Array; using v8::Boolean; using v8::Context; using v8::Function; diff --git a/src/env.cc b/src/env.cc index ea0ab51cfe922a..12be4866aac2d2 100644 --- a/src/env.cc +++ b/src/env.cc @@ -17,7 +17,6 @@ using v8::Local; using v8::Message; using v8::StackFrame; using v8::StackTrace; -using v8::TryCatch; using v8::Value; void Environment::PrintSyncTrace() const { diff --git a/src/handle_wrap.cc b/src/handle_wrap.cc index 41c42caa3cca11..7a7ce8ae262e34 100644 --- a/src/handle_wrap.cc +++ b/src/handle_wrap.cc @@ -9,7 +9,6 @@ namespace node { -using v8::Boolean; using v8::Context; using v8::FunctionCallbackInfo; using v8::HandleScope; diff --git a/src/node.cc b/src/node.cc index 53d390a467983a..a70621636fca33 100644 --- a/src/node.cc +++ b/src/node.cc @@ -127,8 +127,6 @@ using v8::PromiseRejectMessage; using v8::PropertyCallbackInfo; using v8::ScriptOrigin; using v8::SealHandleScope; -using v8::StackFrame; -using v8::StackTrace; using v8::String; using v8::TryCatch; using v8::Uint32; diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 322cc5f57ce881..ea62dc929435aa 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -71,7 +71,6 @@ using v8::Context; using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; -using v8::FunctionTemplate; using v8::HandleScope; using v8::Integer; using v8::Isolate; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 6586f79bfedbe1..db83660308ce99 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -11,7 +11,6 @@ namespace node { -using v8::AccessType; using v8::Array; using v8::ArrayBuffer; using v8::Boolean; @@ -30,7 +29,6 @@ using v8::Maybe; using v8::MaybeLocal; using v8::Name; using v8::NamedPropertyHandlerConfiguration; -using v8::None; using v8::Object; using v8::ObjectTemplate; using v8::Persistent; diff --git a/src/node_v8.cc b/src/node_v8.cc index a1122e57f13cac..04da61677dc26d 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -20,7 +20,6 @@ using v8::NewStringType; using v8::Object; using v8::String; using v8::Uint32; -using v8::Uint32Array; using v8::V8; using v8::Value; diff --git a/src/node_watchdog.cc b/src/node_watchdog.cc index ac9f304926bac4..dfa7debd9a7b3a 100644 --- a/src/node_watchdog.cc +++ b/src/node_watchdog.cc @@ -4,9 +4,6 @@ namespace node { -using v8::V8; - - Watchdog::Watchdog(v8::Isolate* isolate, uint64_t ms) : isolate_(isolate), destroyed_(false) { int rc; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index ec6ef32b08ac09..25080041c276d8 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -26,7 +26,6 @@ using v8::HandleScope; using v8::Integer; using v8::Local; using v8::Object; -using v8::PropertyAttribute; using v8::String; using v8::Undefined; using v8::Value; diff --git a/src/stream_wrap.cc b/src/stream_wrap.cc index e6236a6e529864..695e917e027604 100644 --- a/src/stream_wrap.cc +++ b/src/stream_wrap.cc @@ -22,7 +22,6 @@ namespace node { -using v8::Array; using v8::Context; using v8::EscapableHandleScope; using v8::FunctionCallbackInfo; @@ -30,12 +29,8 @@ using v8::FunctionTemplate; using v8::HandleScope; using v8::Integer; using v8::Local; -using v8::Number; using v8::Object; -using v8::PropertyCallbackInfo; -using v8::String; using v8::True; -using v8::Undefined; using v8::Value; diff --git a/src/string_bytes.cc b/src/string_bytes.cc index b8d7d3b42f11c8..5bd3a21176a474 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -19,10 +19,10 @@ using v8::EscapableHandleScope; using v8::HandleScope; using v8::Isolate; using v8::Local; +using v8::MaybeLocal; using v8::Object; using v8::String; using v8::Value; -using v8::MaybeLocal; template class ExternString: public ResourceType { diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 4bfe9dd0d838a3..4e8617af2d0c18 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -27,7 +27,6 @@ using v8::HandleScope; using v8::Integer; using v8::Local; using v8::Object; -using v8::PropertyAttribute; using v8::String; using v8::Undefined; using v8::Value; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index ba8f760194d75e..d4214ed7c3efa5 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -15,8 +15,8 @@ namespace node { -using crypto::SSLWrap; using crypto::SecureContext; +using crypto::SSLWrap; using v8::Boolean; using v8::Context; using v8::EscapableHandleScope; @@ -24,9 +24,7 @@ using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; -using v8::Integer; using v8::Local; -using v8::Null; using v8::Object; using v8::String; using v8::Value; diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 567a504276a0d4..5a1d333c3d2bf1 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -21,7 +21,6 @@ using v8::FunctionTemplate; using v8::Integer; using v8::Local; using v8::Object; -using v8::PropertyAttribute; using v8::String; using v8::Value; diff --git a/src/util.cc b/src/util.cc index 3b0278cedaff67..57c44a9795ec04 100644 --- a/src/util.cc +++ b/src/util.cc @@ -6,8 +6,8 @@ namespace node { using v8::Isolate; -using v8::String; using v8::Local; +using v8::String; using v8::Value; static int MakeUtf8String(Isolate* isolate, diff --git a/src/uv.cc b/src/uv.cc index d03e7750083b4c..21520f5cb8783c 100644 --- a/src/uv.cc +++ b/src/uv.cc @@ -9,8 +9,8 @@ namespace uv { using v8::Context; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; -using v8::Local; using v8::Integer; +using v8::Local; using v8::Object; using v8::String; using v8::Value;