Skip to content

Commit

Permalink
wip: modify the implementation to properly lint against and fix when …
Browse files Browse the repository at this point in the history
…more vars are declared on the same line and fix failing tests
  • Loading branch information
kresimir-coko committed Nov 15, 2021
1 parent 3356e35 commit 62f5580
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@ module.exports = {
return;
}

const {references} = context.getDeclaredVariables(node)[0];
const varsDeclaredOnLine = context.getDeclaredVariables(node);

const declarationLine = references[0].identifier.loc.start.line;
const declarationLine =
varsDeclaredOnLine[0].identifiers[0].loc.start.line;

references.slice(1).forEach((reference) => {
const referenceLine = reference.identifier.loc.start.line;
varsDeclaredOnLine.forEach((reference) => {
const varReference = reference.references[1];

if (varReference === undefined) {
return;
}

const referenceLine =
varReference.identifier.loc.start.line;

if (
sourceCode.lines
Expand All @@ -42,7 +50,7 @@ module.exports = {
}
},
message,
node: reference.identifier,
node: reference.references[1].identifier,
});
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,14 @@ ruleTester.run('blank-line-declaration-usage', rule, {
bar: 'foo',
life: 'ray',
}
const {foo} = obj;
const length = foo.length;
`,
},
{
code: `
const obj = {
foo: 'bar',
bar: 'foo',
life: 'ray',
}
const {foo, bar, life} = obj;
const length = life.length;
`,
Expand All @@ -145,12 +139,6 @@ ruleTester.run('blank-line-declaration-usage', rule, {
},
],
output: `
const obj = {
foo: 'bar',
bar: 'foo',
life: 'ray',
}
const {foo, bar, life} = obj;
const length = life.length;
Expand Down Expand Up @@ -227,8 +215,8 @@ ruleTester.run('blank-line-declaration-usage', rule, {
bar: 'foo',
life: 'ray',
}
Object.keys(obj)
Object.keys(obj).map(key => {});
`,
},
{
Expand All @@ -240,7 +228,7 @@ ruleTester.run('blank-line-declaration-usage', rule, {
}
const {foo} = obj;
const length = foo.length;
`,
},
Expand Down

0 comments on commit 62f5580

Please sign in to comment.