chore: Ensure the return code is handled correctly to account for any unexpected behavior. (#36068)
* chore: Ensure the return code is handled correctly to account for any unexpected behavior.
This commit is contained in:
@@ -49,20 +49,25 @@ def run_eslint():
|
|||||||
)
|
)
|
||||||
|
|
||||||
print(result.stdout)
|
print(result.stdout)
|
||||||
last_line = result.stdout.strip().splitlines()[-1] if result.stdout.strip().splitlines() else ""
|
if result.returncode == 0:
|
||||||
regex = r'^\d+'
|
fail_quality("No eslint violations found. This is unexpected... are you sure eslint is running correctly?")
|
||||||
try:
|
elif result.returncode == 1:
|
||||||
num_violations = int(re.search(regex, last_line).group(0)) if last_line else 0
|
last_line = result.stdout.strip().splitlines()[-1] if result.stdout.strip().splitlines() else ""
|
||||||
# Fail if number of violations is greater than the limit
|
regex = r'^\d+'
|
||||||
if num_violations > violations_limit:
|
try:
|
||||||
fail_quality(
|
num_violations = int(re.search(regex, last_line).group(0)) if last_line else 0
|
||||||
"FAILURE: Too many eslint violations ({count}).\nThe limit is {violations_limit}.".format(count=num_violations, violations_limit=violations_limit))
|
# Fail if number of violations is greater than the limit
|
||||||
else:
|
if num_violations > violations_limit:
|
||||||
print(f"successfully run eslint with '{num_violations}' violations")
|
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.
|
# An AttributeError will occur if the regex finds no matches.
|
||||||
except (AttributeError, ValueError):
|
except (AttributeError, ValueError):
|
||||||
fail_quality(f"FAILURE: Number of eslint violations could not be found in '{last_line}'")
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user