From 3956fd441427a94f0d486bfa144ff4d931b16f2b Mon Sep 17 00:00:00 2001 From: salman2013 Date: Wed, 1 Jan 2025 15:52:57 +0500 Subject: [PATCH] chore: Ensure the return code is handled correctly to account for any unexpected behavior. --- scripts/eslint.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/scripts/eslint.py b/scripts/eslint.py index 3723ada6e219..c84a4d34300b 100644 --- a/scripts/eslint.py +++ b/scripts/eslint.py @@ -49,20 +49,25 @@ def run_eslint(): ) print(result.stdout) - last_line = result.stdout.strip().splitlines()[-1] if result.stdout.strip().splitlines() else "" - regex = r'^\d+' - try: - num_violations = int(re.search(regex, last_line).group(0)) if last_line else 0 - # Fail if number of violations is greater than the limit - if num_violations > violations_limit: - fail_quality( - "FAILURE: Too many eslint violations ({count}).\nThe limit is {violations_limit}.".format(count=num_violations, violations_limit=violations_limit)) - else: - print(f"successfully run eslint with '{num_violations}' violations") + if result.returncode == 0: + print("No eslint violations found.") + elif result.returncode == 1: + last_line = result.stdout.strip().splitlines()[-1] if result.stdout.strip().splitlines() else "" + regex = r'^\d+' + try: + num_violations = int(re.search(regex, last_line).group(0)) if last_line else 0 + # Fail if number of violations is greater than the limit + if num_violations > violations_limit: + fail_quality("FAILURE: Too many eslint violations ({count}).\nThe limit is {violations_limit}.".format(count=num_violations, violations_limit=violations_limit)) + else: + print(f"successfully run eslint with '{num_violations}' violations") - # An AttributeError will occur if the regex finds no matches. - except (AttributeError, ValueError): - fail_quality(f"FAILURE: Number of eslint violations could not be found in '{last_line}'") + # An AttributeError will occur if the regex finds no matches. + except (AttributeError, ValueError): + fail_quality(f"FAILURE: Number of eslint violations could not be found in '{last_line}'") + else: + print(f"Unexpected ESLint failure with exit code {result.returncode}.") + fail_quality(f"Unexpected error: {result.stderr.strip()}") if __name__ == "__main__":