@@ -38,9 +38,8 @@ def has_eslint_disable(file_path):
38
38
"""
39
39
# Initialize key variables
40
40
eslint_disable_pattern = re .compile (
41
- r"\/\/\s*eslint-disable(?:-next-line"
42
- r"|-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/" ,
43
- re .IGNORECASE ,
41
+ r"\/\/.*eslint-disable.*|\/\*[\s\S]*?eslint-disable[\s\S]*?\*\/" ,
42
+ re .IGNORECASE | re .DOTALL ,
44
43
)
45
44
46
45
try :
@@ -49,13 +48,11 @@ def has_eslint_disable(file_path):
49
48
return bool (eslint_disable_pattern .search (content ))
50
49
except FileNotFoundError :
51
50
print (f"File not found: { file_path } " )
52
- return False
53
51
except PermissionError :
54
52
print (f"Permission denied: { file_path } " )
55
- return False
56
53
except (IOError , OSError ) as e :
57
54
print (f"Error reading file { file_path } : { e } " )
58
- return False
55
+ return False
59
56
60
57
61
58
def check_eslint (files_or_directories ):
@@ -71,31 +68,27 @@ def check_eslint(files_or_directories):
71
68
72
69
for item in files_or_directories :
73
70
if os .path .isfile (item ):
74
- # If it's a file, directly check it
75
- if item .endswith (".ts" ) or item .endswith (".tsx" ):
76
- if has_eslint_disable (item ):
77
- print (
78
- f"""\
79
- File { item } contains eslint-disable statement. Please remove them and \
80
- ensure the code adheres to the specified ESLint rules."""
81
- )
82
- eslint_found = True
71
+ # Check a single file
72
+ if item .endswith ((".ts" , ".tsx" )) and has_eslint_disable (item ):
73
+ print (
74
+ f"Error: File { item } contains eslint-disable statements."
75
+ )
76
+ eslint_found = True
83
77
elif os .path .isdir (item ):
84
- # If it's a directory, walk through it and check all
85
- # .ts and .tsx files
78
+ # Recursively check files in a directory
86
79
for root , _ , files in os .walk (item ):
87
80
if "node_modules" in root :
88
81
continue
89
82
for file_name in files :
90
- if file_name .endswith (".ts" ) or file_name . endswith ( ".tsx" ):
83
+ if file_name .endswith (( ".ts" , ".tsx" ) ):
91
84
file_path = os .path .join (root , file_name )
92
85
if has_eslint_disable (file_path ):
93
86
print (
94
- f""" File { file_path } contains eslint-disable
95
- statement."" "
87
+ f"Error: File { file_path } contains "
88
+ "eslint-disable statements. "
96
89
)
97
- eslint_found = True
98
90
91
+ eslint_found = True
99
92
return eslint_found
100
93
101
94
@@ -107,22 +100,22 @@ def arg_parser_resolver():
107
100
Returns:
108
101
result: Parsed argument object
109
102
"""
110
- parser = argparse .ArgumentParser ()
103
+ parser = argparse .ArgumentParser (
104
+ description = "Check TypeScript files for eslint-disable statements."
105
+ )
111
106
parser .add_argument (
112
107
"--files" ,
113
108
type = str ,
114
109
nargs = "+" ,
115
110
default = [],
116
- help = """List of files to check for eslint disable
117
- statements (default: None).""" ,
111
+ help = "List of files to check for eslint-disable statements." ,
118
112
)
119
113
parser .add_argument (
120
114
"--directory" ,
121
115
type = str ,
122
116
nargs = "+" ,
123
117
default = [os .getcwd ()],
124
- help = """One or more directories to check for eslint disable
125
- statements (default: current directory).""" ,
118
+ help = "One or more directories to check for eslint-disable statements." ,
126
119
)
127
120
return parser .parse_args ()
128
121
0 commit comments