Add hacking check H105: don't use author tags

This check is based on the local hacking check 'NN315: Don't use author tags'
used in Nova.

Change-Id: Idaa2a39b27a142e645e8b062fc7c1023036fa9ea
This commit is contained in:
Christian Berendt 2014-10-08 22:27:25 +02:00
parent 367a52e23a
commit 4f015d9e0f
4 changed files with 37 additions and 0 deletions

View File

@ -24,6 +24,7 @@ General
for line continuation.
- [H201] Do not write ``except:``, use ``except Exception:`` at the very least
- [H101] Include your name with TODOs as in ``# TODO(yourname)``
- [H105] Don't use author tags.
- Do not shadow a built-in or reserved word. Example::
def list():

View File

@ -16,6 +16,10 @@ import tokenize
from hacking import core
AUTHOR_TAG_RE = (re.compile("^\s*#\s*@?(a|A)uthor:"),
re.compile("^\.\.\s+moduleauthor::"))
@core.flake8ext
def hacking_todo_format(physical_line, tokens):
"""Check for 'TODO()'.
@ -161,3 +165,18 @@ under the License."""
print ("<license>!=<apache2>:\n'%s' !=\n'%s'" %
(content, stripped_apache2))
return False
@core.flake8ext
def hacking_no_author_tags(physical_line):
"""Check that no author tags are used.
H105 don't use author tags
"""
for regex in AUTHOR_TAG_RE:
if regex.match(physical_line):
physical_line = physical_line.lower()
pos = physical_line.find('moduleauthor')
if pos < 0:
pos = physical_line.find('author')
return (pos, "H105: Don't use author tags")

View File

@ -60,3 +60,19 @@ class CoreTestCase(tests.TestCase):
None,
['# foo'],
100))
def test_H105(self):
self.assertTrue(comments.hacking_no_author_tags(
'# @author: Foo Bar'))
self.assertTrue(comments.hacking_no_author_tags(
'# @Author: Foo Bar'))
self.assertTrue(comments.hacking_no_author_tags(
'# author: Foo Bar'))
self.assertTrue(comments.hacking_no_author_tags(
'# Author: Foo Bar'))
self.assertTrue(comments.hacking_no_author_tags(
'.. moduleauthor:: Foo Bar'))

View File

@ -32,6 +32,7 @@ flake8.extension =
H102 = hacking.checks.comments:hacking_has_license
H103 = hacking.checks.comments:hacking_has_correct_license
H104 = hacking.checks.comments:hacking_has_only_comments
H105 = hacking.checks.comments:hacking_no_author_tags
H201 = hacking.checks.except_checks:hacking_except_format
H202 = hacking.checks.except_checks:hacking_except_format_assert
H231 = hacking.checks.python23:hacking_python3x_except_compatible