Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNew rules: Disallow or enforce spaces inside of curly braces and brackets (object-curly-spacing and array-bracket-spacing) #609
Comments
dcousens
added
the
question
label
Sep 2, 2016
feross
added this to the
standard v9 milestone
Sep 10, 2016
This comment has been minimized.
This comment has been minimized.
|
Agreed. Now that this is automatically fixable with |
feross
added
enhancement
and removed
question
labels
Sep 11, 2016
feross
modified the milestones:
standard v9,
standard v10
Feb 9, 2017
feross
added
the
ecosystem impact
label
Feb 9, 2017
feross
modified the milestones:
standard v10,
standard v11
Mar 2, 2017
This comment has been minimized.
This comment has been minimized.
|
I personally prefer without spaces. The reason is saving editor space-the line has only 80 characters and even two spaces can make a difference whether the line is overflowing or not. Many people would argue that it's more apparent when the braces are spaced-to those I would say-configure your editor to highlight them. I use a plugin https://marketplace.visualstudio.com/items?itemName=2gua.rainbow-brackets to make them more apparent and that works out better than trying to use spaces. |
This comment has been minimized.
This comment has been minimized.
langri-sha
commented
May 6, 2017
•
|
|
This comment has been minimized.
This comment has been minimized.
eddiemonge
commented
Jul 3, 2017
|
All the documentation shows spaces in object in the rules list so that should be whats used since it looks like its implied that it is. |
This comment has been minimized.
This comment has been minimized.
flipxfx
commented
Feb 7, 2018
|
@feross v9 is already behind us, really wish we could decide on this. I think this is the biggest part missing in standard and it's driving me nuts because there's still no consistency. In standard/eslint-config-standard#35 it looks like most people are leaning towards spaces around objects and not arrays. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I really think it's time that we take a decision on this! This is something that constantly creeps up during code review for me, and the promise of Standard was that that shouldn't happen. Let's fix this Here is the current eco-system impact:
I think we should just go with I'll send a PR now |
LinusU
added a commit
to standard/eslint-config-standard
that referenced
this issue
Jun 27, 2018
This comment has been minimized.
This comment has been minimized.
dougwilson
commented
Jun 27, 2018
|
FWIW as I have been using standard I have gone back and forth between never and always since standard allows both. Over time I have ended up with the always style. |
This comment has been minimized.
This comment has been minimized.
patrickabkarian
commented
Jul 5, 2018
•
|
This should be added as always, just because it's simply more readable and more consistent within object declarations. a: there is already a space after : it looks less awkward if u add all the spaces |
feross
modified the milestones:
standard v12,
standard v13
Aug 28, 2018
This comment has been minimized.
This comment has been minimized.
|
Thank you to everyone for sharing your thoughts on this issue. Thanks for sending the PR, @LinusU! Let's merge it and put this one behind us! |
feross
closed this
Aug 28, 2018
This comment has been minimized.
This comment has been minimized.
noygal
commented
Sep 3, 2018
|
Hi, first of all thank for all the effort you put into this project, I've been using it for years now (before that I was on "npm style guide") and I love the minimalist code it enforce. With regard to this rule addition to standard you render your tool useless for almost all my projects and other developers that use javascript functional programming approach. The minimal object notation reduce a lot of space on one liners and make the functional flow clearer. const foo = ({in1, in2}) => ({out1: in1.reduce((acc, el, i) => (acc[el] = {x: in2[i], y: i}) && acc, {})})This is conventional functional code example, readability is a matter of opinion, but I think that most would agreed that spacing out the objects won't make it any clearer. Just to clear that this not an opinionated view, check the docs for Ramda and Bobab - "the granddaddy" of functional programming in javascript: |
This comment has been minimized.
This comment has been minimized.
I don't think that this is true. I use functional programming a lot, and have no problems with having spaces in the curly objects.
I'm not sure I agree with this, the flow will still be exactly the same? I personally think that the spacing makes it more clear where the objects begin and end, which I think makes it easier to see where the definition of const foo = ({in1, in2}) => ({out1: in1.reduce((acc, el, i) => (acc[el] = {x: in2[i], y: i}) && acc, {})})
const foo = ({ in1, in2 }) => ({ out1: in1.reduce((acc, el, i) => (acc[el] = { x: in2[i], y: i }) && acc, {}) })Ultimately, we are of course going to upset a few people with this change, but I hope that you can see the benefit of unifying behind a single standard. As our testing indicated, most people already used spacing, and that's why we went with that... |
This comment has been minimized.
This comment has been minimized.
noygal
commented
Sep 3, 2018
With that approach we should have stayed with semicolon But honestly, I really can't argue with the your decisions regarding the future of standard, just to note that as a long time community user I find this decision as contradiction to the reasons I choose to use standard. For now I'll stay on v11, but I hope that more people would raised concerns about this issue. |
This comment has been minimized.
This comment has been minimized.
I was referring to the tests I ran on existing packages using standard, so no semicolons there
I'm not sure that we are aiming for minimalistic, the goal is to increase readability not remove as much as possible. e.g. this is still valid JS, but not too easy to read: const foo=({in1, in2})=>({out1:in1.reduce((acc,el,i)=>(acc[el]={x:in2[i],y:i})&&acc,{})})
Sounds like a good plan for now, if there is much push back on this we can of course reconsider. Although I don't think that many people will have a problem with it |
This comment has been minimized.
This comment has been minimized.
flipxfx
commented
Sep 5, 2018
|
@LinusU It looks like we addressed the object-curly-spacing but the array-bracket-spacing is still not decided? We currently use standardx just to enforce these:
|
This comment has been minimized.
This comment has been minimized.
|
@flipxfx oh, I thought we already were using Let's run the test and see how breaking it would be to add, as far as I've seen, it's not common to add spaces to arrays. If you want to run the ecosystem impact test that would be much appreciated
|
This comment has been minimized.
This comment has been minimized.
flipxfx
commented
Sep 6, 2018
|
This comment has been minimized.
This comment has been minimized.
flipxfx
commented
Sep 21, 2018
|
@LinusU should we create a new issue for this? It would be a simple fix and it seems |
This comment has been minimized.
This comment has been minimized.
|
Yes please, sounds good |

ischas commentedSep 1, 2016
•
edited
http://eslint.org/docs/rules/object-curly-spacing
http://eslint.org/docs/rules/array-bracket-spacing
Standard JS should define if there should be spaces inside of brackets and curly braces or not.
By now, following code is allowed but looks awkward:
Personally I have no preference if there should be spaces or not.