diff options
author | Mike Frysinger <vapier@google.com> | 2023-06-08 23:42:35 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@google.com> | 2023-06-10 23:32:38 +0000 |
commit | 13285896d0e51447e5d7e20fb21d89d091d911b9 (patch) | |
tree | b548bea05014c4f408290fe561b30939907ab1c3 | |
parent | 5c139d804bbe48ad3e7ac2184c313b9ac7be9ce7 (diff) | |
download | repohooks-13285896d0e51447e5d7e20fb21d89d091d911b9.tar.gz |
hooks: ktfmt: drop custom format suggestion
Rely on the common framework to display & run fixup commands.
Bug: None
Test: unittests
Change-Id: Id3714df6b6c5c2654cf43cff78fb8226e4ec3629
-rw-r--r-- | rh/hooks.py | 11 | ||||
-rwxr-xr-x | rh/hooks_unittest.py | 6 |
2 files changed, 5 insertions, 12 deletions
diff --git a/rh/hooks.py b/rh/hooks.py index 1d7eb3f..c90c0a3 100644 --- a/rh/hooks.py +++ b/rh/hooks.py @@ -425,15 +425,10 @@ def check_ktfmt(project, commit, _desc, diff, options=None): ('${PREUPLOAD_FILES}',), filtered) result = _run(cmd) if result.stdout: - paths = [os.path.join(project.dir, x.file) for x in filtered] fixup_cmd = [ktfmt] + args - error = ( - '\nKotlin files need formatting.\n' + - 'To reformat the kotlin files in this commit:\n' + - rh.shell.cmd_to_str(fixup_cmd + paths) - ) - return [rh.results.HookResult('ktfmt', project, commit, error=error, - files=paths, fixup_cmd=fixup_cmd)] + return [rh.results.HookResult( + 'ktfmt', project, commit, error='Formatting errors detected', + files=[x.file for x in filtered], fixup_cmd=fixup_cmd)] return None diff --git a/rh/hooks_unittest.py b/rh/hooks_unittest.py index 901eca1..003057e 100755 --- a/rh/hooks_unittest.py +++ b/rh/hooks_unittest.py @@ -829,16 +829,14 @@ class BuiltinHooksTests(unittest.TestCase): rh.git.RawDiffEntry(file='baz/blah.kt')] ret = rh.hooks.check_ktfmt( self.project, 'commit', 'desc', diff, options=self.options) - self.assertListEqual(ret[0].files, ['/.../repo/dir/foo.kt', - '/.../repo/dir/baz/blah.kt']) + self.assertListEqual(ret[0].files, ['foo.kt', 'baz/blah.kt']) diff = [rh.git.RawDiffEntry(file='foo/f1.kt'), rh.git.RawDiffEntry(file='bar/f2.kt'), rh.git.RawDiffEntry(file='baz/f2.kt')] ret = rh.hooks.check_ktfmt(self.project, 'commit', 'desc', diff, options=rh.hooks.HookOptions('hook name', [ '--include-dirs=foo,baz'], {})) - self.assertListEqual(ret[0].files, ['/.../repo/dir/foo/f1.kt', - '/.../repo/dir/baz/f2.kt']) + self.assertListEqual(ret[0].files, ['foo/f1.kt', 'baz/f2.kt']) def test_pylint(self, mock_check, _mock_run): """Verify the pylint builtin hook.""" |