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

Allow autocorrect with display-only-fail-level-offenses #12535

Merged
merged 1 commit into from Dec 22, 2023

Conversation

naveg
Copy link
Contributor

@naveg naveg commented Dec 12, 2023

The --display-only-fail-level-offenses option uses
considered_failure? to determine what to print. The same method is
used to determine the exit code of rubocop, so the two options should
be entirely safe to use together.

This change is useful when using rubocop as part of a pre-commit hook.
When the hook fails becuase rubocop exited with a non-zero status, we
can use --display-only-fail-level-offenses to avoid having the output
cluttered up with non-blocking offenses.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@naveg naveg force-pushed the naveg/autocorrect-display-fail branch from 0024ae9 to 6416464 Compare December 12, 2023 22:49
@naveg naveg marked this pull request as ready for review December 12, 2023 22:49
@naveg naveg marked this pull request as draft December 12, 2023 22:55
@naveg naveg force-pushed the naveg/autocorrect-display-fail branch 2 times, most recently from 668c50b to 23e65ab Compare December 12, 2023 23:45
@naveg naveg marked this pull request as ready for review December 12, 2023 23:52
it 'fails if given with an autocorrect argument' do
%w[--fix-layout -x --autocorrect -a --autocorrect-all -A].each do |o|
expect { options.parse ['--display-only-correctable', o] }
.to raise_error(RuboCop::OptionArgumentError)
Copy link
Member

Choose a reason for hiding this comment

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

It seems that instead of being removed, it should be updated to reflect an expected behavior, rather than resulting in the RuboCop::OptionArgumentError error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow. This tests the validation that I removed in order to allow the two arguments to be used together. I could change it to not_to expect the error, but did you have something else in mind?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, for now, the test should probably be changed to not_to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. The test was actually not doing the right thing before, because it was re-using the same Options instance and generating errors for a different reason (using -a and -A together)

The `--display-only-fail-level-offenses` option uses
`considered_failure?` to determine what to print. The same method is
used to determine the exit code of `rubocop`, so the two options should
be entirely safe to use together.

This change is useful when using rubocop as part of a pre-commit hook.
When the hook fails becuase rubocop exited with a non-zero status, we
can use `--display-only-fail-level-offenses` to avoid having the output
cluttered up with non-blocking offenses.
@naveg naveg force-pushed the naveg/autocorrect-display-fail branch from 23e65ab to b695ff7 Compare December 13, 2023 17:49
@naveg naveg requested a review from koic December 13, 2023 17:59
@naveg
Copy link
Contributor Author

naveg commented Dec 15, 2023

@koic would appreciate another look when you have a chance, thanks! 🙏

@naveg
Copy link
Contributor Author

naveg commented Dec 21, 2023

@koic @bbatsov just checking in on this one. Let me know if I should make any other adjustments

@bbatsov bbatsov merged commit 685a7f8 into rubocop:master Dec 22, 2023
28 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 22, 2023

The change looks good to me. Thanks!

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 this pull request may close these issues.

None yet

3 participants