jscs-dev / babel-jscs

(deprecated) JSCS has merged with ESLint, so check out babel-eslint!
https://github.com/babel/babel-eslint
MIT License
27 stars 6 forks source link

`disallowSpaceAfterObjectKeys` evaluating functions as objects in 2.0.x #20

Closed EvHaus closed 9 years ago

EvHaus commented 9 years ago

After upgrading to 2.0.x, the disallowSpaceAfterObjectKeys rule is now throwing a ton of warnings for me which it didn't used to. Sample:

render () {
------^
    71 |  var classes = {},
    72 |   ACLS = 'Administration-Sidebar';
disallowSpaceAfterObjectKeys: Illegal space after key

It seems that function declarations are now evaluated as object keys.

I want to force a space after the function name and before the parenthesis, but not for objects. ie.

{
    // This spacing is good!
    render () {}
}

// This spacing is bad!
{"test" : "abc"}

This used to work fine in 1.x.x, but in 2.0.x, something has changed.

mrjoelkemp commented 9 years ago

That shorthand is technically an object property whose value is a function expression which is why it's evaluated.

We have a test in JSCS core showing that this is the expected behavior: https://github.com/jscs-dev/node-jscs/blob/ca39a8912b4d498432fc92230b8a68f82174cd48/test/specs/rules/disallow-space-after-object-keys.js#L180-L186.

Sounds like you want a new rule value like allExcept: ['functionShorthand']. I'm not actually sure what the proper name for that "shorthand" version is. @mikesherov would know. We'll substitute "shorthand" with whatever it is.

@globexdesigns Would you mind creating an issue for this in JSCS proper?

EvHaus commented 9 years ago

Done. Issue opened with JSCS.

mrjoelkemp commented 9 years ago

Great. Thanks @globexdesigns