📄 max-params¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 3 |
| 📦 Imports | 6 |
| 📑 Type Aliases | 4 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/rules/max-params.ts
📤 Default Export¶
| Property | Value |
|---|---|
name |
'max-params' |
meta.type |
'suggestion' |
meta.docs.description |
'Enforce a maximum number of parameters in function definitions' |
meta.docs.extendsBaseRule |
true |
meta.messages |
baseRule.meta.messages |
meta.schema |
[ { type: 'object', additionalProperties: false, properties: { countVoidThis: { type: 'boolean', description: 'Whethe... |
defaultOptions |
[{ countVoidThis: false, max: 3 }] |
Entry point: create — documented under Functions.
📦 Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
InferMessageIdsTypeFromRule |
../util |
InferOptionsTypeFromRule |
../util |
createRule |
../util |
getESLintCoreRule |
../util/getESLintCoreRule |
Functions¶
create(context: any, [{ countVoidThis }]: any): any¶
Parameters:
contextany[{ countVoidThis }]any
Returns: any
Calls:
baseRule.createnode.params.slicelistenerremoveVoidThisParamwrapListener
Code
create(context, [{ countVoidThis }]) {
const baseRules = baseRule.create(context);
if (countVoidThis === true) {
return baseRules;
}
const removeVoidThisParam = <T extends FunctionLike>(node: T): T => {
if (
node.params.length === 0 ||
node.params[0].type !== AST_NODE_TYPES.Identifier ||
node.params[0].name !== 'this' ||
node.params[0].typeAnnotation?.typeAnnotation.type !==
AST_NODE_TYPES.TSVoidKeyword
) {
return node;
}
return {
...node,
params: node.params.slice(1),
};
};
const wrapListener = <T extends FunctionLike>(
listener: FunctionRuleListener<T>,
): FunctionRuleListener<T> => {
return (node: T): void => {
listener(removeVoidThisParam(node));
};
};
return {
ArrowFunctionExpression: wrapListener(baseRules.ArrowFunctionExpression),
FunctionDeclaration: wrapListener(baseRules.FunctionDeclaration),
FunctionExpression: wrapListener(baseRules.FunctionExpression),
TSDeclareFunction: wrapListener(baseRules.FunctionDeclaration),
TSFunctionType: wrapListener(baseRules.FunctionDeclaration),
};
}
Internal helpers¶
Declared inside another function in this file.
removeVoidThisParam(node: T): T¶
Parameters:
nodeT
Returns: T
Calls:
node.params.slice
Code
<T extends FunctionLike>(node: T): T => {
if (
node.params.length === 0 ||
node.params[0].type !== AST_NODE_TYPES.Identifier ||
node.params[0].name !== 'this' ||
node.params[0].typeAnnotation?.typeAnnotation.type !==
AST_NODE_TYPES.TSVoidKeyword
) {
return node;
}
return {
...node,
params: node.params.slice(1),
};
}
wrapListener(listener: FunctionRuleListener<T>): FunctionRuleListener<T>¶
Parameters:
listenerFunctionRuleListener<T>
Returns: FunctionRuleListener<T>
Calls:
listenerremoveVoidThisParam
Code
Type Aliases¶
FunctionLike¶
type FunctionLike = | TSESTree.ArrowFunctionExpression
| TSESTree.FunctionDeclaration
| TSESTree.FunctionExpression
| TSESTree.TSDeclareFunction
| TSESTree.TSFunctionType;
FunctionRuleListener<T extends FunctionLike>¶
Options¶
MessageIds¶
Generated by Syntax Scribe