📄 no-empty-function.ts
¶
📊 Analysis Summary¶
Metric | Count |
---|---|
🔧 Functions | 5 |
📦 Imports | 8 |
📊 Variables & Constants | 4 |
📑 Type Aliases | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/rules/no-empty-function.ts
📦 Imports¶
Name | Source |
---|---|
TSESTree |
@typescript-eslint/utils |
JSONSchema4 |
@typescript-eslint/utils/json-schema |
AST_NODE_TYPES |
@typescript-eslint/utils |
InferMessageIdsTypeFromRule |
../util |
InferOptionsTypeFromRule |
../util |
createRule |
../util |
deepMerge |
../util |
getESLintCoreRule |
../util/getESLintCoreRule |
Variables & Constants¶
Name | Type | Kind | Value | Exported |
---|---|---|---|---|
defaultOptions |
Options |
const | `[ | |
{ | ||||
allow: [], | ||||
}, | ||||
]` | ✗ | |||
schema |
JSONSchema4 |
const | `deepMerge( | |
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- https://github.com/microsoft/TypeScript/issues/17002 | ||||
Array.isArray(baseRule.meta.schema) | ||||
? baseRule.meta.schema[0] | ||||
: baseRule.meta.schema, | ||||
{ | ||||
properties: { | ||||
allow: { | ||||
description: | ||||
'Locations and kinds of functions that are allowed to be empty.', | ||||
items: { | ||||
type: 'string', | ||||
enum: [ | ||||
'functions', | ||||
'arrowFunctions', | ||||
'generatorFunctions', | ||||
'methods', | ||||
'generatorMethods', | ||||
'getters', | ||||
'setters', | ||||
'constructors', | ||||
'private-constructors', | ||||
'protected-constructors', | ||||
'asyncFunctions', | ||||
'asyncMethods', | ||||
'decoratedFunctions', | ||||
'overrideMethods', | ||||
], | ||||
}, | ||||
}, | ||||
}, | ||||
}, | ||||
) as unknown as JSONSchema4` | ✗ | |||
parent |
any |
const | node.parent |
✗ |
decorators |
any |
const | `node.parent.type === AST_NODE_TYPES.MethodDefinition | |
? node.parent.decorators | ||||
: undefined` | ✗ |
Functions¶
isBodyEmpty(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression): boolean
¶
Code
-
JSDoc:
-
Parameters:
node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression
- Return Type:
boolean
hasParameterProperties(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression): boolean
¶
Code
-
JSDoc:
-
Parameters:
node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression
- Return Type:
boolean
- Calls:
node.params.some
isAllowedEmptyConstructor(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression): boolean
¶
Code
function isAllowedEmptyConstructor(
node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression,
): boolean {
const parent = node.parent;
if (
isBodyEmpty(node) &&
parent.type === AST_NODE_TYPES.MethodDefinition &&
parent.kind === 'constructor'
) {
const { accessibility } = parent;
return (
// allow protected constructors
(accessibility === 'protected' && isAllowedProtectedConstructors) ||
// allow private constructors
(accessibility === 'private' && isAllowedPrivateConstructors) ||
// allow constructors which have parameter properties
hasParameterProperties(node)
);
}
return false;
}
-
JSDoc:
-
Parameters:
node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression
- Return Type:
boolean
- Calls:
isBodyEmpty
hasParameterProperties
- Internal Comments:
isAllowedEmptyDecoratedFunctions(node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression): boolean
¶
Code
function isAllowedEmptyDecoratedFunctions(
node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression,
): boolean {
if (isAllowedDecoratedFunctions && isBodyEmpty(node)) {
const decorators =
node.parent.type === AST_NODE_TYPES.MethodDefinition
? node.parent.decorators
: undefined;
return !!decorators && !!decorators.length;
}
return false;
}
-
JSDoc:
-
Parameters:
node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression
- Return Type:
boolean
- Calls:
isBodyEmpty
isAllowedEmptyOverrideMethod(node: TSESTree.FunctionExpression): boolean
¶
Code
- Parameters:
node: TSESTree.FunctionExpression
- Return Type:
boolean
- Calls:
isBodyEmpty