From 18d9cd7c6bae15971adb9ccc9b57681f5004392a Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 13:02:13 +0530 Subject: [PATCH 1/9] Fixed eslint-disable script --- .github/workflows/pull-request.yml | 12 +++--- .../workflows/scripts/eslint_disable_check.py | 41 +++++++------------ src/App.tsx | 1 + 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index a6f0dc0b5f..d9ae9debc1 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -195,14 +195,16 @@ jobs: id: changed-files uses: tj-actions/changed-files@v45 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.9 + - name: Filter TypeScript files + id: filter-files + run: | + echo "::set-output name=ts_files::$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' ' ')" + shell: bash - name: Run Python script + if: steps.filter-files.outputs.ts_files != '' run: | - python .github/workflows/scripts/eslint_disable_check.py --files ${{ steps.changed-files.outputs.all_changed_files }} + python .github/workflows/scripts/eslint_disable_check.py --files ${{ steps.filter-files.outputs.ts_files }} Check-Code-Coverage-Disable: name: Check for code coverage disable diff --git a/.github/workflows/scripts/eslint_disable_check.py b/.github/workflows/scripts/eslint_disable_check.py index 45ce52b84a..fa9a664adf 100644 --- a/.github/workflows/scripts/eslint_disable_check.py +++ b/.github/workflows/scripts/eslint_disable_check.py @@ -38,8 +38,7 @@ 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[^\*]*\*\/", + r"\/\/\s*eslint-disable(?:-next-line|-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/", re.IGNORECASE, ) @@ -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,21 @@ 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.""" - ) + print(f"Error: File {file_path} contains eslint-disable statements.") eslint_found = True - return eslint_found @@ -107,22 +94,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() diff --git a/src/App.tsx b/src/App.tsx index a12f3e7ceb..bd36789ee8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -98,6 +98,7 @@ function app(): JSX.Element { // TODO: Fetch Installed plugin extras and store for use within MainContent and Side Panel Components. const { data, loading } = useQuery(CHECK_AUTH); + /*eslint-disable */ useEffect(() => { if (!loading && data?.checkAuth) { From a44552680f3dc510a3424cbad40e550b6c07f81f Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 13:19:20 +0530 Subject: [PATCH 2/9] Update regex to handle edge cases --- .github/workflows/scripts/eslint_disable_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/eslint_disable_check.py b/.github/workflows/scripts/eslint_disable_check.py index fa9a664adf..045b081923 100644 --- a/.github/workflows/scripts/eslint_disable_check.py +++ b/.github/workflows/scripts/eslint_disable_check.py @@ -38,8 +38,8 @@ def has_eslint_disable(file_path): """ # Initialize key variables eslint_disable_pattern = re.compile( - r"\/\/\s*eslint-disable(?:-next-line|-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/", - re.IGNORECASE, + r"\/\/\s*eslint-disable(?:-next-line|-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/|\/\*[\s\S]*?eslint-disable[\s\S]*?\*\/", + re.IGNORECASE | re.DOTALL, ) try: From 287a9830db09a0b55e5e99b4bb138bbae4334582 Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 13:29:41 +0530 Subject: [PATCH 3/9] Remove test eslint-disable --- src/App.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/App.tsx b/src/App.tsx index bd36789ee8..a12f3e7ceb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -98,7 +98,6 @@ function app(): JSX.Element { // TODO: Fetch Installed plugin extras and store for use within MainContent and Side Panel Components. const { data, loading } = useQuery(CHECK_AUTH); - /*eslint-disable */ useEffect(() => { if (!loading && data?.checkAuth) { From d765c0a4cd3e663a61010669d265652a02a056dd Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 14:25:38 +0530 Subject: [PATCH 4/9] Fixed lint --- .github/workflows/pull-request.yml | 2 +- .github/workflows/scripts/eslint_disable_check.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index d9ae9debc1..80c13f5168 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -198,7 +198,7 @@ jobs: - name: Filter TypeScript files id: filter-files run: | - echo "::set-output name=ts_files::$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' ' ')" + echo "ts_files=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' ' ')" >> $GITHUB_OUTPUT shell: bash - name: Run Python script diff --git a/.github/workflows/scripts/eslint_disable_check.py b/.github/workflows/scripts/eslint_disable_check.py index 045b081923..aba5810687 100644 --- a/.github/workflows/scripts/eslint_disable_check.py +++ b/.github/workflows/scripts/eslint_disable_check.py @@ -70,7 +70,9 @@ def check_eslint(files_or_directories): if os.path.isfile(item): # Check a single file if item.endswith((".ts", ".tsx")) and has_eslint_disable(item): - print(f"Error: File {item} contains eslint-disable statements.") + print( + f"Error: File {item} contains eslint-disable statements." + ) eslint_found = True elif os.path.isdir(item): # Recursively check files in a directory @@ -81,7 +83,9 @@ def check_eslint(files_or_directories): if file_name.endswith((".ts", ".tsx")): file_path = os.path.join(root, file_name) if has_eslint_disable(file_path): - print(f"Error: File {file_path} contains eslint-disable statements.") + print( + f"Error: File {file_path} contains eslint-disable statements." + ) eslint_found = True return eslint_found From 8dbff8cc5fc53a1e2febd1a4a2ed8e4d13231698 Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 15:55:05 +0530 Subject: [PATCH 5/9] Fixed lint --- .github/workflows/pull-request.yml | 2 +- .github/workflows/scripts/eslint_disable_check.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 80c13f5168..357b4a48c4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -198,7 +198,7 @@ jobs: - name: Filter TypeScript files id: filter-files run: | - echo "ts_files=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' ' ')" >> $GITHUB_OUTPUT + echo "ts_files=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' '\n')" >> $GITHUB_OUTPUT shell: bash - name: Run Python script diff --git a/.github/workflows/scripts/eslint_disable_check.py b/.github/workflows/scripts/eslint_disable_check.py index aba5810687..a7421f226b 100644 --- a/.github/workflows/scripts/eslint_disable_check.py +++ b/.github/workflows/scripts/eslint_disable_check.py @@ -38,7 +38,9 @@ def has_eslint_disable(file_path): """ # Initialize key variables eslint_disable_pattern = re.compile( - r"\/\/\s*eslint-disable(?:-next-line|-line)?[^\n]*|\/\*\s*eslint-disable[^\*]*\*\/|\/\*[\s\S]*?eslint-disable[\s\S]*?\*\/", + r"\/\/\s*eslint-disable(?:-next-line|-line)?[^\n]*|" + r"\/\*\s*eslint-disable[^\*]*\*\/|" + r"\/\*[\s\S]*?eslint-disable[\s\S]*?\*\/", re.IGNORECASE | re.DOTALL, ) From 3f4dab9d0975c867463b1c06429b8d9209433f17 Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 16:01:18 +0530 Subject: [PATCH 6/9] Fixed redundant \n --- .github/workflows/pull-request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 357b4a48c4..80c13f5168 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -198,7 +198,7 @@ jobs: - name: Filter TypeScript files id: filter-files run: | - echo "ts_files=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' '\n')" >> $GITHUB_OUTPUT + echo "ts_files=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' ' ')" >> $GITHUB_OUTPUT shell: bash - name: Run Python script From 314d23524cc3271ed7b1dff77e43782711aab648 Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 19:38:31 +0530 Subject: [PATCH 7/9] Fixed flake8 lint --- .github/workflows/scripts/eslint_disable_check.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/scripts/eslint_disable_check.py b/.github/workflows/scripts/eslint_disable_check.py index a7421f226b..ae93350f02 100644 --- a/.github/workflows/scripts/eslint_disable_check.py +++ b/.github/workflows/scripts/eslint_disable_check.py @@ -86,8 +86,10 @@ def check_eslint(files_or_directories): file_path = os.path.join(root, file_name) if has_eslint_disable(file_path): print( - f"Error: File {file_path} contains eslint-disable statements." + f"Error: File {item} contains " + "eslint-disable statements." ) + eslint_found = True return eslint_found From df5db71f454b4ac79792e8218a3c4f3a177005fe Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 21:25:46 +0530 Subject: [PATCH 8/9] Implemented suggestions --- .github/workflows/pull-request.yml | 13 ++++++------- .github/workflows/scripts/eslint_disable_check.py | 6 ++---- src/App.tsx | 2 ++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 80c13f5168..afbbf66b5b 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -195,16 +195,15 @@ jobs: id: changed-files uses: tj-actions/changed-files@v45 - - name: Filter TypeScript files - id: filter-files - run: | - echo "ts_files=$(echo '${{ steps.changed-files.outputs.all_changed_files }}' | tr ',' '\n' | grep -E '\.(ts|tsx)$' | tr '\n' ' ')" >> $GITHUB_OUTPUT - shell: bash + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 - name: Run Python script - if: steps.filter-files.outputs.ts_files != '' run: | - python .github/workflows/scripts/eslint_disable_check.py --files ${{ steps.filter-files.outputs.ts_files }} + 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 diff --git a/.github/workflows/scripts/eslint_disable_check.py b/.github/workflows/scripts/eslint_disable_check.py index ae93350f02..84d608aaa5 100644 --- a/.github/workflows/scripts/eslint_disable_check.py +++ b/.github/workflows/scripts/eslint_disable_check.py @@ -38,9 +38,7 @@ def has_eslint_disable(file_path): """ # Initialize key variables eslint_disable_pattern = re.compile( - r"\/\/\s*eslint-disable(?:-next-line|-line)?[^\n]*|" - r"\/\*\s*eslint-disable[^\*]*\*\/|" - r"\/\*[\s\S]*?eslint-disable[\s\S]*?\*\/", + r"\/\/.*eslint-disable.*|\/\*[\s\S]*?eslint-disable[\s\S]*?\*\/", re.IGNORECASE | re.DOTALL, ) @@ -86,7 +84,7 @@ def check_eslint(files_or_directories): file_path = os.path.join(root, file_name) if has_eslint_disable(file_path): print( - f"Error: File {item} contains " + f"Error: File {file_path} contains " "eslint-disable statements." ) diff --git a/src/App.tsx b/src/App.tsx index a12f3e7ceb..24214640f6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -99,6 +99,8 @@ function app(): JSX.Element { const { data, loading } = useQuery(CHECK_AUTH); + /* eslint-disable-next-line */ + useEffect(() => { if (!loading && data?.checkAuth) { const auth = data.checkAuth; From 5bba47bbf552997bfa248cd674358234c3e528af Mon Sep 17 00:00:00 2001 From: adithya Date: Tue, 14 Jan 2025 21:27:38 +0530 Subject: [PATCH 9/9] Removed test eslint-disable --- src/App.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 24214640f6..a12f3e7ceb 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -99,8 +99,6 @@ function app(): JSX.Element { const { data, loading } = useQuery(CHECK_AUTH); - /* eslint-disable-next-line */ - useEffect(() => { if (!loading && data?.checkAuth) { const auth = data.checkAuth;