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 #10241] Fix last_column value for JSONFormatter #10242

Merged

Conversation

koic
Copy link
Member

@koic koic commented Nov 12, 2021

Fixes #10241.

This PR fixes last_column value for JSONFormatter.

The minimum value of start_column: real_column is 1. So, the minimum value of last_column should be 1.
And non-zero value of last_column should be used as is.

This patch to last_column seems to be required only for JSONFormatter and not required for other formatters.

It solves a potential JSONFormatter issue for cops that use add_global_offense.


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.

Fixes rubocop#10241.

This PR fixes `last_column` value for `JSONFormatter`.

The minimum value of `start_column: real_column` is 1. So, the minimum value of `last_column` should be 1.
And non-zero value of `last_column` should be used as is.

This patch to `last_column` seems to be required only for `JSONFormatter` and not required for other formatters.

It solves a potential `JSONFormatter` issue for cops that use `add_global_offense`.
@koic koic force-pushed the fix_last_column_number_for_json_formatter branch from b8b17b5 to 965654f Compare November 12, 2021 08:05
@bbatsov bbatsov merged commit 9b03aca into rubocop:master Nov 12, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 12, 2021

It's a bit ugly indeed, but it solves the problem. Thanks!

@koic koic deleted the fix_last_column_number_for_json_formatter branch November 12, 2021 09:24
def hash_for_location(offense)
{
start_line: offense.line,
start_column: offense.real_column,
last_line: offense.last_line,
last_column: offense.last_column,
last_column: offense.last_column.zero? ? 1 : offense.last_column,

Choose a reason for hiding this comment

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

Sorry, I'm not familiar with the Rubocop codebase.

This change prevents a situation start_column==1, last_column==0 from happening, but can something like start_column==5, last_column==4 still happen?

@radomirbosak
Copy link

radomirbosak commented Nov 15, 2021

Thank you very much for fixing this! I tested this locally and everything works now as expected.

Would it be possible to release this fix in a patch/bugfix release?

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