mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 03:56:54 +00:00
Add check-toml hook
This commit is contained in:
parent
cbc17d19d9
commit
cb365ba9c3
3 changed files with 36 additions and 0 deletions
|
|
@ -70,6 +70,12 @@
|
||||||
entry: check-symlinks
|
entry: check-symlinks
|
||||||
language: python
|
language: python
|
||||||
types: [symlink]
|
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
|
- id: check-vcs-permalinks
|
||||||
name: Check vcs permalinks
|
name: Check vcs permalinks
|
||||||
description: Ensures that links to vcs websites are permalinks.
|
description: Ensures that links to vcs websites are permalinks.
|
||||||
|
|
|
||||||
28
pre_commit_hooks/check_toml.py
Normal file
28
pre_commit_hooks/check_toml.py
Normal 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())
|
||||||
|
|
@ -26,6 +26,7 @@ packages = find:
|
||||||
install_requires =
|
install_requires =
|
||||||
flake8
|
flake8
|
||||||
ruamel.yaml>=0.15
|
ruamel.yaml>=0.15
|
||||||
|
pytoml
|
||||||
six
|
six
|
||||||
typing; python_version<"3.5"
|
typing; python_version<"3.5"
|
||||||
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
|
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-json = pre_commit_hooks.check_json:main
|
||||||
check-merge-conflict = pre_commit_hooks.check_merge_conflict:main
|
check-merge-conflict = pre_commit_hooks.check_merge_conflict:main
|
||||||
check-symlinks = pre_commit_hooks.check_symlinks: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-vcs-permalinks = pre_commit_hooks.check_vcs_permalinks:main
|
||||||
check-xml = pre_commit_hooks.check_xml:main
|
check-xml = pre_commit_hooks.check_xml:main
|
||||||
check-yaml = pre_commit_hooks.check_yaml:main
|
check-yaml = pre_commit_hooks.check_yaml:main
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue