max-params
Enforce a maximum number of parameters in function definitions.
This rule extends the base eslint/max-params
rule.
This version adds support for TypeScript this
parameters so they won't be counted as a parameter.
How to Use
- Flat Config
- Legacy Config
eslint.config.mjs
export default tseslint.config({
rules: {
// Note: you must disable the base rule as it can report incorrect errors
"max-params": "off",
"@typescript-eslint/max-params": "error"
}
});
.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"max-params": "off",
"@typescript-eslint/max-params": "error"
}
};
Try this rule in the playground ↗
Options
See eslint/max-params
's options.
This rule adds the following options:
interface Options extends BaseMaxParamsOptions {
countVoidThis?: boolean;
}
const defaultOptions: Options = {
...baseMaxParamsOptions,
countVoidThis: false,
};
countVoidThis
Whether to count a this
declaration when the type is void
. Default: false
.
Example of a code when countVoidThis
is set to false
and max
is 1
:
- ❌ Incorrect
- ✅ Correct
function hasNoThis(this: void, first: string, second: string) {
// ...
}
Open in Playgroundfunction hasNoThis(this: void, first: string) {
// ...
}
Open in Playground