Skip to content

Commit

Permalink
tools: update cpplint to check for inline headers
Browse files Browse the repository at this point in the history
Update cpplint.py to check for inline headers when the corresponding
header is already included.

PR-URL: nodejs/node#21521
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
ryzokuken committed Jul 29, 2018
1 parent 5842366 commit fc81e80
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit fc81e80

Please sign in to comment.