Skip to content

Commit

Permalink
Add hacking check H105: don't use author tags
Browse files Browse the repository at this point in the history
This check is based on the local hacking check 'NN315: Don't use author tags'
used in Nova.

Change-Id: Idaa2a39b27a142e645e8b062fc7c1023036fa9ea
  • Loading branch information
berendt committed Oct 8, 2014
1 parent 367a52e commit 4f015d9
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions HACKING.rst
Expand Up @@ -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():
Expand Down
19 changes: 19 additions & 0 deletions hacking/checks/comments.py
Expand Up @@ -16,6 +16,10 @@
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()'.
Expand Down Expand Up @@ -161,3 +165,18 @@ def _check_for_exact_apache(start, lines):
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")
16 changes: 16 additions & 0 deletions hacking/tests/checks/test_comments.py
Expand Up @@ -60,3 +60,19 @@ def test_H104_regex(self):
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'))
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -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
Expand Down

0 comments on commit 4f015d9

Please sign in to comment.