β¬ οΈ Back to Table of Contents
π no-dynamic-delete¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 2 |
| π¦ Imports | 3 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/rules/no-dynamic-delete.ts
π€ Default Export¶
| Property | Value |
|---|---|
name |
'no-dynamic-delete' |
meta.type |
'suggestion' |
meta.docs.description |
'Disallow using the delete operator on computed key expressions' |
meta.docs.recommended |
'strict' |
meta.messages.dynamicDelete |
'Do not delete dynamically computed property keys.' |
meta.schema |
[] |
defaultOptions |
[] |
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): { 'UnaryExpression[operator=delete]'(node: TSESTree.UnaryEx⦶
Parameters:
contextany
Returns: { 'UnaryExpression[operator=delete]'(node: TSESTree.UnaryExpression): void; }
Calls:
isAcceptableIndexExpressioncontext.report
Code
create(context) {
return {
'UnaryExpression[operator=delete]'(node: TSESTree.UnaryExpression): void {
if (
node.argument.type !== AST_NODE_TYPES.MemberExpression ||
!node.argument.computed ||
isAcceptableIndexExpression(node.argument.property)
) {
return;
}
context.report({
node: node.argument.property,
messageId: 'dynamicDelete',
});
},
};
}
isAcceptableIndexExpression(property: TSESTree.Expression): boolean¶
Parameters:
propertyTSESTree.Expression
Returns: boolean
Calls:
['number', 'string'].includes
Code
function isAcceptableIndexExpression(property: TSESTree.Expression): boolean {
return (
(property.type === AST_NODE_TYPES.Literal &&
['number', 'string'].includes(typeof property.value)) ||
(property.type === AST_NODE_TYPES.UnaryExpression &&
property.operator === '-' &&
property.argument.type === AST_NODE_TYPES.Literal &&
typeof property.argument.value === 'number')
);
}
Generated by Syntax Scribe