Skip to content

Configure some new cops#9688

Merged
jekyllbot merged 3 commits intojekyll:masterfrom
ashmaroli:configure-new-cops
Oct 17, 2024
Merged

Configure some new cops#9688
jekyllbot merged 3 commits intojekyll:masterfrom
ashmaroli:configure-new-cops

Conversation

@ashmaroli
Copy link
Copy Markdown
Member

Summary

Add and configure some new cops available via current bundle (RuboCop v1.57 & extensions)

@ashmaroli ashmaroli requested a review from a team September 20, 2024 15:37
# that is allowed to be used.
def whitelist
@whitelist ||= Array[site.config["whitelist"]].flatten
@whitelist ||= [site.config["whitelist"]].flatten
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this was supposed to be Array() with parens. That was a constructor at one point (perhaps still is) and would avoid another allocation (I think).

Copy link
Copy Markdown
Member Author

@ashmaroli ashmaroli Sep 27, 2024

Choose a reason for hiding this comment

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

I had similar thoughts too but didn't want to play around with this particular line in this PR (only do cosmetic changes in lib/**/* in this PR; Handle specific optimizations in future PRs).

Your points are spot-on regarding allocations. Specifically, current implementation allocates 2 arrays at minimum:

  • The outer [] allocates a new array irrespective of site.config["whitelist"] already being an array.
  • The Array#flatten duplicates existing array, allocating another array just to handle site.config["whitelist"] already being an array.
  • Now, there's a sticky situation here. Array(whitelist_config) alone won't ensure a flat list of strings. So, we have to call Array#flatten (or Array#flatten! with extra steps).

All of the decision overhead in the third-point is outside the scope of this PR.

Minitest/RefutePathExists:
Enabled: true
Minitest/RefutePredicate:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this just too big a diff or do you find this one confusing so that's why it's disabled?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Current:

refute @collection.write?

After style change:

refute_predicate @collection, :write?

Doesn't the current seem clearer and easier to comprehend faster?
Maybe this is just a subjective preference. I'll go with whatever you decide (and apply same for the assert_predicate counterpart.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Replied above, I think assert/refute predicate, message would be the best of both worlds, but no worries if there's not a cop for enforcing a message in assert/refute calls.

Minitest/RefuteKindOf:
Enabled: true
Minitest/RefuteOperator:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the reason for disabling this one?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Current:

assert before_time <= @site.time

After style change (with AssertOperator counterpart):

assert_operator before_time, :<=, @site.time

The new style is objectively harder for humans to parse. So, disabled without veto. (applied to counterpart RefuteOperator as well).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see. I think the idea is to have better error messages since assert boolean_expr makes test output pretty useless. Perhaps we should enforce that assert calls must have a message component, i.e. assert boolean_expr, message_explaining_expectation. If it's not already a cop, then no worries.

Layout/EndAlignment:
Severity: error
Layout/EndOfLine:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we do EnforcedStyle: lf to use line feed everywhere? Maybe in a separate PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could use EnforcedStyle: lf in the current PR as well without affecting CI or including more file changes. All files are already checked out by git with native line-endings automatically.

But for contributors-from-Windows' sake, we may perhaps need to reconfigure .gitattributes file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, I think we'd prefer to check in LF instead of CRLF. Can .gitattributes give us a per-repo way of saying "Windows needs CRLF so write them to disk but Git should remove the CR"? As a Windows user (or one in the past), I think you have the best understanding of how this should work.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can .gitattributes give us a per-repo way of saying "Windows needs CRLF so write them to disk but Git should remove the CR"?

Yes. The jekyll/jekyll repo has that configured already.

Additional Reference: Example from GitHub Docs

Gemspec/DeprecatedAttributeAssignment:
Enabled: true
Gemspec/DevelopmentDependencies:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if this could be a good cleanup in the future? Not sure the value of add_development_dependency anymore in a gemspec.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was always in favor of moving dev-deps to Gemfile until I saw your commit @ rubocop-jekyll

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see -- I think it was more that I was too lazy to move them all to the Gemfile. I think managing dev dependencies in the Gemfile in 2024 makes sense, but no need to enforce it now if it's going to be a good amount of work (especially across repos).

@ashmaroli
Copy link
Copy Markdown
Member Author

Hello @parkr. When you get some time off, please let me know if my replies to your queries are satisfactory.

Gemspec/DeprecatedAttributeAssignment:
Enabled: true
Gemspec/DevelopmentDependencies:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see -- I think it was more that I was too lazy to move them all to the Gemfile. I think managing dev dependencies in the Gemfile in 2024 makes sense, but no need to enforce it now if it's going to be a good amount of work (especially across repos).

Layout/EndAlignment:
Severity: error
Layout/EndOfLine:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, I think we'd prefer to check in LF instead of CRLF. Can .gitattributes give us a per-repo way of saying "Windows needs CRLF so write them to disk but Git should remove the CR"? As a Windows user (or one in the past), I think you have the best understanding of how this should work.

Minitest/RefuteKindOf:
Enabled: true
Minitest/RefuteOperator:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see. I think the idea is to have better error messages since assert boolean_expr makes test output pretty useless. Perhaps we should enforce that assert calls must have a message component, i.e. assert boolean_expr, message_explaining_expectation. If it's not already a cop, then no worries.

Minitest/RefutePathExists:
Enabled: true
Minitest/RefutePredicate:
Enabled: false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Replied above, I think assert/refute predicate, message would be the best of both worlds, but no worries if there's not a cop for enforcing a message in assert/refute calls.

@ashmaroli
Copy link
Copy Markdown
Member Author

Thank you for the discussion, @parkr
@jekyllbot: merge +dev

@jekyllbot jekyllbot merged commit 5e1b6d3 into jekyll:master Oct 17, 2024
jekyllbot added a commit that referenced this pull request Oct 17, 2024
@ashmaroli ashmaroli deleted the configure-new-cops branch October 17, 2024 13:10
@jekyll jekyll locked and limited conversation to collaborators Oct 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants