Skip to content

Commit

Permalink
Merge pull request #18 from ssciwr/check-jsonschema
Browse files Browse the repository at this point in the history
Add check-jsonschema hooks
  • Loading branch information
dokempf authored Mar 20, 2024
2 parents 172a912 + cd36a12 commit 6a01da2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions precommend/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ repos:
rev: v0.16
hooks:
- id: validate-pyproject # Validate the contents of pyproject.toml

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-readthedocs # Validate the given .readthedocs.yml file
- id: check-dependabot # Validate the given dependabot.yml file
12 changes: 12 additions & 0 deletions precommend/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ def check_json(ctx):
return "check-json"


@rule
def check_dependabot(ctx):
if ctx.filename_exists(".github/dependabot.yml"):
return "check-dependabot"


@rule
def check_readthedocs(ctx):
if ctx.filename_exists(".readthedocs.yml"):
return "check-readthedocs"


@rule
def check_toml(ctx):
if ctx.tag_exists("toml"):
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ def _dir_fixture():

python_data = dir_fixture("python")
cpp_data = dir_fixture("cpp")
generic_data = dir_fixture("generic")
Empty file.
Empty file.
Empty file.
25 changes: 25 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ def test_collect_hooks_cpp(monkeypatch, cpp_data):
assert "cmake-format" in hooks


def test_collect_hooks_generic(monkeypatch, generic_data):
monkeypatch.chdir(generic_data)
ctx = GenerationContext()
hooks = collect_hooks(ctx)

assert "actionlint" in hooks
assert "check-dependabot" in hooks
assert "check-readthedocs" in hooks
assert "check-yaml" in hooks


def test_generate_config_python(monkeypatch, tmp_path, python_data):
monkeypatch.chdir(python_data)
ctx = GenerationContext()
Expand All @@ -41,3 +52,17 @@ def test_generate_config_python(monkeypatch, tmp_path, cpp_data):

assert "clang-format" in str(output)
assert "cmake-format" in str(output)


def test_generate_config_generic(monkeypatch, tmp_path, generic_data):
monkeypatch.chdir(generic_data)
ctx = GenerationContext()
hooks = collect_hooks(ctx)

monkeypatch.chdir(str(tmp_path))
output = generate_config(hooks)

assert "actionlint" in str(output)
assert "check-dependabot" in str(output)
assert "check-readthedocs" in str(output)
assert "check-yaml" in str(output)

0 comments on commit 6a01da2

Please sign in to comment.