diff --git a/doc/api/addons.md b/doc/api/addons.md index a2bee79cc3de3f..0d8261d7c66275 100644 --- a/doc/api/addons.md +++ b/doc/api/addons.md @@ -271,9 +271,9 @@ The following `addon.cc` uses `AddEnvironmentCleanupHook`: ```cpp // addon.cc +#include #include #include -#include using node::AddEnvironmentCleanupHook; using v8::HandleScope; diff --git a/src/node_report.cc b/src/node_report.cc index e7bfe7fef09d14..3b97bb705b6985 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -12,8 +12,8 @@ #ifdef _WIN32 #include #else // !_WIN32 -#include #include +#include #include #endif diff --git a/test/addons/async-cleanup-hook/binding.cc b/test/addons/async-cleanup-hook/binding.cc index d18da7a094f71a..0a11220850fca2 100644 --- a/test/addons/async-cleanup-hook/binding.cc +++ b/test/addons/async-cleanup-hook/binding.cc @@ -1,6 +1,6 @@ -#include #include #include +#include void MustNotCall(void* arg, void(*cb)(void*), void* cbarg) { assert(0); diff --git a/test/addons/openssl-binding/binding.cc b/test/addons/openssl-binding/binding.cc index 05849b6c14fe31..79472dd7f25272 100644 --- a/test/addons/openssl-binding/binding.cc +++ b/test/addons/openssl-binding/binding.cc @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include namespace { diff --git a/test/addons/openssl-client-cert-engine/testengine.cc b/test/addons/openssl-client-cert-engine/testengine.cc index 7ccb56e08015a7..95712901e69c8b 100644 --- a/test/addons/openssl-client-cert-engine/testengine.cc +++ b/test/addons/openssl-client-cert-engine/testengine.cc @@ -1,10 +1,10 @@ +#include +#include + #include #include #include -#include -#include - #include #include #include diff --git a/test/addons/openssl-key-engine/testkeyengine.cc b/test/addons/openssl-key-engine/testkeyengine.cc index e1dc22164ac4c1..704027ba5a43d2 100644 --- a/test/addons/openssl-key-engine/testkeyengine.cc +++ b/test/addons/openssl-key-engine/testkeyengine.cc @@ -1,10 +1,10 @@ +#include +#include + #include #include #include -#include -#include - #include #include #include diff --git a/test/addons/stringbytes-external-exceed-max/binding.cc b/test/addons/stringbytes-external-exceed-max/binding.cc index 0e3cd3f4d0a1a1..c452a093849213 100644 --- a/test/addons/stringbytes-external-exceed-max/binding.cc +++ b/test/addons/stringbytes-external-exceed-max/binding.cc @@ -1,6 +1,6 @@ -#include #include #include +#include #ifdef _AIX // AIX allows over-allocation, and will SIGKILL when the allocated pages are diff --git a/test/addons/worker-addon/binding.cc b/test/addons/worker-addon/binding.cc index 63728fa9a4b76d..a5f9d8b3f835d8 100644 --- a/test/addons/worker-addon/binding.cc +++ b/test/addons/worker-addon/binding.cc @@ -1,9 +1,9 @@ -#include #include -#include -#include #include #include +#include +#include +#include using v8::Context; using v8::Function; diff --git a/test/addons/zlib-binding/binding.cc b/test/addons/zlib-binding/binding.cc index 53d25642f0d563..3a958f26af1ac6 100644 --- a/test/addons/zlib-binding/binding.cc +++ b/test/addons/zlib-binding/binding.cc @@ -1,7 +1,7 @@ #include #include -#include #include +#include namespace { diff --git a/tools/cpplint.py b/tools/cpplint.py index 1502ec3e057e1b..1c08ebb982ff78 100755 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -59,7 +59,7 @@ # if empty, use defaults _valid_extensions = set([]) -__VERSION__ = '1.4.6' +__VERSION__ = '1.5.0' try: xrange # Python 2 @@ -518,6 +518,120 @@ 'cwctype', ]) +# C headers +_C_HEADERS = frozenset([ + # System C headers + 'assert.h', + 'complex.h', + 'ctype.h', + 'errno.h', + 'fenv.h', + 'float.h', + 'inttypes.h', + 'iso646.h', + 'limits.h', + 'locale.h', + 'math.h', + 'setjmp.h', + 'signal.h', + 'stdalign.h', + 'stdarg.h', + 'stdatomic.h', + 'stdbool.h', + 'stddef.h', + 'stdint.h', + 'stdio.h', + 'stdlib.h', + 'stdnoreturn.h', + 'string.h', + 'tgmath.h', + 'threads.h', + 'time.h', + 'uchar.h', + 'wchar.h', + 'wctype.h', + # POSIX C headers + 'aio.h', + 'arpa/inet.h', + 'cpio.h', + 'dirent.h', + 'dlfcn.h', + 'fcntl.h', + 'fmtmsg.h', + 'fnmatch.h', + 'ftw.h', + 'glob.h', + 'grp.h', + 'iconv.h', + 'langinfo.h', + 'libgen.h', + 'monetary.h', + 'mqueue.h', + 'ndbm.h', + 'net/if.h', + 'netdb.h', + 'netinet/in.h', + 'netinet/tcp.h', + 'nl_types.h', + 'poll.h', + 'pthread.h', + 'pwd.h', + 'regex.h', + 'sched.h', + 'search.h', + 'semaphore.h', + 'setjmp.h', + 'signal.h', + 'spawn.h', + 'strings.h', + 'stropts.h', + 'syslog.h', + 'tar.h', + 'termios.h', + 'trace.h', + 'ulimit.h', + 'unistd.h', + 'utime.h', + 'utmpx.h', + 'wordexp.h', + # GNUlib headers + 'a.out.h', + 'aliases.h', + 'alloca.h', + 'ar.h', + 'argp.h', + 'argz.h', + 'byteswap.h', + 'crypt.h', + 'endian.h', + 'envz.h', + 'err.h', + 'error.h', + 'execinfo.h', + 'fpu_control.h', + 'fstab.h', + 'fts.h', + 'getopt.h', + 'gshadow.h', + 'ieee754.h', + 'ifaddrs.h', + 'libintl.h', + 'mcheck.h', + 'mntent.h', + 'obstack.h', + 'paths.h', + 'printf.h', + 'pty.h', + 'resolv.h', + 'shadow.h', + 'sysexits.h', + 'ttyent.h', + # Hardware specific headers + 'arm_neon.h', + 'emmintrin.h', + 'xmmintin.h', + ]) + # Type names _TYPES = re.compile( r'^(?:' @@ -604,9 +718,10 @@ # _IncludeState.CheckNextIncludeOrder(). _C_SYS_HEADER = 1 _CPP_SYS_HEADER = 2 -_LIKELY_MY_HEADER = 3 -_POSSIBLE_MY_HEADER = 4 -_OTHER_HEADER = 5 +_OTHER_SYS_HEADER = 3 +_LIKELY_MY_HEADER = 4 +_POSSIBLE_MY_HEADER = 5 +_OTHER_HEADER = 6 # These constants define the current inline assembly state _NO_ASM = 0 # Outside of inline assembly block @@ -863,12 +978,15 @@ class _IncludeState(object): _INITIAL_SECTION = 0 _MY_H_SECTION = 1 _OTHER_H_SECTION = 2 - _C_SECTION = 3 - _CPP_SECTION = 4 + _OTHER_SYS_SECTION = 3 + _C_SECTION = 4 + _CPP_SECTION = 5 + _TYPE_NAMES = { _C_SYS_HEADER: 'C system header', _CPP_SYS_HEADER: 'C++ system header', + _OTHER_SYS_HEADER: 'other system header', _LIKELY_MY_HEADER: 'header this file implements', _POSSIBLE_MY_HEADER: 'header this file may implement', _OTHER_HEADER: 'other header', @@ -876,9 +994,10 @@ 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_SYS_SECTION: 'other system header', + _OTHER_H_SECTION: 'other header', } def __init__(self): @@ -991,6 +1110,12 @@ def CheckNextIncludeOrder(self, header_type): else: self._last_header = '' return error_message + elif header_type == _OTHER_SYS_HEADER: + if self._section <= self._OTHER_SYS_SECTION: + self._section = self._OTHER_SYS_SECTION + else: + self._last_header = '' + return error_message elif header_type == _LIKELY_MY_HEADER: if self._section <= self._MY_H_SECTION: self._section = self._MY_H_SECTION @@ -4820,6 +4945,8 @@ def _ClassifyInclude(fileinfo, include, is_system): _C_SYS_HEADER >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'string', True) _CPP_SYS_HEADER + >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', True) + _OTHER_SYS_HEADER >>> _ClassifyInclude(FileInfo('foo/foo.cc'), 'foo/foo.h', False) _LIKELY_MY_HEADER >>> _ClassifyInclude(FileInfo('foo/foo_unknown_extension.cc'), @@ -4832,6 +4959,9 @@ def _ClassifyInclude(fileinfo, include, is_system): # those already checked for above. is_cpp_h = include in _CPP_HEADERS + # Mark include as C header if in list or of type 'sys/*.h'. + is_c_h = include in _C_HEADERS or Search(r'sys\/.*\.h', include) + # Headers with C++ extensions shouldn't be considered C system headers if is_system and os.path.splitext(include)[1] in ['.hpp', '.hxx', '.h++']: is_system = False @@ -4839,8 +4969,10 @@ def _ClassifyInclude(fileinfo, include, is_system): if is_system: if is_cpp_h: return _CPP_SYS_HEADER - else: + if is_c_h: return _C_SYS_HEADER + else: + return _OTHER_SYS_HEADER # If the target file and the include we're checking share a # basename when we drop common extensions, and the include