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

Few more readability refactors #305

Merged
merged 1 commit into from
Nov 16, 2022
Merged

Few more readability refactors #305

merged 1 commit into from
Nov 16, 2022

Conversation

Sija
Copy link
Member

@Sija Sija commented Nov 15, 2022

Followup to #300

@Sija Sija added the refactor label Nov 15, 2022
@Sija Sija added this to the 1.4.0 milestone Nov 15, 2022
@Sija Sija requested a review from veelenga November 15, 2022 19:46
@Sija Sija self-assigned this Nov 15, 2022
Comment on lines -118 to +143
json.object do
json.field :rule_name, rule_name
json.field :severity, severity
json.field :message, message
json.field :location,
{line: location.try &.line_number, column: location.try &.column_number}
json.field :end_location,
{line: end_location.try &.line_number, column: end_location.try &.column_number}
end
{
rule_name: rule_name,
severity: severity,
message: message,
location: {
line: location.try &.line_number,
column: location.try &.column_number,
},
end_location: {
line: end_location.try &.line_number,
column: end_location.try &.column_number,
},
}.to_json(json)
Copy link
Member

Choose a reason for hiding this comment

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

could you elaborate on the benefits of this change? Do we really need to create an intermediate hash object to make a json object?

Copy link
Member Author

@Sija Sija Nov 16, 2022

Choose a reason for hiding this comment

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

  1. readability
  2. consistency (it's the style being used in other places in the code)

and yes, it's allocating throw-away objects, but they're named tuples and not hashes, thus allocated on the stack, without putting pressure on the gc.

Copy link
Member

Choose a reason for hiding this comment

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

To be honest #1 is subjective. In my opinion, the previous version is readable.

For #2 (consistency), the only way to guarantee it is to enforce it through a rule. Otherwise, (as it often happens) a new developer/maintainer comes and introduces discrepancies or tries to enforce other subjective rules re-writing the whole codebase.

I'm open to do these changes, but just want to be sure the style is preserved in a long term (if we want to follow it).

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with both comments.

For #2 (consistency), the only way to guarantee it is to enforce it through a rule. Otherwise, (as it often happens) a new developer/maintainer comes and introduces discrepancies or tries to enforce other subjective rules re-writing the whole codebase.

While I do agree that would be the ideal solution, I suggest to leave it for a followup PR.

Copy link
Member

@veelenga veelenga left a comment

Choose a reason for hiding this comment

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

LGTM

@Sija Sija merged commit f9b6b17 into master Nov 16, 2022
@Sija Sija deleted the Sija/followup-to-pr-300 branch November 16, 2022 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants