🌐 AI搜索 & 代理 主页
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
23 changes: 9 additions & 14 deletions packages/eslint-plugin/src/rules/consistent-type-exports.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { TSESLint, TSESTree } from '@typescript-eslint/utils';

import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '@typescript-eslint/utils';
import * as tsutils from 'ts-api-utils';
import * as ts from 'typescript';

import {
Expand Down Expand Up @@ -91,22 +90,18 @@ export default createRule<Options, MessageIds>({
function isSymbolTypeBased(
symbol: ts.Symbol | undefined,
): boolean | undefined {
if (!symbol) {
return undefined;
while (symbol && symbol.flags & ts.SymbolFlags.Alias) {
symbol = checker.getAliasedSymbol(symbol);
if (
symbol.getDeclarations()?.find(ts.isTypeOnlyImportOrExportDeclaration)
) {
return true;
}
}

const aliasedSymbol = tsutils.isSymbolFlagSet(
symbol,
ts.SymbolFlags.Alias,
)
? checker.getAliasedSymbol(symbol)
: symbol;

if (checker.isUnknownSymbol(aliasedSymbol)) {
if (!symbol || checker.isUnknownSymbol(symbol)) {
return undefined;
}

return !(aliasedSymbol.flags & ts.SymbolFlags.Value);
return !(symbol.flags & ts.SymbolFlags.Value);
}

return {
Expand Down
26 changes: 26 additions & 0 deletions packages/eslint-plugin/tests/rules/consistent-type-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export { NonTypeNS };
"export type * as foo from './consistent-type-exports/type-only-exports';",
"export type * as foo from './consistent-type-exports/type-only-reexport';",
"export * as foo from './consistent-type-exports/value-reexport';",
`
import * as Foo from './consistent-type-exports';
type Foo = 1;
export { Foo }
`,
],
invalid: [
{
Expand Down Expand Up @@ -483,5 +488,26 @@ export {
export type * as foo from './consistent-type-exports/type-only-reexport';
`,
},
{
code: `
import type * as Foo from './consistent-type-exports';
type Foo = 1;
export { Foo };
`,
errors: [
{
column: 9,
endColumn: 24,
endLine: 4,
line: 4,
messageId: 'typeOverValue',
},
],
output: `
import type * as Foo from './consistent-type-exports';
type Foo = 1;
export type { Foo };
`,
},
],
});
Loading