-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Wanted: Layout/SpaceInsideArrayLiteralBrackets #4811
Comments
I would like to +1 this. Having spaces really improves readability IMHO, if you're listing elements. |
Fair enough. How would you like to treat multiline arrays under the new setting? |
Hm. I personally use the style: arr = [
:a,
:b,
:c
] So this wouldn't apply to me, but I would imagine if you added spaces inside brackets you would do so everywhere. (Including the first/last line of a multi-line array if there is an element on it.) I have trouble imagining someone constructing any other sort of convention, though if others actually employ such a coding style or else envision it actually being used, then perhaps it merits its own |
Ditto to the multi-line style @mvastola mentioned. I think the array brackets should be configurable in the same way that hashes are. IMO, each one of the following cops should have an array equivalent:
So the behavior and supported styles for
|
I think I'm mildly against the idea of creating a second cop. If we did this then (Would it be I guess it depends on how adverse this project is toward making breaking changes. I'm not sure what |
I'm not sure what I'm not clear on the difference between For my use case, my goal is to have space inside arrays, but not inside other brackets. # Yes
array = [ 1, 2, 3, 4 ]
# No
array[ 0 ] = 1 It looks like there are currently two braces cops: Are there any other uses for brackets that I'm missing in Ruby? I agree that it's a bummer that this approach would mean deprecating a cop, but IMHO it's worth it if the new properties are explicit. |
I forgot to mention, there's also |
arr = [ ]
arr = [ 1, 2, 3 ] Whereas arr = []
arr = [ 1, 2, 3 ] The (I think safe) assumption is no one is ever going to want a space only when there's an empty array. |
Gotcha. I think that's a safe assumption. |
The result of removing Style/SpaceInsideBrackets meant that the SpaceInside mixin was only getting utilized in Style/SpaceInsideParens. So this commit includes refactoring the mixin away and moving the necessary logic directly into Style/SpaceInsideParens. In addition, this commit renames the SurroundingSpace mixin's space_between? to space_after?, which is a more accurate description. See comment for more details.
In addition to adding Layout/SpaceInsideArrayLiteralBrackets, this commit breaks out reusable logic from Style/SpaceInsideReferenceBrackets and moves it into the SurroundingSpace mixin.
The result of removing Style/SpaceInsideBrackets meant that the SpaceInside mixin was only getting utilized in Style/SpaceInsideParens. So this commit includes refactoring the mixin away and moving the necessary logic directly into Style/SpaceInsideParens. In addition, this commit renames the SurroundingSpace mixin's space_between? to space_after?, which is a more accurate description. See comment for more details.
@bbatsov Thanks! |
#I would like to be enforce a Ruby array spacing style like this:
I've searched the documentation and GitHub issues for something like this, but I haven't been able to find anything. Rubocop includes Layout/SpaceInsideBrackets, but that seems to only enforce removing spaces, not including them. Furthermore, I only want to include spaces inside arrays, not accessor brackets or other bracket operators.
This would be the array equivilent of Layout/SpaceInsideHashLiteralBraces. It's also equivilent to array-bracket-spacing in ESLint.
Rubocop version:
0.50.0 (using Parser 2.4.0.0, running on ruby 2.4.2 x86_64-darwin17)
The text was updated successfully, but these errors were encountered: