Introduce T106 rule for vi modelines

We don't need to have the vi modelines in each source file anymore.
We've already fixed them several times.
 https://review.openstack.org/#/c/66507/
 https://review.openstack.org/#/c/68552/
 https://review.openstack.org/#/c/69318/
 https://review.openstack.org/#/c/70133/
However, newly some files still have it in its header. So we should
check it automatically with our HACKING rule.
This commit introduces T106 rule for that.

Note: This code is copied from Nova's hacking rule.
   Change-Id: I347307a5145b2760c69085b6ca850d6a9137ffc6

Change-Id: I5c94ef041a39c2377ba6321ace8934f324287bcf
Closes-Bug: #1229324
This commit is contained in:
Masayuki Igawa 2014-02-19 14:00:01 +09:00
parent 1cee3c662a
commit fcacf96204
2 changed files with 17 additions and 0 deletions

View File

@ -11,6 +11,7 @@ Tempest Specific Commandments
- [T102] Cannot import OpenStack python clients in tempest/api tests
- [T104] Scenario tests require a services decorator
- [T105] Unit tests cannot use setUpClass
- [T106] vim configuration should not be kept in source files.
Test Data/Configuration
-----------------------

View File

@ -21,6 +21,7 @@ PYTHON_CLIENT_RE = re.compile('import (%s)client' % '|'.join(PYTHON_CLIENTS))
TEST_DEFINITION = re.compile(r'^\s*def test.*')
SETUPCLASS_DEFINITION = re.compile(r'^\s*def setUpClass')
SCENARIO_DECORATOR = re.compile(r'\s*@.*services\(')
VI_HEADER_RE = re.compile(r"^#\s+vim?:.+")
def import_no_clients_in_api(physical_line, filename):
@ -58,7 +59,22 @@ def no_setupclass_for_unit_tests(physical_line, filename):
"T105: setUpClass can not be used with unit tests")
def no_vi_headers(physical_line, line_number, lines):
"""Check for vi editor configuration in source files.
By default vi modelines can only appear in the first or
last 5 lines of a source file.
T106
"""
# NOTE(gilliard): line_number is 1-indexed
if line_number <= 5 or line_number > len(lines) - 5:
if VI_HEADER_RE.match(physical_line):
return 0, "T106: Don't put vi configuration in source files"
def factory(register):
register(import_no_clients_in_api)
register(scenario_tests_need_service_tags)
register(no_setupclass_for_unit_tests)
register(no_vi_headers)