📄 TypeOrValueSpecifier¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 6 |
| 📦 Imports | 7 |
| 📊 Variables & Constants | 1 |
| 📐 Interfaces | 3 |
| 📑 Type Aliases | 1 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/type-utils/src/TypeOrValueSpecifier.ts
📦 Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/types |
JSONSchema4 |
@typescript-eslint/utils/json-schema |
AST_NODE_TYPES |
@typescript-eslint/types |
specifierNameMatches |
./typeOrValueSpecifiers/specifierNameMatches |
typeDeclaredInFile |
./typeOrValueSpecifiers/typeDeclaredInFile |
typeDeclaredInLib |
./typeOrValueSpecifiers/typeDeclaredInLib |
typeDeclaredInPackageDeclarationFile |
./typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
typeOrValueSpecifiersSchema |
JSONSchema4 |
const | { items: { oneOf: [ { type: 'string', }, { additionalProperties: false, prope... |
✓ |
Functions¶
typeMatchesSpecifier(type: ts.Type, specifier: TypeOrValueSpecifier, program: ts.Program): boolean¶
Parameters:
typets.TypespecifierTypeOrValueSpecifierprogramts.Program
Returns: boolean
Calls:
tsutils.isUnionTypetype.types.everytypeMatchesSpecifiercomplex_call_4343tsutils.isIntrinsicErrorTypespecifierNameMatches (from ./typeOrValueSpecifiers/specifierNameMatches)type.getSymbolsymbol?.getDeclarationsdeclarations.mapdeclaration.getSourceFiletypeDeclaredInFile (from ./typeOrValueSpecifiers/typeDeclaredInFile)typeDeclaredInLib (from ./typeOrValueSpecifiers/typeDeclaredInLib)typeDeclaredInPackageDeclarationFile (from ./typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile)tsutils.isIntersectionTypetsutils .intersectionConstituents(type) .some
Code
export function typeMatchesSpecifier(
type: ts.Type,
specifier: TypeOrValueSpecifier,
program: ts.Program,
): boolean {
if (tsutils.isUnionType(type)) {
return type.types.every(t => typeMatchesSpecifier(t, specifier, program));
}
const wholeTypeMatches = ((): boolean => {
if (tsutils.isIntrinsicErrorType(type)) {
return false;
}
if (typeof specifier === 'string') {
return specifierNameMatches(type, specifier);
}
if (!specifierNameMatches(type, specifier.name)) {
return false;
}
const symbol = type.getSymbol() ?? type.aliasSymbol;
const declarations = symbol?.getDeclarations() ?? [];
const declarationFiles = declarations.map(declaration =>
declaration.getSourceFile(),
);
switch (specifier.from) {
case 'file':
return typeDeclaredInFile(specifier.path, declarationFiles, program);
case 'lib':
return typeDeclaredInLib(declarationFiles, program);
case 'package':
return typeDeclaredInPackageDeclarationFile(
specifier.package,
declarations,
declarationFiles,
program,
);
}
})();
if (wholeTypeMatches) {
return true;
}
if (
tsutils.isIntersectionType(type) &&
tsutils
.intersectionConstituents(type)
.some(part => typeMatchesSpecifier(part, specifier, program))
) {
return true;
}
return false;
}
typeMatchesSomeSpecifier(type: ts.Type, specifiers: TypeOrValueSpecifier[], program: ts.Program): boolean¶
Parameters:
typets.TypespecifiersTypeOrValueSpecifier[]programts.Program
Returns: boolean
Calls:
specifiers.some
Code
valueMatchesSpecifier(node: TSESTree.Node, specifier: TypeOrValueSpecifier, program: ts.Program, type: ts.Type): boolean¶
Parameters:
nodeTSESTree.NodespecifierTypeOrValueSpecifierprogramts.Programtypets.Type
Returns: boolean
Calls:
getStaticNamegetSpecifierNames(specifier.name).includestype.getSymbolsymbol?.getDeclarationsdeclarations.mapdeclaration.getSourceFiletypeDeclaredInPackageDeclarationFile (from ./typeOrValueSpecifiers/typeDeclaredInPackageDeclarationFile)
Code
export function valueMatchesSpecifier(
node: TSESTree.Node,
specifier: TypeOrValueSpecifier,
program: ts.Program,
type: ts.Type,
): boolean {
const staticName = getStaticName(node);
if (!staticName) {
return false;
}
if (typeof specifier === 'string') {
return specifier === staticName;
}
if (!getSpecifierNames(specifier.name).includes(staticName)) {
return false;
}
if (specifier.from === 'package') {
const symbol = type.getSymbol() ?? type.aliasSymbol;
const declarations = symbol?.getDeclarations() ?? [];
const declarationFiles = declarations.map(declaration =>
declaration.getSourceFile(),
);
return typeDeclaredInPackageDeclarationFile(
specifier.package,
declarations,
declarationFiles,
program,
);
}
return true;
}
valueMatchesSomeSpecifier(node: TSESTree.Node, specifiers: TypeOrValueSpecifier[], program: ts.Program, type: ts.Type): boolean¶
Parameters:
nodeTSESTree.NodespecifiersTypeOrValueSpecifier[]programts.Programtypets.Type
Returns: boolean
Calls:
specifiers.some
Code
getSpecifierNames(specifierName: string | string[]): string[]¶
Parameters:
specifierNamestring | string[]
Returns: string[]
Code
getStaticName(node: TSESTree.Node): string | undefined¶
Parameters:
nodeTSESTree.Node
Returns: string | undefined
Code
(node: TSESTree.Node): string | undefined => {
if (
node.type === AST_NODE_TYPES.Identifier ||
node.type === AST_NODE_TYPES.JSXIdentifier ||
node.type === AST_NODE_TYPES.PrivateIdentifier
) {
return node.name;
}
if (node.type === AST_NODE_TYPES.Literal && typeof node.value === 'string') {
return node.value;
}
return undefined;
}
Interfaces¶
FileSpecifier¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
from |
'file' |
✗ | not shown |
name |
string \| string[] |
✗ | not shown |
path |
string |
✓ | not shown |
LibSpecifier¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
from |
'lib' |
✗ | not shown |
name |
string \| string[] |
✗ | not shown |
PackageSpecifier¶
Interface Code
Properties¶
| Name | Type | Optional | Description |
|---|---|---|---|
from |
'package' |
✗ | not shown |
name |
string \| string[] |
✗ | not shown |
package |
string |
✗ | not shown |
Type Aliases¶
TypeOrValueSpecifier¶
/* * A centralized format for rule options to describe specific types and/or values. * See TypeOrValueSpecifier. /
Generated by Syntax Scribe