β¬ οΈ Back to Table of Contents
π consistent-type-exports.ts¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 6 |
| π¦ Imports | 11 |
| π Variables & Constants | 11 |
| π Interfaces | 2 |
| π Type Aliases | 2 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/rules/consistent-type-exports.ts
π¦ Imports¶
| Name | Source |
|---|---|
TSESLint |
@typescript-eslint/utils |
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
AST_TOKEN_TYPES |
@typescript-eslint/utils |
createRule |
../util |
formatWordList |
../util |
getParserServices |
../util |
isClosingBraceToken |
../util |
isOpeningBraceToken |
../util |
nullThrows |
../util |
NullThrowsReasons |
../util |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
sourceExportsMap |
Record<string, SourceExports> |
const | {} |
β |
aliasedSymbol |
any |
const | `tsutils.isSymbolFlagSet( | |
| symbol, | ||||
| ts.SymbolFlags.Alias, | ||||
| ) | ||||
| ? checker.getAliasedSymbol(symbol) | ||||
| : symbol` | β | |||
source |
string |
const | getSourceFromExport(node) ?? 'undefined' |
β |
sourceExports |
SourceExports |
const | `(sourceExportsMap[source] | |
| reportValueExports: [], | ||||
| source, | ||||
| typeOnlyNamedExport: null, | ||||
| valueOnlyNamedExport: null, | ||||
| })` | β | |||
typeBasedSpecifiers |
TSESTree.ExportSpecifier[] |
const | [] |
β |
inlineTypeSpecifiers |
TSESTree.ExportSpecifier[] |
const | [] |
β |
valueSpecifiers |
TSESTree.ExportSpecifier[] |
const | [] |
β |
exportNames |
any |
const | allExportNames[0] |
β |
typeSpecifiers |
any[] |
let/var | [...typeBasedSpecifiers, ...inlineTypeSpecifiers] |
β |
exportedName |
any |
const | `specifier.exported.type === AST_NODE_TYPES.Literal | |
| ? specifier.exported.raw | ||||
| : specifier.exported.name` | β | |||
localName |
any |
const | `specifier.local.type === AST_NODE_TYPES.Literal | |
| ? specifier.local.raw | ||||
| : specifier.local.name` | β |
Functions¶
isSymbolTypeBased(symbol: ts.Symbol | undefined): boolean | undefined¶
Code
function isSymbolTypeBased(
symbol: ts.Symbol | undefined,
): boolean | undefined {
if (!symbol) {
return undefined;
}
const aliasedSymbol = tsutils.isSymbolFlagSet(
symbol,
ts.SymbolFlags.Alias,
)
? checker.getAliasedSymbol(symbol)
: symbol;
if (checker.isUnknownSymbol(aliasedSymbol)) {
return undefined;
}
return !(aliasedSymbol.flags & ts.SymbolFlags.Value);
}
-
JSDoc:
-
Parameters:
symbol: ts.Symbol | undefined- Return Type:
boolean | undefined - Calls:
tsutils.isSymbolFlagSetchecker.getAliasedSymbolchecker.isUnknownSymbol
fixExportInsertType(fixer: TSESLint.RuleFixer, sourceCode: Readonly<TSESLint.SourceCode>, node: TSESTree.ExportNamedDeclaration): IterableIterator<TSESLint.RuleFix>¶
Code
function* fixExportInsertType(
fixer: TSESLint.RuleFixer,
sourceCode: Readonly<TSESLint.SourceCode>,
node: TSESTree.ExportNamedDeclaration,
): IterableIterator<TSESLint.RuleFix> {
const exportToken = nullThrows(
sourceCode.getFirstToken(node),
NullThrowsReasons.MissingToken('export', node.type),
);
yield fixer.insertTextAfter(exportToken, ' type');
for (const specifier of node.specifiers) {
if (specifier.exportKind === 'type') {
const kindToken = nullThrows(
sourceCode.getFirstToken(specifier),
NullThrowsReasons.MissingToken('export', specifier.type),
);
const firstTokenAfter = nullThrows(
sourceCode.getTokenAfter(kindToken, {
includeComments: true,
}),
'Missing token following the export kind.',
);
yield fixer.removeRange([kindToken.range[0], firstTokenAfter.range[0]]);
}
}
}
-
JSDoc:
-
Parameters:
fixer: TSESLint.RuleFixersourceCode: Readonly<TSESLint.SourceCode>node: TSESTree.ExportNamedDeclaration- Return Type:
IterableIterator<TSESLint.RuleFix> - Calls:
nullThrows (from ../util)sourceCode.getFirstTokenNullThrowsReasons.MissingTokenfixer.insertTextAftersourceCode.getTokenAfterfixer.removeRange
fixSeparateNamedExports(fixer: TSESLint.RuleFixer, sourceCode: Readonly<TSESLint.SourceCode>, report: ReportValueExport): IterableIterator<TSESLint.RuleFix>¶
Code
function* fixSeparateNamedExports(
fixer: TSESLint.RuleFixer,
sourceCode: Readonly<TSESLint.SourceCode>,
report: ReportValueExport,
): IterableIterator<TSESLint.RuleFix> {
const { node, inlineTypeSpecifiers, typeBasedSpecifiers, valueSpecifiers } =
report;
const typeSpecifiers = [...typeBasedSpecifiers, ...inlineTypeSpecifiers];
const source = getSourceFromExport(node);
const specifierNames = typeSpecifiers.map(getSpecifierText).join(', ');
const exportToken = nullThrows(
sourceCode.getFirstToken(node),
NullThrowsReasons.MissingToken('export', node.type),
);
// Filter the bad exports from the current line.
const filteredSpecifierNames = valueSpecifiers
.map(getSpecifierText)
.join(', ');
const openToken = nullThrows(
sourceCode.getFirstToken(node, isOpeningBraceToken),
NullThrowsReasons.MissingToken('{', node.type),
);
const closeToken = nullThrows(
sourceCode.getLastToken(node, isClosingBraceToken),
NullThrowsReasons.MissingToken('}', node.type),
);
// Remove exports from the current line which we're going to re-insert.
yield fixer.replaceTextRange(
[openToken.range[1], closeToken.range[0]],
` ${filteredSpecifierNames} `,
);
// Insert the bad exports into a new export line above.
yield fixer.insertTextBefore(
exportToken,
`export type { ${specifierNames} }${source ? ` from '${source}'` : ''};\n`,
);
}
-
JSDoc:
-
Parameters:
fixer: TSESLint.RuleFixersourceCode: Readonly<TSESLint.SourceCode>report: ReportValueExport- Return Type:
IterableIterator<TSESLint.RuleFix> - Calls:
getSourceFromExporttypeSpecifiers.map(getSpecifierText).joinnullThrows (from ../util)sourceCode.getFirstTokenNullThrowsReasons.MissingTokenvalueSpecifiers .map(getSpecifierText) .joinsourceCode.getLastTokenfixer.replaceTextRangefixer.insertTextBefore- Internal Comments:
fixAddTypeSpecifierToNamedExports(fixer: TSESLint.RuleFixer, report: ReportValueExport): IterableIterator<TSESLint.RuleFix>¶
Code
- Parameters:
fixer: TSESLint.RuleFixerreport: ReportValueExport- Return Type:
IterableIterator<TSESLint.RuleFix> - Calls:
fixer.insertTextBefore
getSourceFromExport(node: TSESTree.ExportNamedDeclaration): string | undefined¶
Code
-
JSDoc:
-
Parameters:
node: TSESTree.ExportNamedDeclaration- Return Type:
string | undefined
getSpecifierText(specifier: TSESTree.ExportSpecifier): string¶
Code
function getSpecifierText(specifier: TSESTree.ExportSpecifier): string {
const exportedName =
specifier.exported.type === AST_NODE_TYPES.Literal
? specifier.exported.raw
: specifier.exported.name;
const localName =
specifier.local.type === AST_NODE_TYPES.Literal
? specifier.local.raw
: specifier.local.name;
return `${localName}${
exportedName !== localName ? ` as ${exportedName}` : ''
}`;
}
-
JSDoc:
-
Parameters:
specifier: TSESTree.ExportSpecifier- Return Type:
string
Interfaces¶
SourceExports¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
reportValueExports |
ReportValueExport[] |
β | |
source |
string |
β | |
typeOnlyNamedExport |
TSESTree.ExportNamedDeclaration | null |
β | |
valueOnlyNamedExport |
TSESTree.ExportNamedDeclaration | null |
β |
ReportValueExport¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
inlineTypeSpecifiers |
TSESTree.ExportSpecifier[] |
β | |
node |
TSESTree.ExportNamedDeclaration |
β | |
typeBasedSpecifiers |
TSESTree.ExportSpecifier[] |
β | |
valueSpecifiers |
TSESTree.ExportSpecifier[] |
β |