Add check-toml hook

This commit is contained in:
Semyon Maryasin 2019-03-28 01:13:45 +03:00 committed by Sorin Sbarnea
parent b7abd18ceb
commit ae70f7e3c7
3 changed files with 36 additions and 0 deletions

View File

@ -70,6 +70,12 @@
entry: check-symlinks
language: python
types: [symlink]
- id: check-toml
name: Check Toml
description: This hook checks toml files for parseable syntax.
entry: check-toml
language: python
types: [toml]
- id: check-vcs-permalinks
name: Check vcs permalinks
description: Ensures that links to vcs websites are permalinks.

View File

@ -0,0 +1,28 @@
from __future__ import print_function
import argparse
import sys
from typing import Optional
from typing import Sequence
import pytoml
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
parser = argparse.ArgumentParser()
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
args = parser.parse_args(argv)
retval = 0
for filename in args.filenames:
try:
with open(filename) as f:
pytoml.load(f)
except pytoml.TomlError as exc:
print(exc)
retval = 1
return retval
if __name__ == '__main__':
sys.exit(main())

View File

@ -26,6 +26,7 @@ packages = find:
install_requires =
flake8
ruamel.yaml>=0.15
pytoml
six
typing; python_version<"3.5"
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
@ -43,6 +44,7 @@ console_scripts =
check-json = pre_commit_hooks.check_json:main
check-merge-conflict = pre_commit_hooks.check_merge_conflict:main
check-symlinks = pre_commit_hooks.check_symlinks:main
check-toml = pre_commit_hooks.check_toml:main
check-vcs-permalinks = pre_commit_hooks.check_vcs_permalinks:main
check-xml = pre_commit_hooks.check_xml:main
check-yaml = pre_commit_hooks.check_yaml:main