Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/rules/utils/__tests__/parseJestFnCall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,23 @@ ruleTester.run('esm', rule, {
`,
parserOptions: { sourceType: 'module' },
},
{
code: dedent`
import ByDefault from './myfile';

ByDefault.sayHello();
`,
parserOptions: { sourceType: 'module' },
},
{
code: dedent`
async function doSomething() {
const build = await rollup(config);
build.generate();
}
`,
parserOptions: { sourceType: 'module', ecmaVersion: 2017 },
},
],
invalid: [],
});
Expand Down Expand Up @@ -782,6 +799,14 @@ ruleTester.run('typescript', rule, {
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: { sourceType: 'module' },
},
{
code: dedent`
import dedent = require('dedent');

dedent();
`,
parser: require.resolve('@typescript-eslint/parser'),
},
],
invalid: [
{
Expand Down
17 changes: 8 additions & 9 deletions src/rules/utils/parseJestFnCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ const findImportSourceNode = (
): TSESTree.Node | null => {
if (node.type === AST_NODE_TYPES.AwaitExpression) {
if (node.argument.type === AST_NODE_TYPES.ImportExpression) {
return (node.argument as TSESTree.ImportExpression).source;
return node.argument.source;
}

return null;
Expand Down Expand Up @@ -499,15 +499,16 @@ const describePossibleImportDef = (def: TSESLint.Scope.Definition) => {
return null;
};

const resolveScope = (scope: TSESLint.Scope.Scope, identifier: string) => {
const resolveScope = (
scope: TSESLint.Scope.Scope,
identifier: string,
): ImportDetails | 'local' | null => {
let currentScope: TSESLint.Scope.Scope | null = scope;

while (currentScope !== null) {
for (const ref of currentScope.variables) {
if (ref.defs.length === 0) {
continue;
}
const ref = currentScope.set.get(identifier);

if (ref && ref.defs.length > 0) {
const def = ref.defs[ref.defs.length - 1];

const importDetails = describePossibleImportDef(def);
Expand All @@ -516,9 +517,7 @@ const resolveScope = (scope: TSESLint.Scope.Scope, identifier: string) => {
return importDetails;
}

if (ref.name === identifier) {
return 'local';
}
return 'local';
}

currentScope = currentScope.upper;
Expand Down