Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return non-zero exit code on lint failures #4657

Merged
merged 1 commit into from
Feb 3, 2023

Conversation

mildaniel
Copy link
Contributor

Which issue(s) does this change fix?

#4649

Why is this change necessary?

Currently, sam validate --lint returns a 0 return code even if lint errors occurred.

How does it address the issue?

Raises an exception if any lint rules matched, which will propagate up and will exit the process with a return code of 1.

What side effects does this change have?

N/A

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mildaniel mildaniel requested a review from a team as a code owner February 2, 2023 22:34
@github-actions github-actions bot added pr/internal area/validate sam validate command labels Feb 2, 2023
rules = cfnlint.core.get_used_rules()
matches_output = formatter.print_matches(matches, rules, filenames)

if matches_output:
click.secho(matches_output)

raise LinterRuleMatchedException(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there are 0 matches, do we know that we are in exit code 1 state by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opposite actually. Line 148 checks for any matches and logs a success message if none are found

if not matches:
     click.secho("{} is a valid SAM Template".format(template), fg="green")

Otherwise there are some rules matched (meaning the linter found some issues) and we're in exit code 1 state.

@sriram-mv sriram-mv self-requested a review February 2, 2023 23:23
@mildaniel mildaniel merged commit 6983fe3 into aws:develop Feb 3, 2023
@mildaniel mildaniel deleted the error-code-lint-failure branch February 3, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/validate sam validate command pr/internal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants