Skip to content

Commit

Permalink
DRIVERS-2789 Add script to check for malformed links
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 committed Aug 21, 2024
1 parent 07b7649 commit 26d61f4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
21 changes: 13 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ repos:
args: ["--severity=error"]
stages: [manual]

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
args: ["--wrap=120", "--number"]
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote, mdformat-gfm-alerts]

- repo: local
hooks:
- id: generate-index
Expand All @@ -33,14 +41,11 @@ repos:
types: [markdown]
entry: bash scripts/check_anchors/check-anchors.sh
language: node

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
- id: mdformat
args: ["--wrap=120", "--number"]
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote, mdformat-gfm-alerts]
- id: markdown-link-format-check
name: markdown-link-format-check
types: [markdown]
language: system
entry: python3 scripts/check_links.py

- repo: https://github.com/tcort/markdown-link-check
rev: v3.12.2
Expand Down
17 changes: 17 additions & 0 deletions scripts/check_links.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import sys
fname = sys.argv[-1]

# Check for markdown links that got improperly line wrapped.
with open(fname) as fid:
for line in fid:
id0 = line.index('[') if '[' in line else -1
id1 = line.index(']') if ']' in line else -1
id2 = line.index('(') if '(' in line else -1
id3 = line.index(')') if ')' in line else -1
if id1 == -1 or id2 == -1 or id3 == -1:
continue
if id2 < id1 or id3 < id2:
continue
if id0 == -1:
print('*** Malformed link in line:', line, fname)
sys.exit(1)

0 comments on commit 26d61f4

Please sign in to comment.