Skip to content

Commit ae70f7e

Browse files
MarSoftssbarnea
authored andcommitted
Add check-toml hook
1 parent b7abd18 commit ae70f7e

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.pre-commit-hooks.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
entry: check-symlinks
7171
language: python
7272
types: [symlink]
73+
- id: check-toml
74+
name: Check Toml
75+
description: This hook checks toml files for parseable syntax.
76+
entry: check-toml
77+
language: python
78+
types: [toml]
7379
- id: check-vcs-permalinks
7480
name: Check vcs permalinks
7581
description: Ensures that links to vcs websites are permalinks.

pre_commit_hooks/check_toml.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import print_function
2+
3+
import argparse
4+
import sys
5+
from typing import Optional
6+
from typing import Sequence
7+
8+
import pytoml
9+
10+
11+
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
12+
parser = argparse.ArgumentParser()
13+
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
14+
args = parser.parse_args(argv)
15+
16+
retval = 0
17+
for filename in args.filenames:
18+
try:
19+
with open(filename) as f:
20+
pytoml.load(f)
21+
except pytoml.TomlError as exc:
22+
print(exc)
23+
retval = 1
24+
return retval
25+
26+
27+
if __name__ == '__main__':
28+
sys.exit(main())

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ packages = find:
2626
install_requires =
2727
flake8
2828
ruamel.yaml>=0.15
29+
pytoml
2930
six
3031
typing; python_version<"3.5"
3132
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
@@ -43,6 +44,7 @@ console_scripts =
4344
check-json = pre_commit_hooks.check_json:main
4445
check-merge-conflict = pre_commit_hooks.check_merge_conflict:main
4546
check-symlinks = pre_commit_hooks.check_symlinks:main
47+
check-toml = pre_commit_hooks.check_toml:main
4648
check-vcs-permalinks = pre_commit_hooks.check_vcs_permalinks:main
4749
check-xml = pre_commit_hooks.check_xml:main
4850
check-yaml = pre_commit_hooks.check_yaml:main

0 commit comments

Comments
 (0)