From a42dcbeb43ab22c0db07c4e0a9eab5e0f44578f4 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Wed, 8 Jan 2020 21:21:56 +0800 Subject: [PATCH] tools: add clang-tidy rule in src PR-URL: https://github.com/nodejs/node/pull/26840 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Rich Trott --- src/.clang-tidy | 27 +++++++++++++++++++++++++++ src/env.h | 7 ++++--- src/fs_event_wrap.cc | 2 +- src/node.cc | 2 +- src/node_main_instance.cc | 15 +++++++++------ src/tracing/traced_value.h | 2 +- 6 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 src/.clang-tidy diff --git a/src/.clang-tidy b/src/.clang-tidy new file mode 100644 index 00000000000000..1713161c8ca9e0 --- /dev/null +++ b/src/.clang-tidy @@ -0,0 +1,27 @@ +--- +Checks: '-*, + # modernize-use-auto, + # modernize-use-equals-delete, + modernize-deprecated-headers, + modernize-make-unique, + modernize-make-shared, + modernize-redundant-void-arg, + modernize-replace-random-shuffle, + modernize-shrink-to-fit, + modernize-use-bool-literals, + modernize-use-emplace, + modernize-use-equals-default, + modernize-use-nullptr, + modernize-use-override, + performance-faster-string-find, + # performance-unnecessary-value-param, see https://github.com/nodejs/node/pull/26042 + readability-delete-null-pointer, ' +WarningsAsErrors: '' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +FormatStyle: none +User: nodejs/cpp +CheckOptions: + - key: google-readability-braces-around-statements.ShortStatementLines + value: 1 +... diff --git a/src/env.h b/src/env.h index db15788ffca7c0..558ef5cbde8cbf 100644 --- a/src/env.h +++ b/src/env.h @@ -589,7 +589,7 @@ struct AllocatedBuffer { class AsyncRequest : public MemoryRetainer { public: AsyncRequest() = default; - ~AsyncRequest(); + ~AsyncRequest() override; AsyncRequest(const AsyncRequest&) = delete; AsyncRequest& operator=(const AsyncRequest&) = delete; @@ -907,7 +907,7 @@ class Environment : public MemoryRetainer { const std::vector& exec_args, Flags flags = Flags(), uint64_t thread_id = kNoThreadId); - ~Environment(); + ~Environment() override; void InitializeLibuv(bool start_profiler_idle_notifier); inline const std::vector& exec_argv(); @@ -1379,7 +1379,8 @@ class Environment : public MemoryRetainer { bool http_parser_buffer_in_use_ = false; std::unique_ptr http2_state_; - bool debug_enabled_[static_cast(DebugCategory::CATEGORY_COUNT)] = {0}; + bool debug_enabled_[static_cast(DebugCategory::CATEGORY_COUNT)] = { + false}; AliasedFloat64Array fs_stats_field_array_; AliasedBigUint64Array fs_stats_field_bigint_array_; diff --git a/src/fs_event_wrap.cc b/src/fs_event_wrap.cc index 8a75f0557c4b37..d38556b1bf8011 100644 --- a/src/fs_event_wrap.cc +++ b/src/fs_event_wrap.cc @@ -64,7 +64,7 @@ class FSEventWrap: public HandleWrap { static const encoding kDefaultEncoding = UTF8; FSEventWrap(Environment* env, Local object); - ~FSEventWrap() = default; + ~FSEventWrap() override = default; static void OnEvent(uv_fs_event_t* handle, const char* filename, int events, int status); diff --git a/src/node.cc b/src/node.cc index 461bdc7f6661ae..7da1fbb6689d4a 100644 --- a/src/node.cc +++ b/src/node.cc @@ -877,7 +877,7 @@ int InitializeNodeWithArgs(std::vector* argv, } if (will_start_new_arg) { - env_argv.push_back(std::string(1, c)); + env_argv.emplace_back(std::string(1, c)); will_start_new_arg = false; } else { env_argv.back() += c; diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 86a857299f6e90..1453e1ea6a3810 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -1,3 +1,5 @@ +#include + #include "node_main_instance.h" #include "node_internals.h" #include "node_options-inl.h" @@ -34,7 +36,8 @@ NodeMainInstance::NodeMainInstance(Isolate* isolate, isolate_data_(nullptr), owns_isolate_(false), deserialize_mode_(false) { - isolate_data_.reset(new IsolateData(isolate_, event_loop, platform, nullptr)); + isolate_data_ = + std::make_unique(isolate_, event_loop, platform, nullptr); IsolateSettings misc; SetIsolateMiscHandlers(isolate_, misc); @@ -76,11 +79,11 @@ NodeMainInstance::NodeMainInstance( deserialize_mode_ = per_isolate_data_indexes != nullptr; // If the indexes are not nullptr, we are not deserializing CHECK_IMPLIES(deserialize_mode_, params->external_references != nullptr); - isolate_data_.reset(new IsolateData(isolate_, - event_loop, - platform, - array_buffer_allocator_.get(), - per_isolate_data_indexes)); + isolate_data_ = std::make_unique(isolate_, + event_loop, + platform, + array_buffer_allocator_.get(), + per_isolate_data_indexes); IsolateSettings s; SetIsolateMiscHandlers(isolate_, s); if (!deserialize_mode_) { diff --git a/src/tracing/traced_value.h b/src/tracing/traced_value.h index aa1dcd15c63d29..93c5be799b63a4 100644 --- a/src/tracing/traced_value.h +++ b/src/tracing/traced_value.h @@ -18,7 +18,7 @@ namespace tracing { class TracedValue : public v8::ConvertableToTraceFormat { public: - ~TracedValue() = default; + ~TracedValue() override = default; static std::unique_ptr Create(); static std::unique_ptr CreateArray();