MCPcopy Index your code
hub / github.com/nodejs/node / ErrorSuppressions

Class ErrorSuppressions

tools/cpplint.py:1000–1064  ·  view source on GitHub ↗

Class to track all error suppressions for cpplint

Source from the content-addressed store, hash-verified

998
999
1000class ErrorSuppressions:
1001 """Class to track all error suppressions for cpplint"""
1002
1003 class LineRange:
1004 """Class to represent a range of line numbers for which an error is suppressed"""
1005
1006 def __init__(self, begin, end):
1007 self.begin = begin
1008 self.end = end
1009
1010 def __str__(self):
1011 return f"[{self.begin}-{self.end}]"
1012
1013 def __contains__(self, obj):
1014 return self.begin <= obj <= self.end
1015
1016 def ContainsRange(self, other):
1017 return self.begin <= other.begin and self.end >= other.end
1018
1019 def __init__(self):
1020 self._suppressions = collections.defaultdict(list)
1021 self._open_block_suppression = None
1022
1023 def _AddSuppression(self, category, line_range):
1024 suppressed = self._suppressions[category]
1025 if not (suppressed and suppressed[-1].ContainsRange(line_range)):
1026 suppressed.append(line_range)
1027
1028 def GetOpenBlockStart(self):
1029 """:return: The start of the current open block or `-1` if there is not an open block"""
1030 return self._open_block_suppression.begin if self._open_block_suppression else -1
1031
1032 def AddGlobalSuppression(self, category):
1033 """Add a suppression for `category` which is suppressed for the whole file"""
1034 self._AddSuppression(category, self.LineRange(0, math.inf))
1035
1036 def AddLineSuppression(self, category, linenum):
1037 """Add a suppression for `category` which is suppressed only on `linenum`"""
1038 self._AddSuppression(category, self.LineRange(linenum, linenum))
1039
1040 def StartBlockSuppression(self, category, linenum):
1041 """Start a suppression block for `category` on `linenum`. inclusive"""
1042 if self._open_block_suppression is None:
1043 self._open_block_suppression = self.LineRange(linenum, math.inf)
1044 self._AddSuppression(category, self._open_block_suppression)
1045
1046 def EndBlockSuppression(self, linenum):
1047 """End the current block suppression on `linenum`. inclusive"""
1048 if self._open_block_suppression:
1049 self._open_block_suppression.end = linenum
1050 self._open_block_suppression = None
1051
1052 def IsSuppressed(self, category, linenum):
1053 """:return: `True` if `category` is suppressed for `linenum`"""
1054 suppressed = self._suppressions[category] + self._suppressions[None]
1055 return any(linenum in lr for lr in suppressed)
1056
1057 def HasOpenBlock(self):

Callers 1

cpplint.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…