Skip to content

Commit f21bdc6

Browse files
committed
feature: @putout/plugin-declare-before-reference: exclude not single VariableDeclaration
1 parent d794c2a commit f21bdc6

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

packages/plugin-declare-before-reference/lib/declare-before-reference.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const {
1515
isProgram,
1616
isArrowFunctionExpression,
1717
isExportDeclaration,
18+
isVariableDeclaration,
1819
} = types;
1920

2021
const isArrowOrBlock = (a) => isArrowFunctionExpression(a) || isBlockStatement(a);
@@ -118,6 +119,9 @@ export const traverse = ({push}) => ({
118119
if (!path.parentPath.node)
119120
continue;
120121

122+
if (!insideSingleDeclaration(path))
123+
continue;
124+
121125
if (own && declarationLine > referenceLine)
122126
push({
123127
name,
@@ -186,3 +190,10 @@ function checkKeys(path, referencePath) {
186190

187191
return path.key < key;
188192
}
193+
194+
function insideSingleDeclaration({parentPath}) {
195+
if (!isVariableDeclaration(parentPath))
196+
return true;
197+
198+
return parentPath.node.declarations.length === 1;
199+
}

packages/plugin-declare-before-reference/test/declare-before-reference.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ test('plugin-declare-before-reference: no report: returns', (t) => {
164164
t.end();
165165
});
166166

167+
test('plugin-declare-before-reference: no report: single', (t) => {
168+
t.noReport('single');
169+
t.end();
170+
});
171+
167172
test('plugin-declare-before-reference: transform: arg', (t) => {
168173
t.transform('arg');
169174
t.end();
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const SCOPE_TOP = 1,
2+
SCOPE_FUNCTION = 2,
3+
SCOPE_CLASS_STATIC_BLOCK = 256,
4+
SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;

0 commit comments

Comments
 (0)