β¬ οΈ Back to Table of Contents
π no-wrapper-object-types¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 2 |
| π¦ Imports | 5 |
| π Variables & Constants | 1 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/rules/no-wrapper-object-types.ts
π€ Default Export¶
| Property | Value |
|---|---|
name |
'no-wrapper-object-types' |
meta.type |
'problem' |
meta.docs.description |
'Disallow using confusing built-in primitive class wrappers' |
meta.docs.recommended |
'recommended' |
meta.fixable |
'code' |
meta.messages.bannedClassType |
'Prefer using the primitive {{preferred}} as a type name, rather than the upper-cased {{typeName}}.' |
meta.schema |
[] |
defaultOptions |
[] |
Entry point: create β documented under Functions.
π¦ Imports¶
| Name | Source |
|---|---|
TSESLint |
@typescript-eslint/utils |
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
createRule |
../util |
isReferenceToGlobalFunction |
../util |
Variables & Constants¶
| Name | Type | Kind | Value | Exported |
|---|---|---|---|---|
classNames |
Set<string> |
const | new Set([ 'BigInt', // eslint-disable-next-line @typescript-eslint/internal/p... |
β |
Functions¶
create(context: any): { TSClassImplements(node: any): void; TSInterfaceHeritage(n⦶
Parameters:
contextany
Returns: { TSClassImplements(node: any): void; TSInterfaceHeritage(node: any): void; TSTypeReference(node: any): void; }
Calls:
classNames.hasisReferenceToGlobalFunction (from ../util)typeName.toLowerCasecontext.reportfixer.replaceTextcheckBannedTypes
Code
create(context) {
function checkBannedTypes(
node: TSESTree.EntityName | TSESTree.Expression,
includeFix: boolean,
): void {
const typeName = node.type === AST_NODE_TYPES.Identifier && node.name;
if (
!typeName ||
!classNames.has(typeName) ||
!isReferenceToGlobalFunction(typeName, node, context.sourceCode)
) {
return;
}
const preferred = typeName.toLowerCase();
context.report({
node,
messageId: 'bannedClassType',
data: { preferred, typeName },
fix: includeFix
? (fixer): TSESLint.RuleFix => fixer.replaceText(node, preferred)
: undefined,
});
}
return {
TSClassImplements(node): void {
checkBannedTypes(node.expression, false);
},
TSInterfaceHeritage(node): void {
checkBannedTypes(node.expression, false);
},
TSTypeReference(node): void {
checkBannedTypes(node.typeName, true);
},
};
}
Internal helpers¶
Declared inside another function in this file.
checkBannedTypes(node: TSESTree.EntityName | TSESTree.Expressiβ¦, includeFix: boolean): void¶
Parameters:
nodeTSESTree.EntityName | TSESTree.ExpressionincludeFixboolean
Returns: void
Calls:
classNames.hasisReferenceToGlobalFunction (from ../util)typeName.toLowerCasecontext.reportfixer.replaceText
Code
function checkBannedTypes(
node: TSESTree.EntityName | TSESTree.Expression,
includeFix: boolean,
): void {
const typeName = node.type === AST_NODE_TYPES.Identifier && node.name;
if (
!typeName ||
!classNames.has(typeName) ||
!isReferenceToGlobalFunction(typeName, node, context.sourceCode)
) {
return;
}
const preferred = typeName.toLowerCase();
context.report({
node,
messageId: 'bannedClassType',
data: { preferred, typeName },
fix: includeFix
? (fixer): TSESLint.RuleFix => fixer.replaceText(node, preferred)
: undefined,
});
}
Generated by Syntax Scribe