Skip to content

Commit 62f5580

Browse files
committed
wip: modify the implementation to properly lint against and fix when more vars are declared on the same line and fix failing tests
1 parent 3356e35 commit 62f5580

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

projects/eslint-plugin/rules/general/lib/rules/blank-line-declaration-usage.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ module.exports = {
2121
return;
2222
}
2323

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

26-
const declarationLine = references[0].identifier.loc.start.line;
26+
const declarationLine =
27+
varsDeclaredOnLine[0].identifiers[0].loc.start.line;
2728

28-
references.slice(1).forEach((reference) => {
29-
const referenceLine = reference.identifier.loc.start.line;
29+
varsDeclaredOnLine.forEach((reference) => {
30+
const varReference = reference.references[1];
31+
32+
if (varReference === undefined) {
33+
return;
34+
}
35+
36+
const referenceLine =
37+
varReference.identifier.loc.start.line;
3038

3139
if (
3240
sourceCode.lines
@@ -42,7 +50,7 @@ module.exports = {
4250
}
4351
},
4452
message,
45-
node: reference.identifier,
53+
node: reference.references[1].identifier,
4654
});
4755
}
4856
});

projects/eslint-plugin/rules/general/tests/lib/rules/blank-line-declaration-usage.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,20 +121,14 @@ ruleTester.run('blank-line-declaration-usage', rule, {
121121
bar: 'foo',
122122
life: 'ray',
123123
}
124-
124+
125125
const {foo} = obj;
126126
127127
const length = foo.length;
128128
`,
129129
},
130130
{
131131
code: `
132-
const obj = {
133-
foo: 'bar',
134-
bar: 'foo',
135-
life: 'ray',
136-
}
137-
138132
const {foo, bar, life} = obj;
139133
const length = life.length;
140134
`,
@@ -145,12 +139,6 @@ ruleTester.run('blank-line-declaration-usage', rule, {
145139
},
146140
],
147141
output: `
148-
const obj = {
149-
foo: 'bar',
150-
bar: 'foo',
151-
life: 'ray',
152-
}
153-
154142
const {foo, bar, life} = obj;
155143
156144
const length = life.length;
@@ -227,8 +215,8 @@ ruleTester.run('blank-line-declaration-usage', rule, {
227215
bar: 'foo',
228216
life: 'ray',
229217
}
230-
231-
Object.keys(obj)
218+
219+
Object.keys(obj).map(key => {});
232220
`,
233221
},
234222
{
@@ -240,7 +228,7 @@ ruleTester.run('blank-line-declaration-usage', rule, {
240228
}
241229
242230
const {foo} = obj;
243-
231+
244232
const length = foo.length;
245233
`,
246234
},

0 commit comments

Comments
 (0)