-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
Object curlies: File/project–wide or standard? #35
Comments
Personally, I've been struggling with the choice between |
Agreed. I've seen a lot of inconsistency in a multi-person Standard project with different bikeshed preferences ensuring both styles We've rolled a custom rule to prevent this. But like, so non-Standard. Also don't care which style prevails, but picking one seems squarely in Standard's decision space. |
I thought I was alone on struggling to pick a side on this, but it seems the lack of clear choice is quite common. Is the hard part what @timdp pointed out? const array = [one, two];
const object = { one, two }; const array = [one, two];
const object = {one, two}; const array = [ one, two ];
const object = { one, two }; |
@feross, it might be time to "just pick something" for the next version IMHO. I'd be happy with either:
But, I don't mind as long as it is enforced. |
Apparently the Surely the fact that compliance can be automated like this makes this a less controversial change? Why would you bring 1 or 2 files into compliance rather than the whole project, when doing the whole project is this simple? |
@dcousens I'm fine with going with your latter example, since that's more consistent. I usually add spaces around my objects, but consistency is more important. If |
Looks like I'm going to be fixing a lot of scripts soon, but all the better! 👍 |
@feross my only aversion to the latter is let map = {a: 1} instead of let map = { a: 1 } I think the spacing keeps up a form of spacial difference, where the tightly packed array allows you immediately recognize it. Obviously subjective. Removing padding spaces from object definitions might actually lead to mistakes since it looks closer to an array. |
You raise a good point. This is definitely very subjective. 😅 Btw, it would be: let map = {a: 1} Not: let map = {a:1} |
I wonder if either is "easier" to search for? |
|
Agreed with @cayuu. |
This line: import {belongsTo/*, hasMany*/} from 'ember-data/relationships' triggers this error:
I believe it should be considered valid: it contains no stray whitespace; a comment is not whitespace. |
Should I file a separate issue? Into which repo? |
@mightyiam The offending rule is |
Woops |
@lolmaus Yes, this is a separate issue. Please file it here: https://github.com/xjamundx/eslint-plugin-standard |
@dcousens in your example up there was that about destructuring? I'd be pretty happy doing file-wide enforcement. I was the one that wrote that original instance-wide enforcement before and probably should have done file-wide instead. My personal pref is |
@xjamundx no, it was about object definitions in general |
No spaces (e.g. But there's an argument to be made that And like @dcousens says, it makes objects visually distinctive from arrays. This is also currently my preferred code style. |
I think that |
My preferred style is |
@jprichardson Good points. Seems that no spaces (except for blocks, which are pretty different) is the most consistent, no? |
I see this issue hasn't had any discussion in almost 4 months. Regarding @feross's comment, "We can revisit all this in early 2017", maybe now is the time. After reading all the discussion, my preference has converted from spaceless-objects to spacey-objects, but now I also want spacey-arrays for a few reasons already mentioned:
var u = {
x: 1,
y: 3
}
var f = {x: 1, y: 3}
Well, we can do similar with arrays: var a = [
x,
y
]
var b = [x, y] Are these similarly inconsistent? Probably. This argument isn't that convincing to me, but it goes with the other two. |
It'd be handy for some accord to be reached between https://github.com/jlongster/prettier and JavaScript Standard |
@jokeyrhyme I would discuss that in another issue. I'm 👍 on spacey. And on determining this. |
I'm also on the spacey side. Arrays and object literals are two different things, so I think the "inconsistency" between |
What I was thinking about last few months. I'm pretty used to spacey objects, but not spacey arrays (maybe sometimes, hm). var a = { x: 2 }
var a = {
x: 1
}
var a = {
x: 1,
y: 2
}
var a = [
x,
y
]
var b = [x]
var b = [123]
var b = [ x, y ]
var b = [ { a: 'b' }, 2, { c: 3 }, 4 ]
var b = [{ a: 'b' }]
var b = [ { a: 'b' } ] // too much spaces? above is better
var b = {
a: 1,
b: {
c: [ { cc: 22 }, 333 ]
},
d: [ 'e', 444, [ 1, 2, 3 ] ]
} If we apply consistency, it may seem too spacey in some times, but in most cases it would be separated in separate lines, so won't maybe won't look too spacey. As about the |
It's worth noting that this change (no matter which way we go - but especially spaced-arrays), is likely to affect a significant portion of We have three options for concluding this:
My preference would be for 1 or 3. I'm wary of a "happened to be in the room" policy approach (2). |
What is the ecosystem impact of either? |
Started at the top of the README list of companies, left to right:
..then I got tired looking ;) |
For some perspective, it looks like the prettier folks couldn't decide and just made this a "bracketSpacing" option: |
@jokeyrhyme |
@wuhkuh I just mention prettier, because it's another example of an opinionated style guide, and it's been a difficult enough decision to make that they've made it an option In principle, I agree that eliminating pointless bike-shedding and decision-making is the noble goal of an opinionated project |
Despite the fact that npm and opbeat use tight arrays, I still prefer spacey for the reasons @thejohnfreeman put down. There are also tools available that update existing code to suit the standard. This debunks 'patching my enormous package is a ton of work!'. I would like to add that if we decide which way to go, we could start by sending warnings instead of erroring when this patch is just introduced. EditTo counter my bias towards spacey, consider the following situation: const obj = { ooh: 'that', is: 'spacey' }
console.log(obj[ 'is' ]) // wait, what? |
paypal uses tight arrays FWIW |
Just realized that having spacey arrays is a way to distinguish array literals and property access 🤔 const array = [ 1 ]
const number = array[0] |
I see more often about spacey objects than spacey arrays, space arrays feel a bit awkward to me const obj = { a: 1, b: 2 }
const arr = [1, 2] I personally find this more readable import React, { Component } from 'react'
import { connect } from 'react-redux'
import { getItems } from '../actions'
const objItems = [{ one: 1 }, { two: 2 }]
const App = () => (
<div
style={{ height: '100vh' }}
objItems={objItems}
arrItems={[1, 2]}
/>
)
const mapStateToProps = ({ aReducer, bReducer }) => ({ aReducer, bReducer })
export default connect(mapStateToProps, { getItems })(App) Than this import React, {Component} from 'react'
import {connect} from 'react-redux'
import {getItems} from '../actions'
const objItems = [{one: 1}, {two: 2}]
const App = () => (
<div
style={{height: '100vh'}}
objItems={objItems}
arrItems={[1, 2]}
/>
)
const mapStateToProps = ({aReducer, bReducer}) => ({aReducer, bReducer})
export default connect(mapStateToProps, {getItems})(App) PD: Sorry for using long noisy examples |
For those of you looking for a quick fix in the meantime:
Careful, this will replace an exisiting
This workaround got rid of the majority of my non-fixable standard.js errors. Apparently, at least for me, inconsistent spacing happens a lot less often with array-bracket-spacing. So my suggestion is to just define Count me in on spacey objects. ❤️ Standard.js |
I might have changed my mind on this. An array looks clean already without spaced-style, and spaced arrays make statements and declarations harder to read in some cases. const Obj = {
properties: [ { type: Object } ] // this sucks. Lets add an exception
}
const Arr = [ ] // sure
console.log(Obj[ 'properties' ]) // this sucks. Lets add an exception Before you know it, we forgot what we tried to achieve: consistency. If we want to patch those situations we would need exceptions to keep it readable (and convenient), therefore making it less consistent. My vote is for spaced objects and tight arrays. Arrays are readable and consistent as they are. @feross Could you update us on the status? |
That's totally different rule - edit:
I really dont like empty things to have space |
I was just mentoring a person. On a project where we use standard. And I chose to just not tell him to space out the objects. It came out like this: |
I like this a lot. I'm sure it will impact a lot, so maybe for the next major version. |
Hey guys it's been almost a year since this issue was opened. I'm going to add a quote from the FAQ
I think in all this time people have been given the opportunity to express their opinion, but it's time to decide. I really don't have a preference, I just want to see this issue close, I have colleges using both approach and I can't enforce a style on them, because as @mightyiam just said, we have a linter for that (That we really like) and the CI passes. You are always going to find people who prefer one way or the other, but I don't think they will just remove standard from their projects just because they disagree with a rule. Cheers. |
Rest assured that this will be decided in a future version. There's no need for folks to continue weighing in. The past few releases have had some pretty large breaking changes, and there's a limit to how many breaking changes we can include in a given release. I'll lock this issue to save everyone some time. |
Thank you to everyone for sharing your thoughts on this issue. Thanks to @LinusU for the analysis in this comment and for sending a PR: standard/standard#609 (comment) The rule to enforce spacing inside of braces will be included in the |
So, we got #21 and that's great.
It got us instance–wide consistency.
Now, what about file–wide consistency, as was mentioned here?
And, now that I'm thinking about it, why not project–wide consistency?
And thinking further, why not choose a style as standard?
Either no spaces (
{a, b}
) or a single space ({ a, b }
).The text was updated successfully, but these errors were encountered: