Skip to content

Commit

Permalink
Merge pull request #328 from asottile/correct-pre-commit-config
Browse files Browse the repository at this point in the history
use the correct pre-commit config
  • Loading branch information
asottile committed Oct 30, 2023
2 parents 4d4b0ef + 391846e commit 73e6470
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions babi/linters/pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions tests/linters/pre_commit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 73e6470

Please sign in to comment.