diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a6f0dc0b5f..afbbf66b5b 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -204,6 +204,7 @@ jobs: run: | python .github/workflows/scripts/eslint_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }} + Check-Code-Coverage-Disable: name: Check for code coverage disable runs-on: ubuntu-latest diff --git a/.github/workflows/scripts/eslint_disable_check.py b/.github/workflows/scripts/eslint_disable_check.py index 45ce52b84a..84d608aaa5 100644 --- a/.github/workflows/scripts/eslint_disable_check.py +++ b/.github/workflows/scripts/eslint_disable_check.py @@ -38,9 +38,8 @@ def has_eslint_disable(file_path): """ # Initialize key variables eslint_disable_pattern = re.compile( - r"\/\/\s*eslint-disable(?:-next-line" - r"|-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/", - re.IGNORECASE, + r"\/\/.*eslint-disable.*|\/\*[\s\S]*?eslint-disable[\s\S]*?\*\/", + re.IGNORECASE | re.DOTALL, ) try: @@ -49,13 +48,11 @@ def has_eslint_disable(file_path): return bool(eslint_disable_pattern.search(content)) except FileNotFoundError: print(f"File not found: {file_path}") - return False except PermissionError: print(f"Permission denied: {file_path}") - return False except (IOError, OSError) as e: print(f"Error reading file {file_path}: {e}") - return False + return False def check_eslint(files_or_directories): @@ -71,31 +68,27 @@ def check_eslint(files_or_directories): for item in files_or_directories: if os.path.isfile(item): - # If it's a file, directly check it - if item.endswith(".ts") or item.endswith(".tsx"): - if has_eslint_disable(item): - print( - f"""\ -File {item} contains eslint-disable statement. Please remove them and \ -ensure the code adheres to the specified ESLint rules.""" - ) - eslint_found = True + # Check a single file + if item.endswith((".ts", ".tsx")) and has_eslint_disable(item): + print( + f"Error: File {item} contains eslint-disable statements." + ) + eslint_found = True elif os.path.isdir(item): - # If it's a directory, walk through it and check all - # .ts and .tsx files + # Recursively check files in a directory for root, _, files in os.walk(item): if "node_modules" in root: continue for file_name in files: - if file_name.endswith(".ts") or file_name.endswith(".tsx"): + if file_name.endswith((".ts", ".tsx")): file_path = os.path.join(root, file_name) if has_eslint_disable(file_path): print( - f"""File {file_path} contains eslint-disable - statement.""" + f"Error: File {file_path} contains " + "eslint-disable statements." ) - eslint_found = True + eslint_found = True return eslint_found @@ -107,22 +100,22 @@ def arg_parser_resolver(): Returns: result: Parsed argument object """ - parser = argparse.ArgumentParser() + parser = argparse.ArgumentParser( + description="Check TypeScript files for eslint-disable statements." + ) parser.add_argument( "--files", type=str, nargs="+", default=[], - help="""List of files to check for eslint disable - statements (default: None).""", + help="List of files to check for eslint-disable statements.", ) parser.add_argument( "--directory", type=str, nargs="+", default=[os.getcwd()], - help="""One or more directories to check for eslint disable - statements (default: current directory).""", + help="One or more directories to check for eslint-disable statements.", ) return parser.parse_args()