commit f70a450a7f6aaaef6d44a6a49c24edb8ad5a7fdb Author: Sean McGinnis Date: Wed Jul 22 14:02:08 2020 -0500 Fix H903 hacking_no_cr Hacking check was failing to match on lines that should have been flagged an issue. This fixes the check and adds unit tests to validate the check is working as expected. Change-Id: I20e3b54a0c5830565e5d4bbb3bbc8b4921c82fb2 Signed-off-by: Sean McGinnis diff --git a/hacking/checks/other.py b/hacking/checks/other.py index b4bfb4e..99aaea7 100644 --- a/hacking/checks/other.py +++ b/hacking/checks/other.py @@ -28,9 +28,8 @@ def hacking_no_cr(physical_line): # upstream fix H903 import os\r\nimport sys """ - pos = physical_line.find('\r') - if pos != -1 and pos == (len(physical_line) - 2): - return (pos, "H903: Windows style line endings not allowed in code") + if '\r' in physical_line: + yield (0, "H903: Windows style line endings not allowed in code") @core.flake8ext diff --git a/hacking/tests/checks/test_other.py b/hacking/tests/checks/test_other.py index c50b605..e7227ed 100644 --- a/hacking/tests/checks/test_other.py +++ b/hacking/tests/checks/test_other.py @@ -37,3 +37,13 @@ class OthersTestCase(tests.TestCase): else: self.assertCheckPasses(other.hacking_delayed_string_interpolation, line, noqa) + + @ddt.unpack + @ddt.data( + (False, 'import os\r\nimport sys'), + (True, 'import os\nimport sys')) + def test_H903_hacking_no_cr(self, passes, line): + if passes: + self.assertCheckPasses(other.hacking_no_cr, line) + else: + self.assertCheckFails(other.hacking_no_cr, line)