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

ktlint --format should return error code if unable to autocorrect #2795

Closed
ccjernigan opened this issue Sep 12, 2024 · 2 comments · Fixed by #2803
Closed

ktlint --format should return error code if unable to autocorrect #2795

ccjernigan opened this issue Sep 12, 2024 · 2 comments · Fixed by #2803

Comments

@ccjernigan
Copy link

I ran into a bug in ktlint earlier today, which has motivated this feature request. I ran ktlint --format locally, before submitting a pull request where the CI system runs ktlint. ktlint --format did not fail locally (and I didn't look closely at the logs to see the warning), but ktlint on CI did fail.

Expected Behavior

When running ktlint --format, any inability to autocorrect should be an error result code.

Current Behavior

ktlint will print a warning, rather than returning an error result code.

Additional information

  • Current version of ktlint: 1.3.1
@paul-dingemans
Copy link
Collaborator

Normally the exit code will be set in case an unfixed error is found. I believe that in your case there is special situation in which multiple violations are found in the same file, which in the end do not change that file at all. In this case the exit code is not set properly. To be sure, I need to have a reproducable example.

@ccjernigan
Copy link
Author

A single uncorrectable error will trigger the issue. The additional comment I made in #2794 with the .editorconfig should make it reproducible.

paul-dingemans added a commit that referenced this issue Sep 18, 2024
…hanged

In very rare cases it is possible that Lint violations are detected while formatting but that they have opposite effects and the file gets not altered at all. As the logging already might contain the message "Format was not able to resolve all violations which (theoretically) can be autocorrected in file ..." the format may not return with exit code 0.

Closes #2795
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants