From 391846efb6321a8391253034e49f5f596fde9593 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 30 Oct 2023 19:54:58 -0400 Subject: [PATCH] use the correct pre-commit config --- babi/linters/pre_commit.py | 10 ++++++++-- tests/linters/pre_commit_test.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/babi/linters/pre_commit.py b/babi/linters/pre_commit.py index d5ffc5c9..380608b4 100644 --- a/babi/linters/pre_commit.py +++ b/babi/linters/pre_commit.py @@ -63,10 +63,16 @@ def command(self, filename: str, scope: str) -> tuple[str, ...] | None: return None # not in a git repo! # no pre-commit config! - if not os.path.exists(os.path.join(root, '.pre-commit-config.yaml')): + cfg = os.path.join(root, '.pre-commit-config.yaml') + if not os.path.exists(cfg): return None - return ('pre-commit', 'run', '--color=never', '--files', filename) + return ( + 'pre-commit', 'run', + '--color=never', + '--config', cfg, + '--files', filename, + ) def parse(self, filename: str, output: str) -> tuple[linting.Error, ...]: root = self._root(filename) diff --git a/tests/linters/pre_commit_test.py b/tests/linters/pre_commit_test.py index 6fdf20a3..7fa7781f 100644 --- a/tests/linters/pre_commit_test.py +++ b/tests/linters/pre_commit_test.py @@ -96,10 +96,16 @@ def test_command_returns_none_no_pre_commit_config(tmpdir_git): def test_command_returns_when_config_exists(tmpdir_git): - tmpdir_git.join('.pre-commit-config.yaml').write('{}\n') + cfg = tmpdir_git.join('.pre-commit-config.yaml') + cfg.write('{}\n') path = str(tmpdir_git.join('t.py')) ret = PreCommit().command(path, 'source.python') - assert ret == ('pre-commit', 'run', '--color=never', '--files', path) + assert ret == ( + 'pre-commit', 'run', + '--color=never', + '--config', str(cfg), + '--files', path, + ) def test_filters_file_paths_to_actual_file(tmpdir_git):