mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-04-15 18:11:48 +04:00
Added powershell support
This commit is contained in:
parent
835396c645
commit
f2e3803913
5 changed files with 43 additions and 2 deletions
21
pre_commit/languages/powershell.py
Normal file
21
pre_commit/languages/powershell.py
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Sequence
|
||||||
|
|
||||||
|
from pre_commit.hook import Hook
|
||||||
|
from pre_commit.languages import helpers
|
||||||
|
|
||||||
|
|
||||||
|
ENVIRONMENT_DIR = None
|
||||||
|
get_default_version = helpers.basic_get_default_version
|
||||||
|
healthy = helpers.basic_healthy
|
||||||
|
install_environment = helpers.no_install
|
||||||
|
|
||||||
|
def run_hook(
|
||||||
|
hook: Hook,
|
||||||
|
file_args: Sequence[str],
|
||||||
|
color: bool,
|
||||||
|
) -> tuple[int, bytes]: # pragma: win32 no cover
|
||||||
|
fullpath = (hook.prefix.prefix_dir + '\\' + hook.cmd[0])
|
||||||
|
cmd = ('pwsh', '-F') + (fullpath,)
|
||||||
|
return helpers.run_xargs(hook, cmd, file_args, color=color)
|
||||||
|
|
@ -5,8 +5,8 @@ import sys
|
||||||
|
|
||||||
LANGUAGES = [
|
LANGUAGES = [
|
||||||
'conda', 'coursier', 'dart', 'docker', 'docker_image', 'dotnet', 'fail',
|
'conda', 'coursier', 'dart', 'docker', 'docker_image', 'dotnet', 'fail',
|
||||||
'golang', 'lua', 'node', 'perl', 'pygrep', 'python', 'r', 'ruby', 'rust',
|
'golang', 'lua', 'node', 'perl', 'powershell', 'pygrep', 'python', 'r',
|
||||||
'script', 'swift', 'system',
|
'ruby', 'rust', 'script', 'swift', 'system',
|
||||||
]
|
]
|
||||||
FIELDS = [
|
FIELDS = [
|
||||||
'ENVIRONMENT_DIR', 'get_default_version', 'healthy', 'install_environment',
|
'ENVIRONMENT_DIR', 'get_default_version', 'healthy', 'install_environment',
|
||||||
|
|
|
||||||
6
testing/resources/powershell_repo/.pre-commit-hooks.yaml
Normal file
6
testing/resources/powershell_repo/.pre-commit-hooks.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
- id: powershell-example-hook
|
||||||
|
name: Test Powershell Project
|
||||||
|
description: Test Powershell Project
|
||||||
|
entry: test-script.ps1
|
||||||
|
language: powershell
|
||||||
|
stages: [commit]
|
||||||
2
testing/resources/powershell_repo/test-script.ps1
Normal file
2
testing/resources/powershell_repo/test-script.ps1
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
Write-Output "Hello from Powershell"
|
||||||
|
exit 0
|
||||||
|
|
@ -1162,3 +1162,15 @@ def test_local_lua_additional_dependencies(store):
|
||||||
ret, out = _hook_run(hook, (), color=False)
|
ret, out = _hook_run(hook, (), color=False)
|
||||||
assert b'Luacheck' in out
|
assert b'Luacheck' in out
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'repo',
|
||||||
|
(
|
||||||
|
'powershell_repo',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
def test_dotnet_hook(tempdir_factory, store, repo):
|
||||||
|
_test_hook_repo(
|
||||||
|
tempdir_factory, store, repo,
|
||||||
|
'powershell-example-hook', [], b'Hello from Powershell\n',
|
||||||
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue