Check to see if a rule is suppressed. :param ruleNum: is the rule number in hundreds format :param file_path: File path of checked location :param linenr: Line number of checked location If the rule exists in the dict then check for a filename If th
(self, file_path, linenr, ruleNum)
| 4352 | ruleItemList.append(line_symbol) |
| 4353 | |
| 4354 | def isRuleSuppressed(self, file_path, linenr, ruleNum): |
| 4355 | """ |
| 4356 | Check to see if a rule is suppressed. |
| 4357 | |
| 4358 | :param ruleNum: is the rule number in hundreds format |
| 4359 | :param file_path: File path of checked location |
| 4360 | :param linenr: Line number of checked location |
| 4361 | |
| 4362 | If the rule exists in the dict then check for a filename |
| 4363 | If the filename is None then rule is suppressed globally |
| 4364 | for all files. |
| 4365 | If the filename exists then look for list of |
| 4366 | line number, symbol name tuples. If the list is None then |
| 4367 | the rule is suppressed for the entire file |
| 4368 | If the list of tuples exists then search the list looking for |
| 4369 | matching line numbers. Symbol names are currently ignored |
| 4370 | because they can include regular expressions. |
| 4371 | TODO: Support symbol names and expression matching. |
| 4372 | |
| 4373 | """ |
| 4374 | ruleIsSuppressed = False |
| 4375 | |
| 4376 | # Remove any prefix listed in command arguments from the filename. |
| 4377 | filename = None |
| 4378 | if file_path is not None: |
| 4379 | if self.filePrefix is not None: |
| 4380 | filename = remove_file_prefix(file_path, self.filePrefix) |
| 4381 | else: |
| 4382 | filename = os.path.basename(file_path) |
| 4383 | |
| 4384 | if ruleNum in self.suppressedRules: |
| 4385 | fileDict = self.suppressedRules[ruleNum] |
| 4386 | |
| 4387 | # a file name entry of None means that the rule is suppressed |
| 4388 | # globally |
| 4389 | if None in fileDict: |
| 4390 | ruleIsSuppressed = True |
| 4391 | else: |
| 4392 | # Does the filename match one of the names in |
| 4393 | # the file list |
| 4394 | if filename in fileDict: |
| 4395 | # Get the list of ruleItems |
| 4396 | ruleItemList = fileDict[filename] |
| 4397 | |
| 4398 | if None in ruleItemList: |
| 4399 | # Entry of None in the ruleItemList means the rule is |
| 4400 | # suppressed for all lines in the filename |
| 4401 | ruleIsSuppressed = True |
| 4402 | else: |
| 4403 | # Iterate though the the list of line numbers |
| 4404 | # and symbols looking for a match of the line |
| 4405 | # number. Matching the symbol is a TODO: |
| 4406 | for each in ruleItemList: |
| 4407 | if each is not None: |
| 4408 | if each[0] == linenr: |
| 4409 | ruleIsSuppressed = True |
| 4410 | |
| 4411 | return ruleIsSuppressed |
no test coverage detected