From fcacf96204590e57266e81ed13c8a60a60f1b73e Mon Sep 17 00:00:00 2001 From: Masayuki Igawa Date: Wed, 19 Feb 2014 14:00:01 +0900 Subject: [PATCH] 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 --- HACKING.rst | 1 + tempest/hacking/checks.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/HACKING.rst b/HACKING.rst index 3fa1ff5bb4..e7e765153f 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -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 ----------------------- diff --git a/tempest/hacking/checks.py b/tempest/hacking/checks.py index 2e499a2b17..55be60ac97 100644 --- a/tempest/hacking/checks.py +++ b/tempest/hacking/checks.py @@ -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)