Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
- id: reorder-python-imports
language_version: python2.7
- repo: https://github.com/asottile/add-trailing-comma
sha: v0.3.0
sha: v0.4.0
hooks:
- id: add-trailing-comma
23 changes: 0 additions & 23 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,6 @@ variable `slowtests=false`.

With the environment activated simply run `pre-commit install`.

## Style

This repository follows pep8 (and enforces it with flake8). There are a few
nitpicky things I also like that I'll outline below.

### Multi-line method invocation

Multiple line method invocation should look as follows

```python
function_call(
argument,
argument,
argument,
)
```

Some notable features:
- The initial parenthesis is at the end of the line
- Parameters are indented one indentation level further than the function name
- The last parameter contains a trailing comma (This helps make `git blame`
more accurate and reduces merge conflicts when adding / removing parameters).

## Documentation

Documentation is hosted at http://pre-commit.com
Expand Down
12 changes: 7 additions & 5 deletions pre_commit/languages/ruby.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ def get_env_patch(venv, language_version): # pragma: windows no cover
('GEM_HOME', os.path.join(venv, 'gems')),
('RBENV_ROOT', venv),
('BUNDLE_IGNORE_CONFIG', '1'),
('PATH', (
os.path.join(venv, 'gems', 'bin'), os.pathsep,
os.path.join(venv, 'shims'), os.pathsep,
os.path.join(venv, 'bin'), os.pathsep, Var('PATH'),
)),
(
'PATH', (
os.path.join(venv, 'gems', 'bin'), os.pathsep,
os.path.join(venv, 'shims'), os.pathsep,
os.path.join(venv, 'bin'), os.pathsep, Var('PATH'),
),
),
)
if language_version != 'default':
patches += (('RBENV_VERSION', language_version),)
Expand Down
16 changes: 9 additions & 7 deletions testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ def modify_config(path='.', commit=True):
def config_with_local_hooks():
return OrderedDict((
('repo', 'local'),
('hooks', [OrderedDict((
('id', 'do_not_commit'),
('name', 'Block if "DO NOT COMMIT" is found'),
('entry', 'DO NOT COMMIT'),
('language', 'pcre'),
('files', '^(.*)$'),
))]),
(
'hooks', [OrderedDict((
('id', 'do_not_commit'),
('name', 'Block if "DO NOT COMMIT" is found'),
('entry', 'DO NOT COMMIT'),
('language', 'pcre'),
('files', '^(.*)$'),
))],
),
))


Expand Down
156 changes: 81 additions & 75 deletions tests/clientlib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,94 +56,100 @@ def test_validate_config_main(args, expected_output):
assert validate_config_main(args) == expected_output


@pytest.mark.parametrize(('config_obj', 'expected'), (
([], False),
(
[{
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
'hooks': [{'id': 'pyflakes', 'files': '\\.py$'}],
}],
True,
),
(
[{
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
'hooks': [
{
'id': 'pyflakes',
'files': '\\.py$',
'args': ['foo', 'bar', 'baz'],
},
],
}],
True,
),
(
[{
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
'hooks': [
{
'id': 'pyflakes',
'files': '\\.py$',
# Exclude pattern must be a string
'exclude': 0,
'args': ['foo', 'bar', 'baz'],
},
],
}],
False,
@pytest.mark.parametrize(
('config_obj', 'expected'), (
([], False),
(
[{
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
'hooks': [{'id': 'pyflakes', 'files': '\\.py$'}],
}],
True,
),
(
[{
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
'hooks': [
{
'id': 'pyflakes',
'files': '\\.py$',
'args': ['foo', 'bar', 'baz'],
},
],
}],
True,
),
(
[{
'repo': 'git@github.com:pre-commit/pre-commit-hooks',
'sha': 'cd74dc150c142c3be70b24eaf0b02cae9d235f37',
'hooks': [
{
'id': 'pyflakes',
'files': '\\.py$',
# Exclude pattern must be a string
'exclude': 0,
'args': ['foo', 'bar', 'baz'],
},
],
}],
False,
),
),
))
)
def test_config_valid(config_obj, expected):
ret = is_valid_according_to_schema(config_obj, CONFIG_SCHEMA)
assert ret is expected


@pytest.mark.parametrize('config_obj', (
[{
'repo': 'local',
'sha': 'foo',
'hooks': [{
'id': 'do_not_commit',
'name': 'Block if "DO NOT COMMIT" is found',
'entry': 'DO NOT COMMIT',
'language': 'pcre',
'files': '^(.*)$',
@pytest.mark.parametrize(
'config_obj', (
[{
'repo': 'local',
'sha': 'foo',
'hooks': [{
'id': 'do_not_commit',
'name': 'Block if "DO NOT COMMIT" is found',
'entry': 'DO NOT COMMIT',
'language': 'pcre',
'files': '^(.*)$',
}],
}],
}],
))
),
)
def test_config_with_local_hooks_definition_fails(config_obj):
with pytest.raises(schema.ValidationError):
schema.validate(config_obj, CONFIG_SCHEMA)


@pytest.mark.parametrize('config_obj', (
[{
'repo': 'local',
'hooks': [{
'id': 'arg-per-line',
'name': 'Args per line hook',
'entry': 'bin/hook.sh',
'language': 'script',
'files': '',
'args': ['hello', 'world'],
@pytest.mark.parametrize(
'config_obj', (
[{
'repo': 'local',
'hooks': [{
'id': 'arg-per-line',
'name': 'Args per line hook',
'entry': 'bin/hook.sh',
'language': 'script',
'files': '',
'args': ['hello', 'world'],
}],
}],
}],
[{
'repo': 'local',
'hooks': [{
'id': 'arg-per-line',
'name': 'Args per line hook',
'entry': 'bin/hook.sh',
'language': 'script',
'files': '',
'args': ['hello', 'world'],
}]
}],
))
[{
'repo': 'local',
'hooks': [{
'id': 'arg-per-line',
'name': 'Args per line hook',
'entry': 'bin/hook.sh',
'language': 'script',
'files': '',
'args': ['hello', 'world'],
}]
}],
),
)
def test_config_with_local_hooks_definition_passes(config_obj):
schema.validate(config_obj, CONFIG_SCHEMA)

Expand Down
10 changes: 6 additions & 4 deletions tests/color_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
from pre_commit.color import use_color


@pytest.mark.parametrize(('in_text', 'in_color', 'in_use_color', 'expected'), (
('foo', GREEN, True, '{}foo\033[0m'.format(GREEN)),
('foo', GREEN, False, 'foo'),
))
@pytest.mark.parametrize(
('in_text', 'in_color', 'in_use_color', 'expected'), (
('foo', GREEN, True, '{}foo\033[0m'.format(GREEN)),
('foo', GREEN, False, 'foo'),
),
)
def test_format_color(in_text, in_color, in_use_color, expected):
ret = format_color(in_text, in_color, in_use_color)
assert ret == expected
Expand Down
Loading