β¬ οΈ Back to Table of Contents
π no-this-alias¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 1 |
| π¦ Imports | 3 |
| π Type Aliases | 2 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/rules/no-this-alias.ts
π€ Default Export¶
| Property | Value |
|---|---|
name |
'no-this-alias' |
meta.type |
'suggestion' |
meta.docs.description |
'Disallow aliasing this' |
meta.docs.recommended |
'recommended' |
meta.messages.thisAssignment |
"Unexpected aliasing of 'this' to local variable." |
meta.messages.thisDestructure |
"Unexpected aliasing of members of 'this' to local variables." |
meta.schema |
[ { type: 'object', additionalProperties: false, properties: { allowDestructuring: { type: 'boolean', description: 'W... |
defaultOptions |
[ { allowDestructuring: true, allowedNames: [], }, ] |
Entry point: create β documented under Functions.
π¦ Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
createRule |
../util |
Functions¶
create(context: any, [{ allowDestructuring, allowedNβ¦: any): { "VariableDeclarator[init.type='ThisExpression'], Assignme⦶
Parameters:
contextany[{ allowDestructuring, allowedNames }]any
Returns: { "VariableDeclarator[init.type='ThisExpression'], AssignmentExpression[right.type='ThisExpression']"(node: TSESTree.AssignmentExpression | TSESTree.VariableDeclarator): void; }
Calls:
allowedNames!.includescontext.report
Internal Comments:
Code
create(context, [{ allowDestructuring, allowedNames }]) {
return {
"VariableDeclarator[init.type='ThisExpression'], AssignmentExpression[right.type='ThisExpression']"(
node: TSESTree.AssignmentExpression | TSESTree.VariableDeclarator,
): void {
const id =
node.type === AST_NODE_TYPES.VariableDeclarator ? node.id : node.left;
if (allowDestructuring && id.type !== AST_NODE_TYPES.Identifier) {
return;
}
const hasAllowedName =
id.type === AST_NODE_TYPES.Identifier
? // https://github.com/typescript-eslint/typescript-eslint/issues/5439
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
allowedNames!.includes(id.name)
: false;
if (!hasAllowedName) {
context.report({
node: id,
messageId:
id.type === AST_NODE_TYPES.Identifier
? 'thisAssignment'
: 'thisDestructure',
});
}
},
};
}
Type Aliases¶
Options¶
MessageIds¶
Generated by Syntax Scribe