diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 61455b2fccbaab..2087db2667c467 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -19,6 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +#include "async_wrap.h" // NOLINT(build/include_inline) #include "async_wrap-inl.h" #include "env-inl.h" #include "node_errors.h" diff --git a/src/debug_utils.cc b/src/debug_utils.cc index f1024183cdaedf..bff2f9ae915c8e 100644 --- a/src/debug_utils.cc +++ b/src/debug_utils.cc @@ -22,11 +22,6 @@ #include #endif -#else // __POSIX__ - -#include -#include - #endif // __POSIX__ #if defined(__linux__) || defined(__sun) || defined(__FreeBSD__) diff --git a/src/env.cc b/src/env.cc index fa98efabccd28c..fbf097caba37c7 100644 --- a/src/env.cc +++ b/src/env.cc @@ -1,3 +1,5 @@ +#include "env.h" + #include "async_wrap.h" #include "node_buffer.h" #include "node_context_data.h" @@ -14,9 +16,9 @@ #include "tracing/traced_value.h" #include "v8-profiler.h" -#include #include #include +#include namespace node { diff --git a/src/inspector/main_thread_interface.cc b/src/inspector/main_thread_interface.cc index 14f90fbd9d3a6c..af123d9ac5b549 100644 --- a/src/inspector/main_thread_interface.cc +++ b/src/inspector/main_thread_interface.cc @@ -2,10 +2,11 @@ #include "node_mutex.h" #include "v8-inspector.h" +#include "util-inl.h" -#include #include -#include "util-inl.h" + +#include namespace node { namespace inspector { diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 2376ae50044f0e..7b4dec90fc9548 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -16,16 +16,16 @@ #include "libplatform/libplatform.h" +#ifdef __POSIX__ +#include +#include // PTHREAD_STACK_MIN +#endif // __POSIX__ + #include #include #include #include -#ifdef __POSIX__ -#include // PTHREAD_STACK_MIN -#include -#endif // __POSIX__ - namespace node { namespace inspector { namespace { diff --git a/src/inspector_agent.h b/src/inspector_agent.h index b8b03b2edc3388..aa89fbba6bc099 100644 --- a/src/inspector_agent.h +++ b/src/inspector_agent.h @@ -1,12 +1,7 @@ -#ifndef SRC_INSPECTOR_AGENT_H_ -#define SRC_INSPECTOR_AGENT_H_ +#pragma once #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include - -#include - #if !HAVE_INSPECTOR #error("This header can only be used when inspector is enabled") #endif @@ -15,6 +10,9 @@ #include "node_persistent.h" #include "v8.h" +#include +#include + namespace v8_inspector { class StringView; } // namespace v8_inspector @@ -143,5 +141,3 @@ class Agent { } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#endif // SRC_INSPECTOR_AGENT_H_ diff --git a/src/inspector_io.h b/src/inspector_io.h index e4b4ee44f81d8c..0dfb08f470345e 100644 --- a/src/inspector_io.h +++ b/src/inspector_io.h @@ -1,18 +1,18 @@ -#ifndef SRC_INSPECTOR_IO_H_ -#define SRC_INSPECTOR_IO_H_ +#pragma once #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS +#if !HAVE_INSPECTOR +#error("This header can only be used when inspector is enabled") +#endif + #include "inspector_socket_server.h" #include "node_mutex.h" + #include "uv.h" -#include #include - -#if !HAVE_INSPECTOR -#error("This header can only be used when inspector is enabled") -#endif +#include namespace v8_inspector { @@ -93,5 +93,3 @@ class InspectorIo { } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#endif // SRC_INSPECTOR_IO_H_ diff --git a/src/inspector_socket.cc b/src/inspector_socket.cc index 139a7352ea7667..7fd691ddd871ae 100644 --- a/src/inspector_socket.cc +++ b/src/inspector_socket.cc @@ -10,8 +10,8 @@ #include "openssl/sha.h" // Sha-1 hash -#include #include +#include #define ACCEPT_KEY_LENGTH base64_encoded_size(20) diff --git a/src/large_pages/node_large_page.cc b/src/large_pages/node_large_page.cc index 4b860d9ccb47ca..ad599a1a91bfdc 100644 --- a/src/large_pages/node_large_page.cc +++ b/src/large_pages/node_large_page.cc @@ -20,8 +20,8 @@ // // SPDX-License-Identifier: MIT -#include -#include // _O_RDWR +#include // NOLINT(build/include) +#include // _O_RDWR #include // PATH_MAX #include #include @@ -31,11 +31,12 @@ #include #include #include +#include // readlink + #include #include #include #include -#include // readlink // The functions in this file map the text segment of node into 2M pages. // The algorithm is simple diff --git a/src/memory_tracker.h b/src/memory_tracker.h index 4125f9585f1d74..c5d9b2106f0826 100644 --- a/src/memory_tracker.h +++ b/src/memory_tracker.h @@ -1,16 +1,17 @@ -#ifndef SRC_MEMORY_TRACKER_H_ -#define SRC_MEMORY_TRACKER_H_ +#pragma once #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS -#include +#include "aliased_buffer.h" +#include "v8-profiler.h" + +#include + +#include #include #include #include -#include -#include -#include "aliased_buffer.h" -#include "v8-profiler.h" +#include namespace node { @@ -253,5 +254,3 @@ class MemoryTracker { } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS - -#endif // SRC_MEMORY_TRACKER_H_ diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 3d55d12cc3874a..d311f7cacaee1e 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -1,6 +1,3 @@ -#include -#include // PATH_MAX -#include // S_IFDIR #include "module_wrap.h" #include "env.h" @@ -10,6 +7,11 @@ #include "node_contextify.h" #include "node_watchdog.h" +#include // S_IFDIR + +#include +#include // PATH_MAX + namespace node { namespace loader { diff --git a/src/node.cc b/src/node.cc index fcc8923ff4768c..5e0e8df4214450 100644 --- a/src/node.cc +++ b/src/node.cc @@ -19,6 +19,10 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +#include "node.h" + +// ========== local headers ========== + #include "debug_utils.h" #include "node_binding.h" #include "node_buffer.h" @@ -72,25 +76,19 @@ #include "large_pages/node_large_page.h" #endif -#include +#ifdef NODE_REPORT +#include "node_report.h" +#endif + +// ========== global C headers ========== + #include // _O_RDWR -#include // PATH_MAX -#include -#include -#include -#include #include -#include -#include - #if defined(NODE_HAVE_I18N_SUPPORT) #include #endif -#ifdef NODE_REPORT -#include "node_report.h" -#endif #if defined(LEAK_SANITIZER) #include @@ -106,6 +104,18 @@ #include // STDIN_FILENO, STDERR_FILENO #endif +// ========== global C++ headers ========== + +#include +#include // PATH_MAX +#include +#include +#include +#include + +#include +#include + namespace node { using options_parser::kAllowedInEnvironment; diff --git a/src/node_constants.cc b/src/node_constants.cc index e4eae1727cb62e..be27de4ed64430 100644 --- a/src/node_constants.cc +++ b/src/node_constants.cc @@ -24,28 +24,31 @@ #include "zlib.h" -#include #if !defined(_MSC_VER) #include #endif + #include -#include #include #include -#include + #if HAVE_OPENSSL -# include -# include -# ifndef OPENSSL_NO_ENGINE -# include -# endif // !OPENSSL_NO_ENGINE -#endif +#include +#include +#ifndef OPENSSL_NO_ENGINE +#include +#endif // !OPENSSL_NO_ENGINE +#endif // HAVE_OPENSSL #if defined(__POSIX__) #include #endif +#include +#include +#include + namespace node { using v8::Local; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 0ba2b1a90cb93b..b9962f091d9e40 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -19,11 +19,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -#include "node_errors.h" +#include "node_contextify.h" + #include "node_internals.h" #include "node_watchdog.h" #include "base_object-inl.h" -#include "node_contextify.h" #include "node_context_data.h" #include "node_errors.h" #include "module_wrap.h" diff --git a/src/node_crypto_clienthello.cc b/src/node_crypto_clienthello.cc index b0375755774318..268d4773570f8b 100644 --- a/src/node_crypto_clienthello.cc +++ b/src/node_crypto_clienthello.cc @@ -19,6 +19,7 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. +#include "node_crypto_clienthello.h" // NOLINT(build/include_inline) #include "node_crypto_clienthello-inl.h" namespace node { diff --git a/src/node_http_parser_impl.h b/src/node_http_parser_impl.h index 7a51a3140d212e..a154af5cfbaf4e 100644 --- a/src/node_http_parser_impl.h +++ b/src/node_http_parser_impl.h @@ -22,8 +22,7 @@ // This file is included from 2 files, node_http_parser_traditional.cc // and node_http_parser_llhttp.cc. -#ifndef SRC_NODE_HTTP_PARSER_IMPL_H_ -#define SRC_NODE_HTTP_PARSER_IMPL_H_ +#pragma once #include "node.h" #include "node_buffer.h" @@ -32,13 +31,13 @@ #include "async_wrap-inl.h" #include "env-inl.h" #include "stream_base-inl.h" -#include "util-inl.h" #include "v8.h" +#include "http_parser_adaptor.h" + #include // free() #include // strdup(), strchr() -#include "http_parser_adaptor.h" // This is a binding to http_parser (https://github.com/nodejs/http-parser) // The goal is to decouple sockets from parsing for more javascript-level @@ -978,5 +977,3 @@ void InitializeHttpParser(Local target, } // anonymous namespace } // namespace node - -#endif // SRC_NODE_HTTP_PARSER_IMPL_H_ diff --git a/src/node_messaging.cc b/src/node_messaging.cc index 4fda880c1c3a0e..e6e7f743de27ad 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -1,11 +1,10 @@ #include "node_messaging.h" + #include "async_wrap-inl.h" -#include "async_wrap.h" #include "debug_utils.h" #include "node_buffer.h" #include "node_errors.h" #include "node_process.h" -#include "util-inl.h" #include "util.h" using v8::Array; diff --git a/src/node_options.cc b/src/node_options.cc index 85f0d447109d10..b208488a69ee46 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -1,6 +1,8 @@ +#include "node_options.h" // NOLINT(build/include_inline) +#include "node_options-inl.h" + #include "env-inl.h" #include "node_binding.h" -#include "node_options-inl.h" #include // strtoul, errno diff --git a/src/node_os.cc b/src/node_os.cc index cbf2a3040969a4..6ba4e54a3be649 100644 --- a/src/node_os.cc +++ b/src/node_os.cc @@ -23,19 +23,19 @@ #include "string_bytes.h" #include "util.h" -#include -#include -#include - #ifdef __MINGW32__ # include #endif // __MINGW32__ #ifdef __POSIX__ -# include // PATH_MAX on Solaris. # include // gethostname, sysconf +# include // PATH_MAX on Solaris. #endif // __POSIX__ +#include +#include +#include + namespace node { namespace os { diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index b46735bc791dd4..3cf2670a88bac2 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -1,5 +1,4 @@ #include "base_object-inl.h" -#include "base_object.h" #include "env-inl.h" #include "node.h" #include "node_errors.h" diff --git a/src/node_report.cc b/src/node_report.cc index 5cbfd27d7694c4..a319f51fdb1a9e 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -8,8 +8,11 @@ #include "node_metadata.h" #include "zlib.h" -#include -#include +#ifdef __APPLE__ +#include +#endif + +#include #ifdef _WIN32 #include @@ -18,31 +21,19 @@ #include #include #include -#include -#else +#else // !_WIN32 #include -// Get the standard printf format macros for C99 stdint types. -#ifndef __STDC_FORMAT_MACROS -#define __STDC_FORMAT_MACROS -#endif #include #include -#include #endif -#include #include #include +#include +#include +#include #include -#ifndef _MSC_VER -#include -#endif - -#ifdef __APPLE__ -#include -#endif - #ifndef _WIN32 extern char** environ; #endif diff --git a/src/node_report.h b/src/node_report.h index 18135f5666c68a..9ba45053996827 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -1,26 +1,10 @@ -#ifndef SRC_NODE_REPORT_H_ -#define SRC_NODE_REPORT_H_ +#pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "node.h" +#include "node_buffer.h" +#include "uv.h" #include "v8.h" -#include -#include -#include -#include -#include -#include - #ifdef _WIN32 #include #else @@ -29,6 +13,20 @@ #include #endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + namespace report { #ifdef _WIN32 @@ -185,5 +183,3 @@ class JSONWriter { }; } // namespace report - -#endif // SRC_NODE_REPORT_H_ diff --git a/src/node_report_module.cc b/src/node_report_module.cc index 94894b0f5e5f9c..3317077e8b9814 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -5,12 +5,10 @@ #include "node_report.h" #include "util.h" -#include "env-inl.h" #include "handle_wrap.h" #include "node_buffer.h" #include "stream_base-inl.h" #include "stream_wrap.h" -#include "util-inl.h" #include #include diff --git a/src/node_url.cc b/src/node_url.cc index 2070b713ac3d60..5e241b76f12c7c 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -4,10 +4,10 @@ #include "node_i18n.h" #include "util.h" +#include +#include #include #include -#include -#include namespace node { diff --git a/src/node_win32_etw_provider.cc b/src/node_win32_etw_provider.cc index 8a854767d6aed8..5c45a8e2b8c82a 100644 --- a/src/node_win32_etw_provider.cc +++ b/src/node_win32_etw_provider.cc @@ -19,10 +19,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -#include "node_win32_etw_provider.h" -#include "node_etw_provider.h" +#include "node_win32_etw_provider.h" // NOLINT(build/include_inline) #include "node_win32_etw_provider-inl.h" +#include "node_etw_provider.h" + namespace node { using v8::JitCodeEvent; diff --git a/src/node_worker.cc b/src/node_worker.cc index f9a0502aeecf76..c5ccb74a6fd3c5 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -4,8 +4,6 @@ #include "node_buffer.h" #include "node_perf.h" #include "util.h" -#include "util-inl.h" -#include "async_wrap.h" #include "async_wrap-inl.h" #if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR diff --git a/src/node_zlib.cc b/src/node_zlib.cc index badac08449ee6b..ea8b0e2a7637ed 100644 --- a/src/node_zlib.cc +++ b/src/node_zlib.cc @@ -32,10 +32,11 @@ #include "brotli/decode.h" #include "zlib.h" +#include + #include #include #include -#include #include namespace node { diff --git a/src/sharedarraybuffer_metadata.cc b/src/sharedarraybuffer_metadata.cc index 5c58fac3ccf257..722a20065f308e 100644 --- a/src/sharedarraybuffer_metadata.cc +++ b/src/sharedarraybuffer_metadata.cc @@ -1,10 +1,10 @@ #include "sharedarraybuffer_metadata.h" -#include -#include "base_object.h" #include "base_object-inl.h" #include "node_errors.h" +#include + using v8::Context; using v8::Function; using v8::FunctionTemplate; diff --git a/src/stream_base.cc b/src/stream_base.cc index 8eccca1a3e87a1..7aef9ba96d14a0 100644 --- a/src/stream_base.cc +++ b/src/stream_base.cc @@ -1,3 +1,4 @@ +#include "stream_base.h" // NOLINT(build/include_inline) #include "stream_base-inl.h" #include "stream_wrap.h" diff --git a/src/string_decoder.cc b/src/string_decoder.cc index 1441ca86936a5a..90ceb2c222e319 100644 --- a/src/string_decoder.cc +++ b/src/string_decoder.cc @@ -1,7 +1,9 @@ +#include "string_decoder.h" // NOLINT(build/include_inline) +#include "string_decoder-inl.h" + #include "env-inl.h" #include "node_buffer.h" #include "string_bytes.h" -#include "string_decoder-inl.h" using v8::Array; using v8::ArrayBufferView; diff --git a/src/tracing/node_trace_writer.cc b/src/tracing/node_trace_writer.cc index 3b07504acc44ee..8f053efe93324b 100644 --- a/src/tracing/node_trace_writer.cc +++ b/src/tracing/node_trace_writer.cc @@ -1,10 +1,10 @@ #include "tracing/node_trace_writer.h" -#include -#include - #include "util-inl.h" +#include +#include + namespace node { namespace tracing { diff --git a/src/tracing/traced_value.cc b/src/tracing/traced_value.cc index 3eb21a11c939d7..df4d862fb6b9c2 100644 --- a/src/tracing/traced_value.cc +++ b/src/tracing/traced_value.cc @@ -4,16 +4,16 @@ #include "tracing/traced_value.h" -#include -#include -#include -#include - #if defined(NODE_HAVE_I18N_SUPPORT) #include #include #endif +#include +#include +#include +#include + #if defined(_STLP_VENDOR_CSTD) // STLPort doesn't import fpclassify into the std namespace. #define FPCLASSIFY_NAMESPACE diff --git a/src/util.cc b/src/util.cc index 223e0e87720853..f070401934f78b 100644 --- a/src/util.cc +++ b/src/util.cc @@ -19,14 +19,17 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -#include -#include +#include "util.h" + #include "node_buffer.h" #include "node_errors.h" #include "node_internals.h" #include "string_bytes.h" #include "uv.h" +#include +#include + namespace node { using v8::ArrayBufferView; diff --git a/test/cctest/test_util.cc b/test/cctest/test_util.cc index db19d92cbd9c19..7a0da1e6185d51 100644 --- a/test/cctest/test_util.cc +++ b/test/cctest/test_util.cc @@ -1,6 +1,4 @@ -#include "util.h" #include "util-inl.h" - #include "gtest/gtest.h" TEST(UtilTest, ListHead) { diff --git a/test/node-api/test_uv_loop/test_uv_loop.cc b/test/node-api/test_uv_loop/test_uv_loop.cc index c5eaac52736240..51b10f32bb7900 100644 --- a/test/node-api/test_uv_loop/test_uv_loop.cc +++ b/test/node-api/test_uv_loop/test_uv_loop.cc @@ -1,9 +1,11 @@ +#include "../../js-native-api/common.h" + #include #include -#include + +#include #include -#include -#include "../../js-native-api/common.h" +#include template void* SetImmediate(napi_env env, T&& cb) { diff --git a/tools/cpplint.py b/tools/cpplint.py index bae270747670be..034670dad9138a 100755 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -282,9 +282,10 @@ def GetNonHeaderExtensions(): 'build/forward_decl', 'build/header_guard', 'build/include', - 'build/include_subdir', 'build/include_alpha', + 'build/include_inline', 'build/include_order', + 'build/include_subdir', 'build/include_what_you_use', 'build/namespaces_literals', 'build/namespaces', @@ -356,8 +357,9 @@ def GetNonHeaderExtensions(): # off by default (i.e., categories that must be enabled by the --filter= flags). # All entries here should start with a '-' or '+', as in the --filter= flag. _DEFAULT_FILTERS = [ - '-build/include', + '-build/include_alpha', '-build/include_subdir', + '-build/include_what_you_use', '-legal/copyright', ] @@ -834,9 +836,9 @@ class _IncludeState(object): # needs to move backwards, CheckNextIncludeOrder will raise an error. _INITIAL_SECTION = 0 _MY_H_SECTION = 1 - _C_SECTION = 2 - _CPP_SECTION = 3 - _OTHER_H_SECTION = 4 + _OTHER_H_SECTION = 2 + _C_SECTION = 3 + _CPP_SECTION = 4 _TYPE_NAMES = { _C_SYS_HEADER: 'C system header', @@ -848,9 +850,9 @@ class _IncludeState(object): _SECTION_NAMES = { _INITIAL_SECTION: "... nothing. (This can't be an error.)", _MY_H_SECTION: 'a header this file implements', + _OTHER_H_SECTION: 'other header', _C_SECTION: 'C system header', _CPP_SECTION: 'C++ system header', - _OTHER_H_SECTION: 'other header', } def __init__(self): @@ -2130,7 +2132,7 @@ def CheckInlineHeader(filename, include_state, error): for name in bad_headers: err = '%s includes both %s and %s-inl.h' % (filename, name, name) linenum = all_headers[name] - error(filename, linenum, 'build/include', 5, err) + error(filename, linenum, 'build/include_inline', 5, err) def CheckForNewlineAtEOF(filename, lines, error): @@ -4768,11 +4770,10 @@ def CheckIncludeLine(filename, clean_lines, linenum, include_state, error): include_state.include_list[-1].append((include, linenum)) # We want to ensure that headers appear in the right order: - # 1) for foo.cc, foo.h (preferred location) - # 2) c system files - # 3) cpp system files - # 4) for foo.cc, foo.h (deprecated location) - # 5) other google headers + # 1) for foo.cc, foo.h + # 2) other project headers + # 3) c system files + # 4) cpp system files # # We classify each include statement as one of those 5 types # using a number of techniques. The include_state object keeps