javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Misleading documentation 10.8

Open kagant15 opened this issue 4 years ago • 6 comments

The documentation for 10.8 references object-curly-newline however object-curly-newline does not catch this rule. Furthermore airbnb's set of rules also doesn't catch this rule.

See Example

The guidance is good, however the documentation leads you to believe the linter will catch you if you put imports on the same line, which it doesn't.

kagant15 avatar Apr 08 '20 18:04 kagant15

#2205

kagant15 avatar Apr 08 '20 18:04 kagant15

The eslint link should not give you any confidence that the linter will cover the entire guideline - you always have to keep the entire guide in your head, just in case.

https://github.com/airbnb/javascript/blob/06b3ab11d9a443ff46f052dd00375e271e5146e6/packages/eslint-config-airbnb-base/rules/style.js#L396-L401 should definitely be catching that example - it's defined to only kick in if you have 4 or more imported names.

ljharb avatar Apr 08 '20 21:04 ljharb

Unless I'm missing something I think this may be a bug. I just tested this out again with the following:

// -- constants.js
export const one = 'one';
export const two = 'two';
export const three = 'three';
export const four = 'four';
export const five = 'five';
// -- example.js
import {
  one, two, three, four, five,
} from './constants';

if (one && two && three && four && five) {
  console.log('done');
}
// -- .eslintrc
{
"extends": ["airbnb"]
}
// -- package.json
"devDependencies": {
  "eslint-config-airbnb": "^18.1.0"
}

eslint --print-config example.js


  "object-curly-newline": [
      "error",
      {
        "ObjectExpression": {
          "minProperties": 4,
          "multiline": true,
          "consistent": true
        },
        "ObjectPattern": {
          "minProperties": 4,
          "multiline": true,
          "consistent": true
        },
        "ImportDeclaration": {
          "minProperties": 4,
          "multiline": true,
          "consistent": true
        },
        "ExportDeclaration": {
          "minProperties": 4,
          "multiline": true,
          "consistent": true
        }
      }
    ],

eslint example.js

6:3 warning Unexpected console statement no-console

✖ 1 problem (0 errors, 1 warning)

kagant15 avatar Apr 09 '20 12:04 kagant15

In that case, please file it on eslint itself.

ljharb avatar Apr 09 '20 21:04 ljharb

I think the "consistent" rule is satisfied if all of the properties are on the same line, even if the braces aren't. If you have a newline in the middle of the list, what happens?

ljharb avatar Apr 09 '20 21:04 ljharb

https://github.com/eslint/eslint/issues/12018

xiaoxiyao avatar Oct 29 '20 10:10 xiaoxiyao