Skip to content

Commit

Permalink
fix(declaration-order): ignore use after the declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
forivall committed Apr 25, 2023
1 parent f7e41ce commit 2f6e67d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rules/declaration-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ module.exports = {
for (const reference of variable.references) {
const idRange = reference.identifier.range;

if (idRange[0] >= declaration.range[1]) {
if (
idRange[0] >= declaration.range[1] &&
idRange[1] <= node.range[0]
) {
if (first) {
prevDeclarations.shift();
// eslint-disable-next-line no-labels
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/declaration-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,10 @@ new RuleTester().run("declaration-order", rule, {
parserOptions: { ecmaVersion: 6 },
errors: letConstErrors,
},
{
code: "const c = []; let b; const d = []; c.push(b); const a = [...c]",
parserOptions: { ecmaVersion: 6 },
errors: [{ ...letConstErrors[0], column: 22 }],
},
],
});

0 comments on commit 2f6e67d

Please sign in to comment.