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

tools,src,test: bump cpplint to 1.5.0 #35719

Merged
merged 3 commits into from
Oct 23, 2020
Merged
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
2 changes: 1 addition & 1 deletion doc/api/addons.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ The following `addon.cc` uses `AddEnvironmentCleanupHook`:

```cpp
// addon.cc
#include <node.h>
#include <assert.h>
#include <stdlib.h>
#include <node.h>

using node::AddEnvironmentCleanupHook;
using v8::HandleScope;
Expand Down
2 changes: 1 addition & 1 deletion src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#ifdef _WIN32
#include <Windows.h>
#else // !_WIN32
#include <sys/resource.h>
#include <cxxabi.h>
#include <sys/resource.h>
#include <dlfcn.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion test/addons/async-cleanup-hook/binding.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <assert.h>
#include <node.h>
#include <uv.h>
#include <assert.h>

void MustNotCall(void* arg, void(*cb)(void*), void* cbarg) {
assert(0);
Expand Down
4 changes: 2 additions & 2 deletions test/addons/openssl-binding/binding.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <node.h>
#include <assert.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <node.h>
#include <assert.h>

namespace {

Expand Down
6 changes: 3 additions & 3 deletions test/addons/openssl-client-cert-engine/testengine.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <openssl/engine.h>
#include <openssl/pem.h>

#include <assert.h>
#include <string.h>
#include <stdlib.h>

#include <openssl/engine.h>
#include <openssl/pem.h>

#include <fstream>
#include <iterator>
#include <string>
Expand Down
6 changes: 3 additions & 3 deletions test/addons/openssl-key-engine/testkeyengine.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <openssl/engine.h>
#include <openssl/pem.h>

#include <assert.h>
#include <string.h>
#include <stdlib.h>

#include <openssl/engine.h>
#include <openssl/pem.h>

#include <fstream>
#include <iterator>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion test/addons/stringbytes-external-exceed-max/binding.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <node.h>
#include <v8.h>
#include <stdlib.h>

#ifdef _AIX
// AIX allows over-allocation, and will SIGKILL when the allocated pages are
Expand Down
6 changes: 3 additions & 3 deletions test/addons/worker-addon/binding.cc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <assert.h>
#include <node.h>
#include <stdio.h>
#include <stdlib.h>
#include <v8.h>
#include <uv.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

using v8::Context;
using v8::Function;
Expand Down
2 changes: 1 addition & 1 deletion test/addons/zlib-binding/binding.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <node.h>
#include <node_buffer.h>
#include <assert.h>
#include <zlib.h>
#include <assert.h>

namespace {

Expand Down
148 changes: 140 additions & 8 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
# if empty, use defaults
_valid_extensions = set([])

__VERSION__ = '1.4.6'
__VERSION__ = '1.5.0'

try:
xrange # Python 2
Expand Down Expand Up @@ -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'^(?:'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -863,22 +978,26 @@ 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',
}
_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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'),
Expand All @@ -4832,15 +4959,20 @@ 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

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
Expand Down