Follow-ups from eslint4 upgrade
During the eslint 4 upgrade (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/19182) we had to do some compromises in order to keep the merge small. Here they are in order of magnitude (Statistics generated on e9c5e57b with yarn run eslint 2>&1 | rg --only-matching "\s\s\S+$" | awk '{$1=$1;print}' | sort | uniq -c
):
6110 indent
139 prefer-destructuring
54 no-restricted-globals
26 no-multi-assign
The ones with the least lints are also easier to fix. We also should accept community contributions, especially the no-restricted-globals
and no-multi-assign
should be easier to fix.
indent-legacy
instead indent
eslint 4 made indent
much more strict. That's why we use indent-legacy
. We should check out if the new indent
goes hand in hand with our prettier settings or not, and then switch to it.
Reference from the eslint upgrade guide
✅ Disabled prefer-destructuring
Airbnb enforces it for arrays and objects, except for VariableDeclarator
when speaking about arrays. So this would be the wrong code:
let foo = obj.foo;
foo = array[0];
foo = obj.foo;
Correct code:
let bar = array[0];
let {foo} = obj;
[foo] = array[0];
{foo} = obj;
Update: MR: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/19943
✅ camelcase
with option ignoreDestructuring
Directly related to the rule prefer-destructuring
. When using a version of eslint>4.12.1
we get new camelcase lints.. We often use this pattern when we are extracting info from the API, because it sends snake case:
const {camel_case} = obj;
In eslint 4 the camelcase
rule will now warn about that. So you'd either have to do:
const {camel_case: camelCase} = obj;
//or
const {camel_case} = obj; // eslint-disable-line camelcase
There is currently this open PR: https://github.com/eslint/eslint/pull/10373 which plans to implement ignoreDestructing
for the camel case rule.
(See also: https://gitlab.com/gitlab-org/gitlab-ce/issues/40476#note_75361384)
Update: We will gain support for the parameter with eslint 5 (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/21825)
✅ Disabled no-restricted-globals
Our offenders are:
9 Unexpected use of 'confirm'
1 Unexpected use of 'event'
12 Unexpected use of 'history'
1 Unexpected use of 'innerHeight'
3 Unexpected use of 'isNaN'
23 Unexpected use of 'location'
1 Unexpected use of 'pageYOffset'
4 Unexpected use of 'self'
✅ Disabled no-multi-assignment
This rule simply disallows let foo = bar = 1
. Reference