From e82f39375a2a5445ec7f8a2aa25102132661cd40 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 26 May 2020 08:42:30 +0200 Subject: [PATCH 1/2] tools: update check-imports using function Currently, the do_exist function that performs the checks for unused types declared with using declarations, only matches the name of the using declarations. The means that some unused using declarations are not detected. For example having both a 'using Maybe;' and a 'using MaybeLocal' and only using MaybeLocal would not be reported. This commit attempts to take into account the above mentioned case and also others where the name of the using declaration type is used in name of a variables or function call. For example, 'using Just;', will now be reported as unused even if there are calls to the FromJust function. --- tools/check-imports.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/check-imports.py b/tools/check-imports.py index 51b4e63aa039..a91b839e9620 100755 --- a/tools/check-imports.py +++ b/tools/check-imports.py @@ -6,10 +6,11 @@ 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): + re.search("(:?^|\s|<|\(|\:|{{){0}[\s<>(,:*)&]".format(imported), + line) + for line in lines): print('File "{0}" does not use "{1}"'.format(file_name, imported)) return False return True From 6babd4d428cd98bdd28931b37d186f4e40716d2b Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 26 May 2020 08:48:17 +0200 Subject: [PATCH 2/2] src: remove unused using declarations This commit removes the unused using declarations reported by lint-cpp. --- src/async_wrap.cc | 1 - src/heap_utils.cc | 1 - src/inspector_agent.cc | 2 -- src/inspector_js_api.cc | 1 - src/module_wrap.cc | 2 -- src/node_contextify.cc | 1 - src/node_credentials.cc | 1 - src/node_dir.cc | 1 - src/node_dtrace.cc | 1 - src/node_errors.cc | 1 - src/node_http2.cc | 3 --- src/node_main_instance.cc | 1 - src/node_messaging.cc | 1 - src/node_native_module.cc | 3 --- src/node_native_module_env.cc | 1 - src/node_options.cc | 1 - src/node_perf.cc | 3 --- src/node_process_methods.cc | 2 -- src/node_process_object.cc | 2 -- src/node_report.cc | 3 --- src/node_report_module.cc | 2 -- src/node_util.cc | 1 - src/node_zlib.cc | 2 -- src/pipe_wrap.cc | 1 - src/tcp_wrap.cc | 1 - src/tls_wrap.cc | 1 - src/tty_wrap.cc | 1 - 27 files changed, 41 deletions(-) diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 46a6ea6eebe8..13c2c3ca5a5e 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -39,7 +39,6 @@ using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; -using v8::Maybe; using v8::MaybeLocal; using v8::Name; using v8::Number; diff --git a/src/heap_utils.cc b/src/heap_utils.cc index 2e979e49e879..386bf61e4eca 100644 --- a/src/heap_utils.cc +++ b/src/heap_utils.cc @@ -15,7 +15,6 @@ using v8::Global; using v8::HandleScope; using v8::HeapSnapshot; using v8::Isolate; -using v8::JSON; using v8::Local; using v8::MaybeLocal; using v8::Number; diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 74b7fc13cde4..f128a197ca97 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -45,8 +45,6 @@ using v8::Isolate; using v8::Local; using v8::Message; using v8::Object; -using v8::String; -using v8::Task; using v8::Value; using v8_inspector::StringBuffer; diff --git a/src/inspector_js_api.cc b/src/inspector_js_api.cc index 5c9ad5e94642..c318f7864663 100644 --- a/src/inspector_js_api.cc +++ b/src/inspector_js_api.cc @@ -12,7 +12,6 @@ namespace node { namespace inspector { namespace { -using v8::Boolean; using v8::Context; using v8::Function; using v8::FunctionCallbackInfo; diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 59ef9daf727e..ab8dbc9cbf7f 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -33,9 +33,7 @@ using v8::HandleScope; using v8::Integer; using v8::IntegrityLevel; using v8::Isolate; -using v8::Just; using v8::Local; -using v8::Maybe; using v8::MaybeLocal; using v8::Module; using v8::Number; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 99adccbcef9d..69663afe423f 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -36,7 +36,6 @@ namespace contextify { using errors::TryCatchScope; using v8::Array; -using v8::ArrayBuffer; using v8::ArrayBufferView; using v8::Boolean; using v8::Context; diff --git a/src/node_credentials.cc b/src/node_credentials.cc index ad0e1dbb9bb6..d7be988d978b 100644 --- a/src/node_credentials.cc +++ b/src/node_credentials.cc @@ -15,7 +15,6 @@ namespace node { using v8::Array; using v8::Context; -using v8::Function; using v8::FunctionCallbackInfo; using v8::HandleScope; using v8::Isolate; diff --git a/src/node_dir.cc b/src/node_dir.cc index cb32fa0a5c66..7d1e1b1d7d66 100644 --- a/src/node_dir.cc +++ b/src/node_dir.cc @@ -28,7 +28,6 @@ using fs::GetReqWrap; using v8::Array; using v8::Context; -using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::HandleScope; diff --git a/src/node_dtrace.cc b/src/node_dtrace.cc index fc58734c59ae..3c407f3447f1 100644 --- a/src/node_dtrace.cc +++ b/src/node_dtrace.cc @@ -57,7 +57,6 @@ using v8::HandleScope; using v8::Isolate; using v8::Local; using v8::Object; -using v8::String; using v8::Value; #define SLURP_STRING(obj, member, valp) \ diff --git a/src/node_errors.cc b/src/node_errors.cc index 22bc4d994b88..4f8b003d8da2 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -25,7 +25,6 @@ using v8::Local; using v8::Maybe; using v8::MaybeLocal; using v8::Message; -using v8::Number; using v8::Object; using v8::ScriptOrigin; using v8::StackFrame; diff --git a/src/node_http2.cc b/src/node_http2.cc index 25f353bb1477..067e73b043b3 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -22,7 +22,6 @@ using v8::ArrayBufferView; using v8::Boolean; using v8::Context; using v8::EscapableHandleScope; -using v8::Float64Array; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; @@ -35,8 +34,6 @@ using v8::Number; using v8::Object; using v8::ObjectTemplate; using v8::String; -using v8::Uint32; -using v8::Uint32Array; using v8::Uint8Array; using v8::Undefined; using v8::Value; diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index e9cef5fc0022..f638e26dba5a 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -20,7 +20,6 @@ using v8::HandleScope; using v8::Isolate; using v8::Local; using v8::Locker; -using v8::Object; using v8::SealHandleScope; NodeMainInstance::NodeMainInstance(Isolate* isolate, diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 6081a523cd4c..ffe29a5dea8c 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -16,7 +16,6 @@ using v8::BackingStore; using v8::CompiledWasmModule; using v8::Context; using v8::EscapableHandleScope; -using v8::Exception; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; diff --git a/src/node_native_module.cc b/src/node_native_module.cc index a57355418bea..a7675d00d89c 100644 --- a/src/node_native_module.cc +++ b/src/node_native_module.cc @@ -7,14 +7,11 @@ namespace native_module { using v8::Context; using v8::EscapableHandleScope; using v8::Function; -using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; -using v8::Maybe; using v8::MaybeLocal; using v8::Object; -using v8::Script; using v8::ScriptCompiler; using v8::ScriptOrigin; using v8::String; diff --git a/src/node_native_module_env.cc b/src/node_native_module_env.cc index be647b01c640..ae8d349541b9 100644 --- a/src/node_native_module_env.cc +++ b/src/node_native_module_env.cc @@ -11,7 +11,6 @@ using v8::FunctionCallbackInfo; using v8::IntegrityLevel; using v8::Isolate; using v8::Local; -using v8::Maybe; using v8::MaybeLocal; using v8::Name; using v8::None; diff --git a/src/node_options.cc b/src/node_options.cc index 875c2e73001d..a84420e3c5d3 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -18,7 +18,6 @@ using v8::Local; using v8::Map; using v8::Number; using v8::Object; -using v8::String; using v8::Undefined; using v8::Value; diff --git a/src/node_perf.cc b/src/node_perf.cc index fb3b2c43acdd..4ed1c956c9e5 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -11,7 +11,6 @@ namespace node { namespace performance { -using v8::Array; using v8::Context; using v8::DontDelete; using v8::Function; @@ -25,14 +24,12 @@ using v8::Isolate; using v8::Local; using v8::Map; using v8::MaybeLocal; -using v8::Name; using v8::NewStringType; using v8::Number; using v8::Object; using v8::PropertyAttribute; using v8::ReadOnly; using v8::String; -using v8::Uint32Array; using v8::Value; // Microseconds in a millisecond, as a float. diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index 88f4c1cfbd02..6013dbb86b72 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -36,13 +36,11 @@ using v8::ArrayBuffer; using v8::BigUint64Array; using v8::Context; using v8::Float64Array; -using v8::Function; using v8::FunctionCallbackInfo; using v8::HeapStatistics; using v8::Integer; using v8::Isolate; using v8::Local; -using v8::Name; using v8::NewStringType; using v8::Number; using v8::Object; diff --git a/src/node_process_object.cc b/src/node_process_object.cc index ca17da9583ef..5bec65805a10 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -15,10 +15,8 @@ using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; -using v8::HandleScope; using v8::Integer; using v8::Isolate; -using v8::Just; using v8::Local; using v8::MaybeLocal; using v8::Name; diff --git a/src/node_report.cc b/src/node_report.cc index 98da24c9567a..62b3d7abd105 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -41,11 +41,8 @@ using v8::HeapSpaceStatistics; using v8::HeapStatistics; using v8::Isolate; using v8::Local; -using v8::Number; -using v8::StackTrace; using v8::String; using v8::V8; -using v8::Value; namespace per_process = node::per_process; diff --git a/src/node_report_module.cc b/src/node_report_module.cc index 700dd88aba64..5afc0cfe104f 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -18,9 +18,7 @@ namespace report { using node::Environment; using node::Mutex; using node::Utf8Value; -using v8::Boolean; using v8::Context; -using v8::Function; using v8::FunctionCallbackInfo; using v8::HandleScope; using v8::Isolate; diff --git a/src/node_util.cc b/src/node_util.cc index db9b8ec8d65f..ec3f8e1fe7de 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -10,7 +10,6 @@ using v8::Array; using v8::ArrayBufferView; using v8::Boolean; using v8::Context; -using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Global; diff --git a/src/node_zlib.cc b/src/node_zlib.cc index 83698bd5192e..85e87327c077 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -43,7 +43,6 @@ namespace node { -using v8::Array; using v8::ArrayBuffer; using v8::Context; using v8::Function; @@ -56,7 +55,6 @@ using v8::Integer; using v8::Local; using v8::Object; using v8::String; -using v8::Uint32; using v8::Uint32Array; using v8::Value; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index c4a5b7cd62e1..9e6831b2ed3b 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -39,7 +39,6 @@ using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; -using v8::HandleScope; using v8::Int32; using v8::Isolate; using v8::Local; diff --git a/src/tcp_wrap.cc b/src/tcp_wrap.cc index 619c9ef61963..ef1b80939e91 100644 --- a/src/tcp_wrap.cc +++ b/src/tcp_wrap.cc @@ -42,7 +42,6 @@ using v8::EscapableHandleScope; using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; -using v8::HandleScope; using v8::Int32; using v8::Integer; using v8::Local; diff --git a/src/tls_wrap.cc b/src/tls_wrap.cc index 0c2c2bbc014c..8fa1bd2eea01 100644 --- a/src/tls_wrap.cc +++ b/src/tls_wrap.cc @@ -47,7 +47,6 @@ using v8::HandleScope; using v8::Integer; using v8::Isolate; using v8::Local; -using v8::Maybe; using v8::MaybeLocal; using v8::Object; using v8::PropertyAttribute; diff --git a/src/tty_wrap.cc b/src/tty_wrap.cc index 8536fae3ed73..401c2513dbc6 100644 --- a/src/tty_wrap.cc +++ b/src/tty_wrap.cc @@ -32,7 +32,6 @@ namespace node { using v8::Array; using v8::Context; -using v8::Function; using v8::FunctionCallbackInfo; using v8::FunctionTemplate; using v8::Integer;