12
12
format = "%(levelname)s: %(message)s" ,
13
13
)
14
14
15
+ TS_IGNORE_PATTERN = r"(?://|/\*)\s*@ts-ignore(?:\s+|$)"
16
+
15
17
16
18
def check_ts_ignore (files : list [str ]) -> int :
17
19
"""Check for occurrences of '@ts-ignore' in the given files.
@@ -31,7 +33,8 @@ def check_ts_ignore(files: list[str]) -> int:
31
33
for line_num , line in enumerate (f , start = 1 ):
32
34
# Handle more variations of @ts-ignore
33
35
if re .search (
34
- r"(?://|/\*)\s*@ts-ignore(?:\s+|$)" , line .strip ()
36
+ TS_IGNORE_PATTERN ,
37
+ line .strip (),
35
38
):
36
39
print (
37
40
f"❌ Error: '@ts-ignore' found in { file } "
@@ -44,7 +47,7 @@ def check_ts_ignore(files: list[str]) -> int:
44
47
except FileNotFoundError :
45
48
logging .warning (f"File not found: { file } " )
46
49
except OSError as e :
47
- logging .error (f"Could not read { file } : { e } " )
50
+ logging .exception (f"Could not read { file } : { e } " )
48
51
if not ts_ignore_found :
49
52
print ("✅ No '@ts-ignore' comments found in the files." )
50
53
@@ -65,10 +68,13 @@ def main() -> None:
65
68
comments are found, or 1 if any are detected.
66
69
"""
67
70
parser = argparse .ArgumentParser (
68
- description = "Check for @ts-ignore in changed files."
71
+ description = "Check for @ts-ignore in changed files." ,
69
72
)
70
73
parser .add_argument (
71
- "--files" , nargs = "+" , help = "List of changed files" , required = True
74
+ "--files" ,
75
+ nargs = "+" ,
76
+ help = "List of changed files" ,
77
+ required = True ,
72
78
)
73
79
args = parser .parse_args ()
74
80
0 commit comments