jscs-dev / node-jscs

:arrow_heading_up: JavaScript Code Style checker (unmaintained)
https://jscs-dev.github.io
MIT License
4.96k stars 513 forks source link

ES6, object keys, and spaces in function expression #2161

Closed indexzero closed 8 years ago

indexzero commented 8 years ago

EDIT: updated to reflect disallowSpacesInNamedFunctionExpression.beforeOpeningRoundBrace EDIT: updated BACK to reflect requireSpacesInAnonymousFunctionExpression.beforeOpeningRoundBrace based on #2162

The following config:

{
  "disallowSpaceAfterObjectKeys": true,
  "requireSpacesInAnonymousFunctionExpression": {
    "beforeOpeningRoundBrace": true
  },
  //
  // Also applies to less specific cousins
  // of requireSpacesInAnonymousFunctionExpression
  //
  // "requireSpacesInFunctionExpression": {
  //   "beforeOpeningRoundBrace": true
  // }
}

when evaluating the following ES6 code leads to an ambiguous resolution:

var fns = {
  foo() {
    console.log('hey Imma function');
  },
  /*function*/ because() {
    console.log('[space]function[space] becomes [space]');
  }
};
indexzero commented 8 years ago

Note: even more interesting is when autofix is enabled which leads to the fixer resolving this ambiguous rule ... well ambiguously as @DullReferenceException noted here

(...) the autofixer will add a space in one run, then remove it in the next.

indexzero commented 8 years ago

So the take away here is that we needed allexcept: shorthand. I'm going to leave this issue open to see if there might be a better way to explain these types of inherent conflicts to users without having to figure out the correct config incantation yourself https://github.com/jscs-dev/node-jscs/pull/2162#issuecomment-194422173

markelog commented 8 years ago

At this point only major and CST related bugs will be fixed.