Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip2
  • Loading branch information
ryzokuken committed Jun 25, 2018
commit 4ce5702c0da516d98a2ba1a1760597c3520694d9
12 changes: 5 additions & 7 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1904,16 +1904,14 @@ def CheckInlineHeader(filename, include_state, error):
# Proceed further for only inline headers
m = Match(r'^(.+)-inl.h$', header[0])
if m:
name = '%s.h'.format(m.group(0))
name = '%s.h' % m.group(1)
# Look for the corresponding header
for sl in include_state.include_list:
for h in section_list:
if h[0] == name:
error(filename, h[1], 'build/include', 5,
'%s includes both %s and %s'.format(filename, header[0],
h[0]))


err = '%s includes both %s and %s' % (filename, header[0], h[0])
error(filename, h[1], 'build/include', 5, err)
print err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More succinct of way of doing it:

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())  # compute intersection

for name in bad_headers:
  # lineno = all_headers[name]

It's also slightly more idiomatic vis-a-vis other include checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis okay, will try this. That said, I'm more interested at this point to find out what's wrong with my solution? It might not be idiomatic, but it should work. Why does error not work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, is that your question? :-)

I assume you're testing it from the command line like this: python tools/cpplint.py src/*.cc?

Look for _DEFAULT_FILTERS: build/include is off by default. Pass --filter=build/include to test it, or --filter=+build/include to enable it in addition to the other rules.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bnoordhuis I was! That helped.



def CheckForNewlineAtEOF(filename, lines, error):
Expand Down Expand Up @@ -5882,7 +5880,7 @@ def ProcessFileData(filename, file_extension, lines, error,

CheckForNewlineAtEOF(filename, lines, error)

CheckInlineHeader(filename, lines, error)
CheckInlineHeader(filename, include_state, error)

def ProcessConfigOverrides(filename):
""" Loads the configuration files and processes the config overrides.
Expand Down