From fc81e801913de3e3f3c0c8e26c105f983a74e539 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 25 Jun 2018 17:02:22 +0530 Subject: [PATCH] tools: update cpplint to check for inline headers Update cpplint.py to check for inline headers when the corresponding header is already included. PR-URL: https://github.com/nodejs/node/pull/21521 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- tools/cpplint.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/cpplint.py b/tools/cpplint.py index a0f67a4ca8bc49..d96713aa80a1ff 100644 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -1900,6 +1900,21 @@ def CheckForBadCharacters(filename, lines, error): error(filename, linenum, 'readability/nul', 5, 'Line contains NUL byte.') +def CheckInlineHeader(filename, include_state, error): + """Logs an error if both a header and its inline variant are included.""" + + all_headers = dict(item for sublist in include_state.include_list + for item in sublist) + bad_headers = set('%s.h' % name[:-6] for name in all_headers.keys() + if name.endswith('-inl.h')) + bad_headers &= set(all_headers.keys()) + + 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) + + def CheckForNewlineAtEOF(filename, lines, error): """Logs an error if there is no newline char at the end of the file. @@ -5866,6 +5881,8 @@ def ProcessFileData(filename, file_extension, lines, error, CheckForNewlineAtEOF(filename, lines, error) + CheckInlineHeader(filename, include_state, error) + def ProcessConfigOverrides(filename): """ Loads the configuration files and processes the config overrides.