Skip to content

Commit 0949578

Browse files
committed
Add commands to run linters for docs
1 parent 0c556dc commit 0949578

File tree

2 files changed

+66
-4
lines changed

2 files changed

+66
-4
lines changed

.vale/styles/Infrahub/branded-terms-case-swap.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,31 @@ ignorecase: false
66
action:
77
name: replace
88
swap:
9-
(?i:[^/]Github): GitHub
10-
(?i:gitpod): GitPod
11-
(?i:[^/]Graphql): GraphQL
9+
(?:ansible): Ansible
10+
(?:[^"]docker): Docker
11+
(?:[Dd]ockerhub): DockerHub
12+
(?:[^/][Gg]ithub): GitHub
13+
(?:[Gg]itlab): GitLab
14+
(?:gitpod): GitPod
15+
(?:grafana): Grafana
16+
(?:[^/][Gg]raphql): GraphQL
17+
(?:[Ii]nflux[Dd]b): InfluxDB
1218
infrahub(?:\s|$): Infrahub
13-
(?i:Openconfig): OpenConfig
19+
(?:jinja2): Jinja2
20+
(?:k3s): K3s
21+
(?:k8s): K8s
22+
(?:kubernetes): Kubernetes
23+
(?:[^/][Mm]y[Ss]ql): MySQL
24+
(?:neo4j): Neo4j
25+
(?:[^/][Nn]ginx): NGINX
26+
(?:[Nn]odejs): Node.js
27+
(?:[^/][Oo]penapi): OpenAPI
28+
(?:Openconfig): OpenConfig
1429
opsmill(?:\s|$): OpsMill
30+
(?:[Pp]ostgre[Ss]ql): PostgreSQL
31+
(?:[^/]prometheus): Prometheus
32+
(?:[^/-]python): Python
33+
(?:[Rr]abbitmq): RabbitMQ
34+
(?:[^/]terraform): Terraform
35+
(?:ubuntu): Ubuntu
36+
(?:[Vv]s\W?[Cc]ode): VS Code

tasks.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import sys
33
from pathlib import Path
4+
from shutil import which
45
from typing import Any
56

67
from invoke import Context, task
@@ -11,6 +12,11 @@
1112
MAIN_DIRECTORY_PATH = Path(__file__).parent
1213

1314

15+
def is_tool_installed(name: str) -> bool:
16+
"""Check whether `name` is on PATH and marked as executable."""
17+
return which(name) is not None
18+
19+
1420
def _generate(context: Context) -> None:
1521
"""Generate documentation output from code."""
1622
_generate_infrahubctl_documentation(context=context)
@@ -165,12 +171,46 @@ def lint_ruff(context: Context) -> None:
165171
context.run(exec_cmd)
166172

167173

174+
@task
175+
def lint_markdownlint(context: Context) -> None:
176+
"""Run markdownlint to check all markdown files."""
177+
if not is_tool_installed("markdownlint-cli2"):
178+
print(" - markdownlint-cli2 is not installed, skipping documentation linting")
179+
return
180+
181+
print(" - Check documentation with markdownlint-cli2")
182+
exec_cmd = "markdownlint-cli2 **/*.{md,mdx} --config .markdownlint.yaml"
183+
with context.cd(MAIN_DIRECTORY_PATH):
184+
context.run(exec_cmd)
185+
186+
187+
@task
188+
def lint_vale(context: Context) -> None:
189+
"""Run vale to check all documentation files."""
190+
if not is_tool_installed("vale"):
191+
print(" - vale is not installed, skipping documentation style linting")
192+
return
193+
194+
print(" - Check documentation style with vale")
195+
exec_cmd = r'vale $(find ./docs -type f \( -name "*.mdx" -o -name "*.md" \))'
196+
with context.cd(MAIN_DIRECTORY_PATH):
197+
context.run(exec_cmd)
198+
199+
200+
@task
201+
def lint_docs(context: Context) -> None:
202+
"""Run all documentation linters."""
203+
lint_markdownlint(context)
204+
lint_vale(context)
205+
206+
168207
@task(name="lint")
169208
def lint_all(context: Context) -> None:
170209
"""Run all linters."""
171210
lint_yaml(context)
172211
lint_ruff(context)
173212
lint_mypy(context)
213+
lint_docs(context)
174214

175215

176216
@task(name="docs-validate")

0 commit comments

Comments
 (0)