Created
July 28, 2025 09:31
-
-
Save toy-crane/86104682e88c093151fdf39315c73cc2 to your computer and use it in GitHub Desktop.
Type check hook example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import sys | |
import subprocess | |
import re | |
try: | |
input_data = json.loads(sys.stdin.read()) | |
except json.JSONDecodeError as e: | |
print(f"Error: {e}") | |
sys.exit(1) | |
tool_input = input_data.get("tool_input") | |
file_path = tool_input.get("file_path") | |
if re.search(r"\.(ts|tsx)$", file_path): | |
try: | |
subprocess.run( | |
[ | |
"yarn", | |
"type-check", | |
], | |
check=True, | |
capture_output=True, | |
text=True | |
) | |
except subprocess.CalledProcessError as e: | |
print("▲ TypeScript errors detected - please review", file=sys.stderr) | |
if e.stdout: | |
print(e.stdout, file=sys.stderr) | |
if e.stderr: | |
print(e.stderr, file=sys.stderr) | |
sys.exit(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment