Commit a5d55bae authored by Ezio Melotti's avatar Ezio Melotti

Update the suspicious builder to detect unused rules, and remove currently unusued rules.

parent 44ea77bd
This diff is collapsed.
...@@ -68,6 +68,10 @@ class Rule: ...@@ -68,6 +68,10 @@ class Rule:
# None -> don't care # None -> don't care
self.issue = issue # the markup fragment that triggered this rule self.issue = issue # the markup fragment that triggered this rule
self.line = line # text of the container element (single line only) self.line = line # text of the container element (single line only)
self.used = False
def __repr__(self):
return '{0.docname},,{0.issue},{0.line}'.format(self)
...@@ -107,6 +111,12 @@ class CheckSuspiciousMarkupBuilder(Builder): ...@@ -107,6 +111,12 @@ class CheckSuspiciousMarkupBuilder(Builder):
doctree.walk(visitor) doctree.walk(visitor)
def finish(self): def finish(self):
unused_rules = [rule for rule in self.rules if not rule.used]
if unused_rules:
self.warn('Found %s/%s unused rules:' %
(len(unused_rules), len(self.rules)))
for rule in unused_rules:
self.info(repr(rule))
return return
def check_issue(self, line, lineno, issue): def check_issue(self, line, lineno, issue):
...@@ -131,6 +141,7 @@ class CheckSuspiciousMarkupBuilder(Builder): ...@@ -131,6 +141,7 @@ class CheckSuspiciousMarkupBuilder(Builder):
if (rule.lineno is not None) and \ if (rule.lineno is not None) and \
abs(rule.lineno - lineno) > 5: continue abs(rule.lineno - lineno) > 5: continue
# if it came this far, the rule matched # if it came this far, the rule matched
rule.used = True
return True return True
return False return False
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment