jscs-dev / node-jscs

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

the airbnb rules makes conflict #2242

Closed petrelselina closed 8 years ago

petrelselina commented 8 years ago

requireTrailingComma:true disallowSpacesInsideArrayBrackets:true requireSpaceAfterComma:true These 3 rules in presets/airbnb.json , please show me how to write an array. It must write comma before closing bracket, if write space after comma, but cannot write space before closing bracket, so there is no way to write an array.

petrelselina commented 8 years ago

I mean write an array in single line, thx.

qfox commented 8 years ago

Hello.

According to https://github.com/airbnb/javascript#arrays--callback-return it should looks like these:

// good
[1, 2, 3].map(x => x + 1);

// good
const flat = {};
[[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => {
  const flatten = memo.concat(item);
  flat[index] = flatten;
  return flatten;
});

It looks like a bug tho since requireTrailingComma should not require it for inlined arrays.

/cc @markelog @hzoo Thoughts?

markelog commented 8 years ago

Just run jscs --preset airbnb on

const flat = {};
[[0, 1], [2, 3], [4, 5]].reduce((memo, item, index) => {
  const flatten = memo.concat(item);
  flat[index] = flatten;
  return flatten;
});

Don't see any errors. With those three rules i also don't see any contradictions.

@petrelselina i'm gonna close this for now, please ping us up if you find any bugs, thank you