Repository navigation
Linter: Improve erb-unsued-block-argument offense messages - #1992
Merged
Merged
Conversation
🌿 Interactive Playground and Documentation PreviewA preview deployment has been built for this pull request. Try out the changes live in the interactive playground: 🌱 Grown from commit ✅ Preview deployment has been cleaned up. |
commit: |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow up on #1958 and #1968.
Every unused block argument that isn't an
each_with_indexindex gets the same advice today: "Remove it, or prefix it with an underscore". This pull request makes that concrete where it can be, and stops giving it where it is wrong.Show the tag to write
When every argument of the block is unused, the parameter list can go entirely, so the message now shows the tag the author already wrote, minus the
|...|:This is not limited to
each, and the tag is rewritten from the source, so whatever the block is called on is kept as it is.The rewrite is skipped, and the message falls back to the plain
Remove it, when the tag spans multiple lines, when the rewritten tag would be longer than 60 characters, or when an argument the rule does not report (&block,**options) would be left behind.Stop suggesting a removal that rebinds the other arguments
A block destructures what it is yielded based on how many parameters it declares, so removing one argument out of several is not the same edit as removing all of them:
Following the old advice here would rebind
keyfrom the key to the whole pair, and the page would start rendering[:name, "Marco"]:So removal is only offered when every reported argument is unused. When some of them are still in use, the underscore is the only correct fix and the message says just that. The same applies to the element of an
each_with_indexwhose index is used, and to an unused argument of a destructured|(key, value)|.The
each_with_indexmessage from #1968 is unchanged for the shape it was written for. When the element is used and only the index is not, it still suggestseachinstead ofeach_with_index.