eslint-plugin-func-params-args 4.0.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -1
- package/dist/index.js +1 -1
- package/dist/rules/func-params.js +1 -1
- package/docs/rules/func-args.md +50 -0
- package/docs/rules/func-params.md +50 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Limit the number of function parameters and arguments with ease and flexibility!
|
|
|
4
4
|
|
|
5
5
|
This plugin intends to give you control over how many parameters are used in function definitions (declarations), function expressions, arrow function expressions, and TypeScript function type annotations. In addition to this, you can also set limits on how many arguments can be used when calling functions, where you can set a global limit, and have even finer control by providing limits for specific function calls (set by configuring/providing the name of a function).
|
|
6
6
|
|
|
7
|
-
[](https://github.com/abdusabri/eslint-plugin-func-params-args/actions) [](https://coveralls.io/github/abdusabri/eslint-plugin-func-params-args) [](https://renovatebot.com)
|
|
8
8
|
|
|
9
9
|
## Table of contents
|
|
10
10
|
|
|
@@ -53,6 +53,8 @@ npm install eslint-plugin-func-params-args --save-dev
|
|
|
53
53
|
|
|
54
54
|
## General usage notes
|
|
55
55
|
|
|
56
|
+
### ESLint v8 (eslintrc)
|
|
57
|
+
|
|
56
58
|
Add `func-params-args` to the plugins section of your `.eslintrc.json` configuration file. You can omit the `eslint-plugin-` prefix:
|
|
57
59
|
|
|
58
60
|
```json
|
|
@@ -96,6 +98,54 @@ rules:
|
|
|
96
98
|
'$emit': 2
|
|
97
99
|
```
|
|
98
100
|
|
|
101
|
+
### ESLint v9 (flat config)
|
|
102
|
+
|
|
103
|
+
For ESLint v9 with flat config (`eslint.config.js` or `eslint.config.mjs`), import the plugin and configure it as follows:
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
import funcParamsArgs from 'eslint-plugin-func-params-args';
|
|
107
|
+
|
|
108
|
+
export default [
|
|
109
|
+
{
|
|
110
|
+
plugins: {
|
|
111
|
+
'func-params-args': funcParamsArgs,
|
|
112
|
+
},
|
|
113
|
+
rules: {
|
|
114
|
+
'func-params-args/func-args': [
|
|
115
|
+
'warn',
|
|
116
|
+
{
|
|
117
|
+
global: 3,
|
|
118
|
+
$emit: 2,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Or using CommonJS (`eslint.config.cjs`):
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
const funcParamsArgs = require('eslint-plugin-func-params-args');
|
|
130
|
+
|
|
131
|
+
module.exports = [
|
|
132
|
+
{
|
|
133
|
+
plugins: {
|
|
134
|
+
'func-params-args': funcParamsArgs,
|
|
135
|
+
},
|
|
136
|
+
rules: {
|
|
137
|
+
'func-params-args/func-args': [
|
|
138
|
+
'warn',
|
|
139
|
+
{
|
|
140
|
+
global: 3,
|
|
141
|
+
$emit: 2,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
```
|
|
148
|
+
|
|
99
149
|
As shown in the example above, the configuration approach for this plugin's rules uses a simple object structure (no arrays or nested objects), where keys like `$emit` are the options, and the value of a given key is the limit (like `2`). So, in the example above, it means that any calls to `$emit` function should have no more than `2` arguments, and the global limit for any other function call is `3`.
|
|
100
150
|
|
|
101
151
|
### No defaults
|
|
@@ -106,6 +156,8 @@ By design, this plugin's rules don't have pre-set defaults. So, you've to config
|
|
|
106
156
|
|
|
107
157
|
ESLint's eco-system is full of parsers and plugins taking care of non-JavaScript files, like TypeScript and JSX for example. This plugin doesn't provide its own parser (nor does it have a custom AST parsing logic). So, handling non-JS files depends on your existing ESLint setup.
|
|
108
158
|
|
|
159
|
+
#### ESLint v8 (eslintrc)
|
|
160
|
+
|
|
109
161
|
As an example, to use this plugin in TS files, you may configure parsing options in your `.eslintrc` file as follows:
|
|
110
162
|
|
|
111
163
|
If you don't have any existing parsers (or other plugins that are already taking care of handling TS files)
|
|
@@ -127,6 +179,32 @@ Or you may override only the parsing of TS files if you've other parsers or plug
|
|
|
127
179
|
|
|
128
180
|
In both examples above, you would need to install `@typescript-eslint/parser` from npm.
|
|
129
181
|
|
|
182
|
+
#### ESLint v9 (flat config)
|
|
183
|
+
|
|
184
|
+
For ESLint v9 with flat config, configure the parser in `languageOptions`:
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
import funcParamsArgs from 'eslint-plugin-func-params-args';
|
|
188
|
+
import tsParser from '@typescript-eslint/parser';
|
|
189
|
+
|
|
190
|
+
export default [
|
|
191
|
+
{
|
|
192
|
+
files: ['**/*.ts', '**/*.tsx'],
|
|
193
|
+
languageOptions: {
|
|
194
|
+
parser: tsParser,
|
|
195
|
+
},
|
|
196
|
+
plugins: {
|
|
197
|
+
'func-params-args': funcParamsArgs,
|
|
198
|
+
},
|
|
199
|
+
rules: {
|
|
200
|
+
'func-params-args/func-params': ['warn', { global: 3 }],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
You would need to install `@typescript-eslint/parser` from npm.
|
|
207
|
+
|
|
130
208
|
## Available rules
|
|
131
209
|
|
|
132
210
|
- [enforce the number of parameters used in a function definition or expression (func-params)](./docs/rules/func-params.md)
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var requireIndex=require("requireindex")
|
|
1
|
+
"use strict";var requireIndex=require("requireindex"),pkg=require("../package.json"),plugin={meta:{name:pkg.name,version:pkg.version},rules:requireIndex(__dirname+"/rules")};module.exports=plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const{BASE_URL,isOptionConfigured}=require("../utils"),utils=require("eslint-utils");function mapTypeToConfigKey(a){return"FunctionDeclaration"===a?"funcDefinition":"ArrowFunctionExpression"===a?"arrowFuncExpression":"FunctionExpression"===a?"funcExpression":"TSFunctionType"===a||"TSMethodSignature"===a?"funcTypeAnnotation":void 0}function getFunctionNameWithKind(a){return"TSFunctionType"===a.type?"TSTypeAliasDeclaration"===a.parent?.type?`function '${a.parent.id.name}'`:"TSTypeAnnotation"===a.parent?.type&&"Identifier"===a.parent.parent?.type?`function '${a.parent.parent.name}'`:`function '${a.parent?.parent?.key?.name}'`:"TSMethodSignature"===a.type?`function '${a.key?.name}'`:utils.getFunctionNameWithKind(a)}module.exports={meta:{type:"problem",docs:{description:"enforce the number of parameters used in a function definition or expression",url:BASE_URL+"func-params.md"},schema:[{type:"object",properties:{global:{type:"integer",minimum:-1},funcDefinition:{type:"integer",minimum:-1},funcExpression:{type:"integer",minimum:-1},arrowFuncExpression:{type:"integer",minimum:-1},funcTypeAnnotation:{type:"integer",minimum:-1}},additionalProperties:!1}],messages:{exceed:"{{name}} has too many parameters ({{count}}). Maximum allowed is ({{max}})."}},create(a){function b(b,c){a.report({node:b,messageId:"exceed",data:c})}function c(a,c){0<=c&&a.params.length>c&&b(a,{count:a.params.length,max:c,name:getFunctionNameWithKind(a)})}function d(a){const b=mapTypeToConfigKey(a.type);let d=-1;isOptionConfigured(e,b)?d=e[b]:isOptionConfigured(e,"global")&&(d=e.global),c(a,d)}const e=a.options[0]||{};return{FunctionDeclaration:d,ArrowFunctionExpression:d,FunctionExpression:d,TSFunctionType:d,TSMethodSignature:d}}};
|
|
1
|
+
"use strict";const{BASE_URL,isOptionConfigured}=require("../utils"),utils=require("@eslint-community/eslint-utils");function mapTypeToConfigKey(a){return"FunctionDeclaration"===a?"funcDefinition":"ArrowFunctionExpression"===a?"arrowFuncExpression":"FunctionExpression"===a?"funcExpression":"TSFunctionType"===a||"TSMethodSignature"===a?"funcTypeAnnotation":void 0}function getFunctionNameWithKind(a){return"TSFunctionType"===a.type?"TSTypeAliasDeclaration"===a.parent?.type?`function '${a.parent.id.name}'`:"TSTypeAnnotation"===a.parent?.type&&"Identifier"===a.parent.parent?.type?`function '${a.parent.parent.name}'`:`function '${a.parent?.parent?.key?.name}'`:"TSMethodSignature"===a.type?`function '${a.key?.name}'`:utils.getFunctionNameWithKind(a)}module.exports={meta:{type:"problem",docs:{description:"enforce the number of parameters used in a function definition or expression",url:BASE_URL+"func-params.md"},schema:[{type:"object",properties:{global:{type:"integer",minimum:-1},funcDefinition:{type:"integer",minimum:-1},funcExpression:{type:"integer",minimum:-1},arrowFuncExpression:{type:"integer",minimum:-1},funcTypeAnnotation:{type:"integer",minimum:-1}},additionalProperties:!1}],messages:{exceed:"{{name}} has too many parameters ({{count}}). Maximum allowed is ({{max}})."}},create(a){function b(b,c){a.report({node:b,messageId:"exceed",data:c})}function c(a,c){0<=c&&a.params.length>c&&b(a,{count:a.params.length,max:c,name:getFunctionNameWithKind(a)})}function d(a){const b=mapTypeToConfigKey(a.type);let d=-1;isOptionConfigured(e,b)?d=e[b]:isOptionConfigured(e,"global")&&(d=e.global),c(a,d)}const e=a.options[0]||{};return{FunctionDeclaration:d,ArrowFunctionExpression:d,FunctionExpression:d,TSFunctionType:d,TSMethodSignature:d}}};
|
package/docs/rules/func-args.md
CHANGED
|
@@ -24,6 +24,8 @@ If you want to disable this rule (removing all restrictions) for any of the opti
|
|
|
24
24
|
|
|
25
25
|
With a config like:
|
|
26
26
|
|
|
27
|
+
ESLint v8 (eslintrc):
|
|
28
|
+
|
|
27
29
|
```json
|
|
28
30
|
{
|
|
29
31
|
"rules": {
|
|
@@ -39,6 +41,30 @@ With a config like:
|
|
|
39
41
|
}
|
|
40
42
|
```
|
|
41
43
|
|
|
44
|
+
ESLint v9 (flat config):
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import funcParamsArgs from 'eslint-plugin-func-params-args';
|
|
48
|
+
|
|
49
|
+
export default [
|
|
50
|
+
{
|
|
51
|
+
plugins: {
|
|
52
|
+
'func-params-args': funcParamsArgs,
|
|
53
|
+
},
|
|
54
|
+
rules: {
|
|
55
|
+
'func-params-args/func-args': [
|
|
56
|
+
'warn',
|
|
57
|
+
{
|
|
58
|
+
global: 3,
|
|
59
|
+
bar: 2,
|
|
60
|
+
baz: 1,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
```
|
|
67
|
+
|
|
42
68
|
Examples of **incorrect** code for this rule:
|
|
43
69
|
|
|
44
70
|
```js
|
|
@@ -77,6 +103,8 @@ b.baz('arg1');
|
|
|
77
103
|
|
|
78
104
|
With a config like:
|
|
79
105
|
|
|
106
|
+
ESLint v8 (eslintrc):
|
|
107
|
+
|
|
80
108
|
```json
|
|
81
109
|
{
|
|
82
110
|
"rules": {
|
|
@@ -90,6 +118,28 @@ With a config like:
|
|
|
90
118
|
}
|
|
91
119
|
```
|
|
92
120
|
|
|
121
|
+
ESLint v9 (flat config):
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
import funcParamsArgs from 'eslint-plugin-func-params-args';
|
|
125
|
+
|
|
126
|
+
export default [
|
|
127
|
+
{
|
|
128
|
+
plugins: {
|
|
129
|
+
'func-params-args': funcParamsArgs,
|
|
130
|
+
},
|
|
131
|
+
rules: {
|
|
132
|
+
'func-params-args/func-args': [
|
|
133
|
+
'warn',
|
|
134
|
+
{
|
|
135
|
+
foo: 2,
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
```
|
|
142
|
+
|
|
93
143
|
Examples of **incorrect** code for this rule:
|
|
94
144
|
|
|
95
145
|
```js
|
|
@@ -37,6 +37,8 @@ If you want to disable this rule (removing all restrictions) for any of the opti
|
|
|
37
37
|
|
|
38
38
|
With a config like:
|
|
39
39
|
|
|
40
|
+
ESLint v8 (eslintrc):
|
|
41
|
+
|
|
40
42
|
```json
|
|
41
43
|
{
|
|
42
44
|
"rules": {
|
|
@@ -51,6 +53,29 @@ With a config like:
|
|
|
51
53
|
}
|
|
52
54
|
```
|
|
53
55
|
|
|
56
|
+
ESLint v9 (flat config):
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
import funcParamsArgs from 'eslint-plugin-func-params-args';
|
|
60
|
+
|
|
61
|
+
export default [
|
|
62
|
+
{
|
|
63
|
+
plugins: {
|
|
64
|
+
'func-params-args': funcParamsArgs,
|
|
65
|
+
},
|
|
66
|
+
rules: {
|
|
67
|
+
'func-params-args/func-params': [
|
|
68
|
+
'warn',
|
|
69
|
+
{
|
|
70
|
+
global: 3,
|
|
71
|
+
arrowFuncExpression: 4,
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
```
|
|
78
|
+
|
|
54
79
|
Examples of **incorrect** code for this rule:
|
|
55
80
|
|
|
56
81
|
```ts
|
|
@@ -140,6 +165,8 @@ type onBarFn = (param1: number, param2: number, param3: number) => void;
|
|
|
140
165
|
|
|
141
166
|
With a config like:
|
|
142
167
|
|
|
168
|
+
ESLint v8 (eslintrc):
|
|
169
|
+
|
|
143
170
|
```json
|
|
144
171
|
{
|
|
145
172
|
"rules": {
|
|
@@ -154,6 +181,29 @@ With a config like:
|
|
|
154
181
|
}
|
|
155
182
|
```
|
|
156
183
|
|
|
184
|
+
ESLint v9 (flat config):
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
import funcParamsArgs from 'eslint-plugin-func-params-args';
|
|
188
|
+
|
|
189
|
+
export default [
|
|
190
|
+
{
|
|
191
|
+
plugins: {
|
|
192
|
+
'func-params-args': funcParamsArgs,
|
|
193
|
+
},
|
|
194
|
+
rules: {
|
|
195
|
+
'func-params-args/func-params': [
|
|
196
|
+
'warn',
|
|
197
|
+
{
|
|
198
|
+
funcDefinition: 1,
|
|
199
|
+
funcExpression: 2,
|
|
200
|
+
},
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
```
|
|
206
|
+
|
|
157
207
|
Examples of **incorrect** code for this rule:
|
|
158
208
|
|
|
159
209
|
```js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-func-params-args",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Limit the number of function parameters and arguments with ease and flexibility",
|
|
5
5
|
"author": "Abdulrahman (Abdu) Assabri <abdusabri@abdusabri.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"engines": {
|
|
27
|
-
"node": ">=
|
|
27
|
+
"node": ">=18.18.0"
|
|
28
28
|
},
|
|
29
29
|
"main": "dist/index.js",
|
|
30
30
|
"scripts": {
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
"build": "rimraf dist && minify lib -d dist"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"
|
|
42
|
-
"
|
|
41
|
+
"@eslint-community/eslint-utils": "^4.4.0",
|
|
42
|
+
"requireindex": "~1.2.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"eslint": "^
|
|
45
|
+
"eslint": "^8.0.0 || ^9.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@typescript-eslint/parser": "^8.0.0",
|
|
49
49
|
"babel-minify": "^0.5.1",
|
|
50
50
|
"coveralls": "^3.1.0",
|
|
51
|
-
"eslint": "^8.
|
|
51
|
+
"eslint": "^8.57.1",
|
|
52
52
|
"husky": "^9.0.0",
|
|
53
53
|
"lint-staged": "^16.0.0",
|
|
54
54
|
"mocha": "^11.0.0",
|