diff --git a/bin/cinder-rtstool b/bin/cinder-rtstool index a4300fc5cc0..fd61d263559 100755 --- a/bin/cinder-rtstool +++ b/bin/cinder-rtstool @@ -1,5 +1,4 @@ #!/usr/bin/env python -# vim: et tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2012 - 2013 Red Hat, Inc. # All Rights Reserved. diff --git a/cinder/hacking/checks.py b/cinder/hacking/checks.py index fc213bc9f24..053cf90e525 100644 --- a/cinder/hacking/checks.py +++ b/cinder/hacking/checks.py @@ -34,6 +34,21 @@ UNDERSCORE_IMPORT_FILES = [] log_translation = re.compile( r"(.)*LOG\.(audit|error|info|warn|warning|critical|exception)_\(\s*('|\")") string_translation = re.compile(r"(.)*_\(\s*('|\")") +vi_header_re = re.compile(r"^#\s+vim?:.+") + + +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. + + N314 + """ + # 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, "N314: Don't put vi configuration in source files" def no_translate_debug_logs(logical_line, filename): @@ -80,6 +95,7 @@ def check_explicit_underscore_import(logical_line, filename): def factory(register): + register(no_vi_headers) register(no_translate_debug_logs) register(no_mutable_default_args) register(check_explicit_underscore_import) diff --git a/cinder/openstack/__init__.py b/cinder/openstack/__init__.py index 0a3b98867a2..00a266a5977 100644 --- a/cinder/openstack/__init__.py +++ b/cinder/openstack/__init__.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright (c) 2011 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may diff --git a/cinder/tests/api/contrib/test_used_limits.py b/cinder/tests/api/contrib/test_used_limits.py index 4511cc83af1..86971bf8311 100644 --- a/cinder/tests/api/contrib/test_used_limits.py +++ b/cinder/tests/api/contrib/test_used_limits.py @@ -1,5 +1,3 @@ -# vim: tabstop=5 shiftwidth=4 softtabstop=4 - # Copyright 2012 OpenStack Foundation # All Rights Reserved. # diff --git a/cinder/tests/test_hacking.py b/cinder/tests/test_hacking.py index a58db7182a6..71793401e3c 100644 --- a/cinder/tests/test_hacking.py +++ b/cinder/tests/test_hacking.py @@ -49,6 +49,23 @@ class HackingTestCase(test.TestCase): should pass. """ + def test_no_vi_headers(self): + + lines = ['Line 1\n', 'Line 2\n', 'Line 3\n', 'Line 4\n', 'Line 5\n' + 'Line 6\n', 'Line 7\n', 'Line 8\n', 'Line 9\n', 'Line 10\n'] + + self.assertEqual(checks.no_vi_headers( + "Test string foo", 1, lines), None) + self.assertEqual(len(list(checks.no_vi_headers( + "# vim: et tabstop=4 shiftwidth=4 softtabstop=4", + 2, lines))), 2) + self.assertEqual(len(list(checks.no_vi_headers( + "# vim: et tabstop=4 shiftwidth=4 softtabstop=4", + 8, lines))), 2) + self.assertEqual(checks.no_vi_headers( + "Test end string for vi", + 9, lines), None) + def test_no_translate_debug_logs(self): self.assertEqual(len(list(checks.no_translate_debug_logs( "LOG.debug(_('foo'))", "cinder/scheduler/foo.py"))), 1)