diff --git a/src/rules/export.ts b/src/rules/export.ts index 7d5f7373a..4eb28b423 100644 --- a/src/rules/export.ts +++ b/src/rules/export.ts @@ -1,4 +1,5 @@ -import { AST_NODE_TYPES, type TSESTree } from '@typescript-eslint/utils' +import { AST_NODE_TYPES } from '@typescript-eslint/utils' +import type { TSESTree } from '@typescript-eslint/utils' import { ExportMap, @@ -6,7 +7,6 @@ import { createRule, getValue, } from '../utils' -import type { type } from 'node:os'; /* Notes on TypeScript namespaces aka TSModuleDeclaration: @@ -40,12 +40,15 @@ const tsTypePrefix = 'type:' * ``` */ function removeTypescriptFunctionOverloads(nodes: Set) { - nodes.forEach((node) => { - const declType = node.type === AST_NODE_TYPES.ExportDefaultDeclaration ? node.declaration.type : node.parent?.type; + for (const node of nodes) { + const declType = + node.type === AST_NODE_TYPES.ExportDefaultDeclaration + ? node.declaration.type + : node.parent?.type if (declType === AST_NODE_TYPES.TSDeclareFunction) { - nodes.delete(node); + nodes.delete(node) } - }); + } } /** @@ -266,7 +269,7 @@ export = createRule<[], MessageId>({ continue } - removeTypescriptFunctionOverloads(nodes); + removeTypescriptFunctionOverloads(nodes) if (nodes.size <= 1) { continue diff --git a/src/utils/export-map.ts b/src/utils/export-map.ts index 14330a52b..22c749741 100644 --- a/src/utils/export-map.ts +++ b/src/utils/export-map.ts @@ -131,7 +131,7 @@ export class ExportMap { // If the visitor keys were not populated, then we shouldn't save anything to the cache, // since the parse results may not be reliable. if (exportMap.visitorKeys) { - exportCache.set(cacheKey, exportMap); + exportCache.set(cacheKey, exportMap) } return exportMap @@ -153,7 +153,7 @@ export class ExportMap { let ast: TSESTree.Program let visitorKeys: TSESLint.SourceCode.VisitorKeys | null try { - ; ({ ast, visitorKeys } = parse(filepath, content, context)) + ;({ ast, visitorKeys } = parse(filepath, content, context)) } catch (error) { m.errors.push(error as ParseError) return m // can't continue @@ -532,17 +532,17 @@ export class ExportMap { const exportedName = n.type === 'TSNamespaceExportDeclaration' ? ( - n.id || - // @ts-expect-error - legacy parser type - n.name - ).name + n.id || + // @ts-expect-error - legacy parser type + n.name + ).name : ('expression' in n && - n.expression && - (('name' in n.expression && n.expression.name) || - ('id' in n.expression && - n.expression.id && - n.expression.id.name))) || - null + n.expression && + (('name' in n.expression && n.expression.name) || + ('id' in n.expression && + n.expression.id && + n.expression.id.name))) || + null const getRoot = ( node: TSESTree.TSQualifiedName, @@ -561,7 +561,7 @@ export class ExportMap { ('name' in node.id ? node.id.name === exportedName : 'left' in node.id && - getRoot(node.id).name === exportedName)) || + getRoot(node.id).name === exportedName)) || ('declarations' in node && node.declarations.find( d => 'name' in d.id && d.id.name === exportedName, @@ -730,7 +730,7 @@ export class ExportMap { declare doc: Annotation | undefined - constructor(public path: string) { } + constructor(public path: string) {} get hasDefault() { return this.get('default') != null diff --git a/src/utils/parse.ts b/src/utils/parse.ts index b06b14b26..61b94383c 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -29,7 +29,7 @@ function withoutProjectParserOptions( const log = debug('eslint-plugin-import-x:parse') function keysFromParser( - parserPath: string | TSESLint.Parser.ParserModule, + _parserPath: string | TSESLint.Parser.ParserModule, parserInstance: TSESLint.Parser.ParserModule, parsedResult?: TSESLint.Parser.ParseResult, ) { @@ -40,7 +40,11 @@ function keysFromParser( // The espree parser doesn't have the `parseForESLint` function, so we don't ended up with a // `parsedResult` here, but it does expose the visitor keys on the parser instance that we can use. - if (parserInstance && 'VisitorKeys' in parserInstance && parserInstance.VisitorKeys) { + if ( + parserInstance && + 'VisitorKeys' in parserInstance && + parserInstance.VisitorKeys + ) { return parserInstance.VisitorKeys as TSESLint.SourceCode.VisitorKeys } return null diff --git a/test/rules/export.spec.ts b/test/rules/export.spec.ts index 6f8b9bcb2..f9ce211e7 100644 --- a/test/rules/export.spec.ts +++ b/test/rules/export.spec.ts @@ -64,8 +64,8 @@ ruleTester.run('export', rule, { export default function foo(param: string, param1?: number): boolean { return param && param1; } - ` - } + `, + }, ], invalid: [ @@ -175,11 +175,8 @@ ruleTester.run('export', rule, { export default function a() {} export { x as default }; `, - errors: [ - 'Multiple default exports.', - 'Multiple default exports.', - ], - }) + errors: ['Multiple default exports.', 'Multiple default exports.'], + }), ], }) diff --git a/test/rules/no-default-export.spec.ts b/test/rules/no-default-export.spec.ts index 168785d28..e38ce7b6e 100644 --- a/test/rules/no-default-export.spec.ts +++ b/test/rules/no-default-export.spec.ts @@ -14,7 +14,7 @@ ruleTester.run('no-default-export', rule, { parserOptions: { sourceType: 'script', }, - } + }, }), test({ code: 'module.exports = function foo() {}', diff --git a/test/rules/no-named-export.spec.ts b/test/rules/no-named-export.spec.ts index 0886a2cf5..55829764a 100644 --- a/test/rules/no-named-export.spec.ts +++ b/test/rules/no-named-export.spec.ts @@ -17,7 +17,7 @@ ruleTester.run('no-named-export', rule, { parserOptions: { sourceType: 'script', }, - } + }, }), test({ code: 'export default function bar() {};', diff --git a/test/utils/export-map.spec.ts b/test/utils/export-map.spec.ts index a0a35bd5c..c60f77c26 100644 --- a/test/utils/export-map.spec.ts +++ b/test/utils/export-map.spec.ts @@ -34,9 +34,11 @@ describe('ExportMap', () => { const mockContext = { ...fakeContext, parserPath: 'not-real', - }; - expect(ExportMap.get('./named-exports', mockContext)).toBeDefined(); - expect(ExportMap.get('./named-exports', mockContext)).not.toBe(ExportMap.get('./named-exports', mockContext)); + } + expect(ExportMap.get('./named-exports', mockContext)).toBeDefined() + expect(ExportMap.get('./named-exports', mockContext)).not.toBe( + ExportMap.get('./named-exports', mockContext), + ) }) it('does not return a cached copy after modification', done => {