javascript
javascript copied to clipboard
Misleading documentation 10.8
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.
#2205
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.
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)
In that case, please file it on eslint itself.
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?
https://github.com/eslint/eslint/issues/12018