Skip to content

Commit 2d05252

Browse files
authored
Use getScopes (#1428)
1 parent 17581e2 commit 2d05252

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

rules/no-unused-properties.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const getScopes = require('./utils/get-scopes.js');
23

34
const MESSAGE_ID = 'no-unused-properties';
45
const messages = {
@@ -211,25 +212,16 @@ const create = context => {
211212
}
212213
};
213214

214-
const checkChildScopes = scope => {
215-
for (const childScope of scope.childScopes) {
216-
checkScope(childScope);
217-
}
218-
};
219-
220-
const checkScope = scope => {
221-
if (scope.type === 'global') {
222-
return checkChildScopes(scope);
223-
}
224-
225-
checkVariables(scope);
226-
227-
return checkChildScopes(scope);
228-
};
229-
230215
return {
231216
'Program:exit'() {
232-
checkScope(context.getScope());
217+
const scopes = getScopes(context.getScope());
218+
for (const scope of scopes) {
219+
if (scope.type === 'global') {
220+
continue;
221+
}
222+
223+
checkVariables(scope);
224+
}
233225
},
234226
};
235227
};

rules/prefer-ternary.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const getIndentString = require('./utils/get-indent-string.js');
77
const {getParenthesizedText} = require('./utils/parentheses.js');
88
const shouldAddParenthesesToConditionalExpressionChild = require('./utils/should-add-parentheses-to-conditional-expression-child.js');
99
const {extendFixRange} = require('./fix/index.js');
10+
const getScopes = require('./utils/get-scopes.js');
1011

1112
const messageId = 'prefer-ternary';
1213

@@ -40,11 +41,6 @@ function getNodeBody(node) {
4041
return node;
4142
}
4243

43-
const getScopes = scope => [
44-
scope,
45-
...scope.childScopes.flatMap(scope => getScopes(scope)),
46-
];
47-
4844
const isSingleLineNode = node => node.loc.start.line === node.loc.end.line;
4945

5046
const create = context => {

0 commit comments

Comments
 (0)