From 43acc5e28f18538e9551e6daaa73aedb1a5aef41 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 25 Jun 2018 17:02:22 +0530 Subject: [PATCH 1/4] wip-lint --- tools/cpplint.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tools/cpplint.py b/tools/cpplint.py index a4f786f01a941f..683c542c0679ae 100644 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -1895,6 +1895,27 @@ 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.""" + + # Iterate over all headers, looking for any inline headers + for section_list in include_state.include_list: + for header in section_list: + # Proceed further for only inline headers + m = Match(r'^(.+)-inl.h$', header[0]) + if m: + name = '%s.h'.format(m.group(0)) + # 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])) + + + + def CheckForNewlineAtEOF(filename, lines, error): """Logs an error if there is no newline char at the end of the file. @@ -5861,6 +5882,8 @@ def ProcessFileData(filename, file_extension, lines, error, CheckForNewlineAtEOF(filename, lines, error) + CheckInlineHeader(filename, lines, error) + def ProcessConfigOverrides(filename): """ Loads the configuration files and processes the config overrides. From 4ce5702c0da516d98a2ba1a1760597c3520694d9 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 25 Jun 2018 17:28:55 +0530 Subject: [PATCH 2/4] wip2 --- tools/cpplint.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/cpplint.py b/tools/cpplint.py index 683c542c0679ae..8a821c41a6d2c9 100644 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -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 def CheckForNewlineAtEOF(filename, lines, error): @@ -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. From f0316ce32319882dd2815748b6f9506ed8fdaae2 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Tue, 26 Jun 2018 15:32:10 +0530 Subject: [PATCH 3/4] use cleaner code --- tools/cpplint.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tools/cpplint.py b/tools/cpplint.py index 8a821c41a6d2c9..a5e95c94d9e6d6 100644 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -1898,20 +1898,15 @@ def CheckForBadCharacters(filename, lines, error): def CheckInlineHeader(filename, include_state, error): """Logs an error if both a header and its inline variant are included.""" - # Iterate over all headers, looking for any inline headers - for section_list in include_state.include_list: - for header in section_list: - # Proceed further for only inline headers - m = Match(r'^(.+)-inl.h$', header[0]) - if m: - 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: - err = '%s includes both %s and %s' % (filename, header[0], h[0]) - error(filename, h[1], 'build/include', 5, err) - print err + 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) + error(filename, all_headers[name], 'build/include', 5, err) def CheckForNewlineAtEOF(filename, lines, error): From 1798955bd3167666e0c40f3eb0477920ee840080 Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Wed, 27 Jun 2018 23:48:28 +0530 Subject: [PATCH 4/4] add a bit of clarity --- tools/cpplint.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/cpplint.py b/tools/cpplint.py index a5e95c94d9e6d6..b5e2d16a3faf92 100644 --- a/tools/cpplint.py +++ b/tools/cpplint.py @@ -1906,7 +1906,8 @@ def CheckInlineHeader(filename, include_state, error): for name in bad_headers: err = '%s includes both %s and %s-inl.h' % (filename, name, name) - error(filename, all_headers[name], 'build/include', 5, err) + linenum = all_headers[name] + error(filename, linenum, 'build/include', 5, err) def CheckForNewlineAtEOF(filename, lines, error):