Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src,tools: rewrite check-imports and fix linter errors #6105

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/async-wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "v8.h"
#include "v8-profiler.h"

using v8::Array;
using v8::Boolean;
using v8::Context;
using v8::Function;
Expand Down
1 change: 0 additions & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace node {

using v8::Boolean;
using v8::Context;
using v8::FunctionCallbackInfo;
using v8::HandleScope;
Expand Down
2 changes: 0 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace node {

using v8::AccessType;
using v8::Array;
using v8::ArrayBuffer;
using v8::Boolean;
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/node_v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 0 additions & 3 deletions src/node_watchdog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

namespace node {

using v8::V8;


Watchdog::Watchdog(v8::Isolate* isolate, uint64_t ms) : isolate_(isolate),
destroyed_(false) {
int rc;
Expand Down
1 change: 0 additions & 1 deletion src/pipe_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/stream_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@

namespace node {

using v8::Array;
using v8::Context;
using v8::EscapableHandleScope;
using v8::FunctionCallbackInfo;
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;


Expand Down
2 changes: 1 addition & 1 deletion src/string_bytes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename ResourceType, typename TypeName>
class ExternString: public ResourceType {
Expand Down
1 change: 0 additions & 1 deletion src/tcp_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/tls_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@

namespace node {

using crypto::SSLWrap;
using crypto::SecureContext;
using crypto::SSLWrap;
using v8::Boolean;
using v8::Context;
using v8::EscapableHandleScope;
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;
Expand Down
1 change: 0 additions & 1 deletion src/tty_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/uv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions tools/check-imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env python
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use two-space indent in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis Done!


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)
36 changes: 0 additions & 36 deletions tools/check-imports.sh

This file was deleted.