Skip to content
This repository was archived by the owner on Jul 13, 2019. It is now read-only.

Commit 0873670

Browse files
Marco Massenziotkruse
authored andcommitted
Added custom system headers section
1 parent a7c23c5 commit 0873670

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

cpplint.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@
139139
Examples:
140140
--extensions=hpp,cpp
141141
142+
custom_headers=header_prefix,...
143+
144+
Custom System Headers
145+
cpplint by default assumes that #include <foo/foo.h>
146+
is a "system header" due to the presence of the leading <
147+
We enable here the ability to define custom system
148+
headers, which will be classified in the correct order if they
149+
follow C/C++ system headers, but precede non-system headers.
150+
151+
ONLY USED IN CPPLINT.cfg
152+
153+
Example:
154+
155+
custom_headers = mesos,stout,process
156+
142157
cpplint.py supports per-directory configurations specified in CPPLINT.cfg
143158
files. CPPLINT.cfg file can contain a number of key=value pairs.
144159
Currently the following options are supported:
@@ -472,9 +487,10 @@
472487
# _IncludeState.CheckNextIncludeOrder().
473488
_C_SYS_HEADER = 1
474489
_CPP_SYS_HEADER = 2
475-
_LIKELY_MY_HEADER = 3
476-
_POSSIBLE_MY_HEADER = 4
477-
_OTHER_HEADER = 5
490+
_CUSTOM_SYS_HEADER = 3
491+
_LIKELY_MY_HEADER = 4
492+
_POSSIBLE_MY_HEADER = 5
493+
_OTHER_HEADER = 6
478494

479495
# These constants define the current inline assembly state
480496
_NO_ASM = 0 # Outside of inline assembly block
@@ -502,6 +518,10 @@
502518
# This is set by --linelength flag.
503519
_line_length = 80
504520

521+
# Custom System Headers
522+
# TODO(marco): verify that they are in the correct alpha order
523+
_custom_system_headers = []
524+
505525
try:
506526
xrange
507527
except NameError:
@@ -631,11 +651,13 @@ class _IncludeState(object):
631651
_MY_H_SECTION = 1
632652
_C_SECTION = 2
633653
_CPP_SECTION = 3
634-
_OTHER_H_SECTION = 4
654+
_CUSTSYS_SECTION = 4
655+
_OTHER_H_SECTION = 5
635656

636657
_TYPE_NAMES = {
637658
_C_SYS_HEADER: 'C system header',
638659
_CPP_SYS_HEADER: 'C++ system header',
660+
_CUSTOM_SYS_HEADER: 'Custome system header',
639661
_LIKELY_MY_HEADER: 'header this file implements',
640662
_POSSIBLE_MY_HEADER: 'header this file may implement',
641663
_OTHER_HEADER: 'other header',
@@ -645,6 +667,7 @@ class _IncludeState(object):
645667
_MY_H_SECTION: 'a header this file implements',
646668
_C_SECTION: 'C system header',
647669
_CPP_SECTION: 'C++ system header',
670+
_CUSTSYS_SECTION: 'Custome system header',
648671
_OTHER_H_SECTION: 'other header',
649672
}
650673

@@ -756,6 +779,9 @@ def CheckNextIncludeOrder(self, header_type):
756779
else:
757780
self._last_header = ''
758781
return error_message
782+
elif header_type == _CUSTOM_SYS_HEADER:
783+
if self._section <= self._CUSTSYS_SECTION:
784+
self._section = self._CUSTSYS_SECTION
759785
elif header_type == _LIKELY_MY_HEADER:
760786
if self._section <= self._MY_H_SECTION:
761787
self._section = self._MY_H_SECTION
@@ -4607,6 +4633,9 @@ def _ClassifyInclude(fileinfo, include, is_system):
46074633
is_cpp_h = include in _CPP_HEADERS
46084634

46094635
if is_system:
4636+
for prefix in _custom_system_headers:
4637+
if include.startswith(prefix):
4638+
return _CUSTOM_SYS_HEADER
46104639
if is_cpp_h:
46114640
return _CPP_SYS_HEADER
46124641
else:
@@ -6136,6 +6165,10 @@ def ProcessConfigOverrides(filename):
61366165
_line_length = int(val)
61376166
except ValueError:
61386167
sys.stderr.write('Line length must be numeric.')
6168+
elif name == 'custom_headers':
6169+
global _custom_system_headers
6170+
for prefix in val.split(','):
6171+
_custom_system_headers.append(prefix)
61396172
else:
61406173
sys.stderr.write(
61416174
'Invalid configuration option (%s) in file %s\n' %

0 commit comments

Comments
 (0)