eslint-plugin-func-params-args 3.0.0 → 4.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 +235 -242
- package/docs/rules/func-args.md +117 -117
- package/docs/rules/func-params.md +180 -180
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,242 +1,235 @@
|
|
|
1
|
-
# eslint-plugin-func-params-args
|
|
2
|
-
|
|
3
|
-
Limit the number of function parameters and arguments with ease and flexibility!
|
|
4
|
-
|
|
5
|
-
This plugin intends to give you control over how many parameters are used in function definitions (declarations), function expressions, and
|
|
6
|
-
|
|
7
|
-
[](https://app.travis-ci.com/github/abdusabri/eslint-plugin-func-params-args) [](https://coveralls.io/github/abdusabri/eslint-plugin-func-params-args) 
|
|
8
|
-
|
|
9
|
-
## Table of contents
|
|
10
|
-
|
|
11
|
-
- [
|
|
12
|
-
|
|
13
|
-
- [
|
|
14
|
-
|
|
15
|
-
- [General usage notes](#general-usage-notes)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- [
|
|
20
|
-
|
|
21
|
-
- [
|
|
22
|
-
|
|
23
|
-
- [
|
|
24
|
-
|
|
25
|
-
- [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
rules
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
]
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
- [
|
|
212
|
-
|
|
213
|
-
- [
|
|
214
|
-
|
|
215
|
-
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
- [Creating an ESLint Plugin](https://medium.com/@bjrnt/creating-an-eslint-plugin-87f1cb42767f)
|
|
237
|
-
|
|
238
|
-
- This course [Creating an Open Source JavaScript Library on Github](https://frontendmasters.com/courses/open-source/), and its associated [GitHub repo](https://github.com/kentcdodds/starwars-names)
|
|
239
|
-
|
|
240
|
-
- This course [Code Transformation and Linting with ASTs](https://frontendmasters.com/courses/linting-asts/)
|
|
241
|
-
|
|
242
|
-
- Badges from [shields.io](https://shields.io/)
|
|
1
|
+
# eslint-plugin-func-params-args
|
|
2
|
+
|
|
3
|
+
Limit the number of function parameters and arguments with ease and flexibility!
|
|
4
|
+
|
|
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
|
+
|
|
7
|
+
[](https://app.travis-ci.com/github/abdusabri/eslint-plugin-func-params-args) [](https://coveralls.io/github/abdusabri/eslint-plugin-func-params-args) 
|
|
8
|
+
|
|
9
|
+
## Table of contents
|
|
10
|
+
|
|
11
|
+
- [eslint-plugin-func-params-args](#eslint-plugin-func-params-args)
|
|
12
|
+
- [Table of contents](#table-of-contents)
|
|
13
|
+
- [Why](#why)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [General usage notes](#general-usage-notes)
|
|
16
|
+
- [No defaults](#no-defaults)
|
|
17
|
+
- [Non-JavaScript files](#non-javascript-files)
|
|
18
|
+
- [Available rules](#available-rules)
|
|
19
|
+
- [What is next](#what-is-next)
|
|
20
|
+
- [Contributing](#contributing)
|
|
21
|
+
- [General guidelines](#general-guidelines)
|
|
22
|
+
- [Documentation notes](#documentation-notes)
|
|
23
|
+
- [Development guidelines](#development-guidelines)
|
|
24
|
+
- [Development notes](#development-notes)
|
|
25
|
+
- [Code of conduct](#code-of-conduct)
|
|
26
|
+
- [Inspiration and credits](#inspiration-and-credits)
|
|
27
|
+
|
|
28
|
+
## Why
|
|
29
|
+
|
|
30
|
+
This plugin has two rules, one for parameters (when defining functions or expressions), and one for arguments when calling functions (including built-in or 3rd party functions). Why each?
|
|
31
|
+
|
|
32
|
+
- **Function Parameters:** ESLint has its own `max-params` rule, but it only provides one global setting, and that's not flexible enough. Let's say we need to call `array.reduce`, where sometimes there is a need to use all of the 4 arguments provided to the reducer callback in an arrow function expression (like `array.reduce((acc, val, index, arr) => {}, {})` for example). Using the built-in `max-params`, we would need to set it to 4 and that would be the global limit. This plugin's rule (`func-params`) allows for more flexibility when handling such cases. One approach would be to set the global setting for (`func-params`) to 3, and override this value to allow arrow function expressions to have 4 parameters instead of 3
|
|
33
|
+
|
|
34
|
+
- **Function Arguments:** The role of the first rule ends when defining functions or expressions, but what about calling functions, especially 3rd party or built-in functions? Let's take migrating from Vue v2 to v3 as an example. Vue v3 recommends using a library called `mitt` as an event bus implementation. Vue v2's own implementation allows more than 2 arguments to be used (passed in) when emitting events (`$emit`), however, `mitt`'s implementation only accepts 2 arguments. So, to help with doing such migration, we can use this plugin's rule (`func-args`) to allow only 2 arguments to be used whenever `$emit` is called. Of course this is only an example, and this rule is flexible to cover any user-configured named function calls - that's in addition to a global limit as well
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
If you don't already have [ESLint](http://eslint.org) installed, you'll first need to install it:
|
|
39
|
+
|
|
40
|
+
```shell
|
|
41
|
+
npm install eslint --save-dev
|
|
42
|
+
|
|
43
|
+
# or yarn add eslint --dev
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Next, install `eslint-plugin-func-params-args`:
|
|
47
|
+
|
|
48
|
+
```shell
|
|
49
|
+
npm install eslint-plugin-func-params-args --save-dev
|
|
50
|
+
|
|
51
|
+
# or yarn add eslint-plugin-func-params-args --dev
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## General usage notes
|
|
55
|
+
|
|
56
|
+
Add `func-params-args` to the plugins section of your `.eslintrc.json` configuration file. You can omit the `eslint-plugin-` prefix:
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"plugins": ["func-params-args"]
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Or `.eslintrc.yml`
|
|
65
|
+
|
|
66
|
+
```yml
|
|
67
|
+
plugins:
|
|
68
|
+
- func-params-args
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Then configure the rules you want to use under the rules section.
|
|
72
|
+
|
|
73
|
+
(`json`)
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"rules": {
|
|
78
|
+
"func-params-args/func-args": [
|
|
79
|
+
"warn",
|
|
80
|
+
{
|
|
81
|
+
"global": 3,
|
|
82
|
+
"$emit": 2
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Or (`yml`)
|
|
90
|
+
|
|
91
|
+
```yml
|
|
92
|
+
rules:
|
|
93
|
+
func-params-args/func-args:
|
|
94
|
+
- 'warn'
|
|
95
|
+
- 'global': 3
|
|
96
|
+
'$emit': 2
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
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
|
+
|
|
101
|
+
### No defaults
|
|
102
|
+
|
|
103
|
+
By design, this plugin's rules don't have pre-set defaults. So, you've to configure them as shown in the example above and as explained in details in the docs of each rule ([Available rules](#available-rules)).
|
|
104
|
+
|
|
105
|
+
### Non-JavaScript files
|
|
106
|
+
|
|
107
|
+
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
|
+
|
|
109
|
+
As an example, to use this plugin in TS files, you may configure parsing options in your `.eslintrc` file as follows:
|
|
110
|
+
|
|
111
|
+
If you don't have any existing parsers (or other plugins that are already taking care of handling TS files)
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
"parser": "@typescript-eslint/parser"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Or you may override only the parsing of TS files if you've other parsers or plugins that are doing their own parsing
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
"overrides": [
|
|
121
|
+
{
|
|
122
|
+
"files": "*.ts",
|
|
123
|
+
"parser": "@typescript-eslint/parser"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
In both examples above, you would need to install `@typescript-eslint/parser` from npm.
|
|
129
|
+
|
|
130
|
+
## Available rules
|
|
131
|
+
|
|
132
|
+
- [enforce the number of parameters used in a function definition or expression (func-params)](./docs/rules/func-params.md)
|
|
133
|
+
|
|
134
|
+
- [enforce the number of arguments used in a function call (func-args)](./docs/rules/func-args.md)
|
|
135
|
+
|
|
136
|
+
## What is next
|
|
137
|
+
|
|
138
|
+
In general, all feedback is welcome, and I would love to get more ideas and contributions to make this project better. As of now, here are a few items I can think of:
|
|
139
|
+
|
|
140
|
+
- Instead of only setting a value as an upper limit when configuring a rule, let's say 3 parameters or arguments max, would setting a min limit as well be a useful addition? Maybe for some function calls you want to allow between 1-3 arguments, but not without any arguments and not with more than 3
|
|
141
|
+
|
|
142
|
+
- Add more examples on how to handle non-JS files, like `.vue` files for instance
|
|
143
|
+
|
|
144
|
+
- ~~Currently, in `func-params` rule, when there is an error reported, in addition to the code location (file and line number), an error message like `function has too many parameters (3). Maximum allowed is (2).` is reported. An improvement would be to report the name of the function (or the variable name in the case of a function expression) in the message instead of the generic `function`. For example, a message like `function has too many parameters...` could be `handleSubmit has too many parameters...` instead~~ **Added in v3**
|
|
145
|
+
|
|
146
|
+
- Consider adding options for pattern matching. Maybe as a start, support `startsWith` and `endsWith` options. Could be useful if you use or have Node-style function names that end with a specific pattern like `[whatever]Sync` or `[whatever]Async`
|
|
147
|
+
|
|
148
|
+
- Adopt the [all-contributors](https://github.com/all-contributors/all-contributors) specification for recognizing contributors
|
|
149
|
+
|
|
150
|
+
## Contributing
|
|
151
|
+
|
|
152
|
+
If you want to report a bug, request a feature, or ask questions, please feel free to open a new issue.
|
|
153
|
+
|
|
154
|
+
All contributions are welcome and appreciated. If you want to help out, please follow the guidelines outlined below. The objective is to ensure that your time and effort are will spent, and to avoid a situation where you might spend time on something that someone else is already working on. Contributors time is valuable, and I hope these guidelines ensure that we can make the best out of it 🙏
|
|
155
|
+
|
|
156
|
+
### General guidelines
|
|
157
|
+
|
|
158
|
+
- Working on your first Pull Request? You can learn how from this free series [How to Contribute to an Open Source Project on GitHub](https://egghead.io/courses/how-to-contribute-to-an-open-source-project-on-github) - Thanks to [Kent C. Dodds](https://github.com/kentcdodds)
|
|
159
|
+
|
|
160
|
+
- Please follow [this guide for your commit messages](https://chris.beams.io/posts/git-commit/). Though the recommended length of the subject line is 50, it is fine to go up to 72 if you need to
|
|
161
|
+
|
|
162
|
+
- For documentation improvements or fixing typos, feel free to open a PR without an existing issue. Otherwise, please follow the development guidelines outlined below
|
|
163
|
+
|
|
164
|
+
#### Documentation notes
|
|
165
|
+
|
|
166
|
+
- You may sometimes find open issues related to documentation. Such issues will have `documentation` label
|
|
167
|
+
|
|
168
|
+
- For minor documentation updates or fixing typos, it is usually fine to do so directly on GitHub website. For large documentation updates, it is recommended to clone the repo and ensure that the project dependencies are installed (by running `npm install` or `yarn`). This is because [Prettier](https://prettier.io/) is used to ensure consistent style/formatting in the docs (all `.md` files), and having the dependencies installed will automatically fix style/formatting issues upon committing
|
|
169
|
+
|
|
170
|
+
### Development guidelines
|
|
171
|
+
|
|
172
|
+
- If you are new to ESLint plugin development, the resources in [Inspiration and credits](#inspiration-and-credits) should help you get started
|
|
173
|
+
|
|
174
|
+
- Check open issues to see if an existing one is already addressing what you want to contribute/help with, or if there is one that is interesting for you to work on. If you want to work on (grab) an existing issue, please ensure that it has the label `up for grabs`, and comment on it to signal your interest. I will then assign the issue to you and add the `assigned` label to it (will remove `up for grabs` as well). [Here is a link to open issues that are up for grabs](https://github.com/abdusabri/eslint-plugin-func-params-args/labels/up%20for%20grabs)
|
|
175
|
+
|
|
176
|
+
- If you don't find an existing issue addressing what you want to contribute/help with, create a new issue and include a short description
|
|
177
|
+
|
|
178
|
+
- If the changes you are working on require documentation updates, please update the docs accordingly
|
|
179
|
+
|
|
180
|
+
- When you are ready to open a PR (all pull requests should be opened against master branch):
|
|
181
|
+
|
|
182
|
+
- Add a summary explaining your changes
|
|
183
|
+
|
|
184
|
+
- Add `Fixes #[issue number]` or `Closes #[issue number]` in the PR description
|
|
185
|
+
|
|
186
|
+
- Here is [a nice article](https://medium.engineering/the-code-review-mindset-3280a4af0a89) about code reviews that I found helpful. Knew about it from [Automattic's Calypso contributing guide](https://github.com/Automattic/wp-calypso/blob/master/docs/CONTRIBUTING.md)
|
|
187
|
+
|
|
188
|
+
#### Development notes
|
|
189
|
+
|
|
190
|
+
- Please run `npm install` or `yarn` to ensure that the required dev dependencies are properly installed
|
|
191
|
+
|
|
192
|
+
- The target for test coverage is `100%`. If not met, a PR will fail on CI (Travis Continuous Integration). You can run `npm run test` locally as well
|
|
193
|
+
|
|
194
|
+
- The project uses Prettier for code formatting and style, and there is a pre-commit hook that auto-fixes any code style issues. This is also checked and will fail on CI if there are issues reported by Prettier
|
|
195
|
+
|
|
196
|
+
## Code of conduct
|
|
197
|
+
|
|
198
|
+
This project adopts Contributor Covenant's Code of Conduct. You can read it in full [here](./CODE_OF_CONDUCT.md), which has my email address included.
|
|
199
|
+
|
|
200
|
+
## Inspiration and credits
|
|
201
|
+
|
|
202
|
+
This work wouldn't have been possible without the power of open source and people who share their knowledge and experiences. Following are some sources of inspiration and references that helped me while creating this plugin/project.
|
|
203
|
+
|
|
204
|
+
- [@gitlab/eslint-plugin](https://gitlab.com/gitlab-org/frontend/eslint-plugin), especially [this Merge Request (MR)](https://gitlab.com/gitlab-org/frontend/eslint-plugin/-/merge_requests/19) and [my MR](https://gitlab.com/gitlab-org/frontend/eslint-plugin/-/merge_requests/20) :)
|
|
205
|
+
|
|
206
|
+
- [AST explorer](https://astexplorer.net/)
|
|
207
|
+
|
|
208
|
+
- ESLint's developer guide, especially [Working with Plugins](https://eslint.org/docs/developer-guide/working-with-plugins) and [Working with Rules
|
|
209
|
+
](https://eslint.org/docs/developer-guide/working-with-rules)
|
|
210
|
+
|
|
211
|
+
- ESlint's [max-params rule](https://eslint.org/docs/rules/max-params#enforce-a-maximum-number-of-parameters-in-function-definitions-max-params), and its linked sources on GitHub
|
|
212
|
+
|
|
213
|
+
- [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import)
|
|
214
|
+
|
|
215
|
+
- [You-Dont-Need-Lodash-Underscore](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore)
|
|
216
|
+
|
|
217
|
+
- Articles and Q&A
|
|
218
|
+
|
|
219
|
+
- [Create custom ESLint rules in 2 minutes](https://blog.webiny.com/create-custom-eslint-rules-in-2-minutes-e3d41cb6a9a0)
|
|
220
|
+
|
|
221
|
+
- [Writing custom EsLint rules](https://www.kenneth-truyers.net/2016/05/27/writing-custom-eslint-rules/)
|
|
222
|
+
|
|
223
|
+
- [How To Write Your First ESLint Plugin](https://dev.to/spukas/how-to-write-your-first-eslint-plugin-145)
|
|
224
|
+
|
|
225
|
+
- [I can't make my custom eslint rule to work](https://stackoverflow.com/questions/60750019/i-cant-make-my-custom-eslint-rule-to-work)
|
|
226
|
+
|
|
227
|
+
- [Writing Custom Lint Rules for Your Picky Developers](https://flexport.engineering/writing-custom-lint-rules-for-your-picky-developers-67732afa1803)
|
|
228
|
+
|
|
229
|
+
- [Creating an ESLint Plugin](https://medium.com/@bjrnt/creating-an-eslint-plugin-87f1cb42767f)
|
|
230
|
+
|
|
231
|
+
- This course [Creating an Open Source JavaScript Library on Github](https://frontendmasters.com/courses/open-source/), and its associated [GitHub repo](https://github.com/kentcdodds/starwars-names)
|
|
232
|
+
|
|
233
|
+
- This course [Code Transformation and Linting with ASTs](https://frontendmasters.com/courses/linting-asts/)
|
|
234
|
+
|
|
235
|
+
- Badges from [shields.io](https://shields.io/)
|
package/docs/rules/func-args.md
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
1
|
-
# enforce the number of arguments used in a function call (func-args)
|
|
2
|
-
|
|
3
|
-
This rule allows you to set a max limit for the number of arguments used in function calls. It allows you to set a global limit, and to override this global limit for any number of named functions you want.
|
|
4
|
-
|
|
5
|
-
## Rule Details
|
|
6
|
-
|
|
7
|
-
By design, this plugin's rules don't have pre-set defaults. So, you've to configure this rule as described here in order to use it. Noting that all the options are used as keys in a single config object (no arrays or nested objects).
|
|
8
|
-
|
|
9
|
-
### Options
|
|
10
|
-
|
|
11
|
-
Here are the available options for this rule:
|
|
12
|
-
|
|
13
|
-
- `global`: accepts an integer indicating the max number of arguments used in a function call. This applies to all function calls unless overridden for specifically configured function names
|
|
14
|
-
|
|
15
|
-
- `[functionName]`: `functionName` is a placeholder for a key that represents the name of a function (`foo`, `bar`, `doSomething`, etc.), and accepts an integer indicating the max number of arguments for a call to `functionName`. This overrides the global limit. You can add as many keys for as many function names you would like to override/set a limit to
|
|
16
|
-
|
|
17
|
-
If you have a need to set the value of an option to `0`, it is a valid limit that's supported by this rule.
|
|
18
|
-
|
|
19
|
-
If you want to disable this rule (removing all restrictions) for any of the options, you can set its value to `-1`. For example, adding an option like `"baz": -1` in the config, allows you to call `baz` with any number of arguments (basically from 0 to an unlimited number of argument). This overrides the global limit.
|
|
20
|
-
|
|
21
|
-
**Error message example:** `foo has been called with too many arguments (3). Maximum allowed is (2).`
|
|
22
|
-
|
|
23
|
-
#### Example (A)
|
|
24
|
-
|
|
25
|
-
With a config like:
|
|
26
|
-
|
|
27
|
-
```json
|
|
28
|
-
{
|
|
29
|
-
"rules": {
|
|
30
|
-
"func-params-args/func-args": [
|
|
31
|
-
"warn",
|
|
32
|
-
{
|
|
33
|
-
"global": 3,
|
|
34
|
-
"bar": 2,
|
|
35
|
-
"baz": 1
|
|
36
|
-
}
|
|
37
|
-
]
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Examples of **incorrect** code for this rule:
|
|
43
|
-
|
|
44
|
-
```js
|
|
45
|
-
foo('arg1', 'arg2', arg3, arg4);
|
|
46
|
-
a.foo('arg1', 'arg2', arg3, arg4);
|
|
47
|
-
|
|
48
|
-
bar('arg1', 'arg2', arg3);
|
|
49
|
-
b.bar('arg1', 'arg2', arg3);
|
|
50
|
-
|
|
51
|
-
baz('arg1', arg2);
|
|
52
|
-
b.baz('arg1', arg2);
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
Examples of **correct** code for this rule:
|
|
56
|
-
|
|
57
|
-
```js
|
|
58
|
-
foo('arg1', 'arg2', arg3);
|
|
59
|
-
foo('arg1', 'arg2');
|
|
60
|
-
foo('arg1');
|
|
61
|
-
a.foo('arg1', 'arg2', arg3);
|
|
62
|
-
a.foo('arg1', 'arg2');
|
|
63
|
-
a.foo('arg1');
|
|
64
|
-
|
|
65
|
-
bar('arg1', arg2);
|
|
66
|
-
bar('arg1');
|
|
67
|
-
b.bar('arg1', arg2);
|
|
68
|
-
b.bar('arg1');
|
|
69
|
-
|
|
70
|
-
baz();
|
|
71
|
-
a.baz();
|
|
72
|
-
baz('arg1');
|
|
73
|
-
b.baz('arg1');
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
#### Example (B)
|
|
77
|
-
|
|
78
|
-
With a config like:
|
|
79
|
-
|
|
80
|
-
```json
|
|
81
|
-
{
|
|
82
|
-
"rules": {
|
|
83
|
-
"func-params-args/func-args": [
|
|
84
|
-
"warn",
|
|
85
|
-
{
|
|
86
|
-
"foo": 2
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
Examples of **incorrect** code for this rule:
|
|
94
|
-
|
|
95
|
-
```js
|
|
96
|
-
foo('arg1', 'arg2', arg3);
|
|
97
|
-
a.foo('arg1', 'arg2', arg3);
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
Examples of **correct** code for this rule:
|
|
101
|
-
|
|
102
|
-
```js
|
|
103
|
-
foo('arg1', 'arg2');
|
|
104
|
-
foo('arg1');
|
|
105
|
-
foo();
|
|
106
|
-
a.b.foo('arg1', 'arg2');
|
|
107
|
-
a.b.c.foo('arg1');
|
|
108
|
-
a.b.foo();
|
|
109
|
-
|
|
110
|
-
bar('arg1', 'arg2', arg3, arg4);
|
|
111
|
-
a.bar('arg1', 'arg2', arg3, arg4);
|
|
112
|
-
|
|
113
|
-
// whatever else function calls
|
|
114
|
-
|
|
115
|
-
// any other function call than foo would have no restrictions
|
|
116
|
-
// since the 'global' option is not configured
|
|
117
|
-
```
|
|
1
|
+
# enforce the number of arguments used in a function call (func-args)
|
|
2
|
+
|
|
3
|
+
This rule allows you to set a max limit for the number of arguments used in function calls. It allows you to set a global limit, and to override this global limit for any number of named functions you want.
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
By design, this plugin's rules don't have pre-set defaults. So, you've to configure this rule as described here in order to use it. Noting that all the options are used as keys in a single config object (no arrays or nested objects).
|
|
8
|
+
|
|
9
|
+
### Options
|
|
10
|
+
|
|
11
|
+
Here are the available options for this rule:
|
|
12
|
+
|
|
13
|
+
- `global`: accepts an integer indicating the max number of arguments used in a function call. This applies to all function calls unless overridden for specifically configured function names
|
|
14
|
+
|
|
15
|
+
- `[functionName]`: `functionName` is a placeholder for a key that represents the name of a function (`foo`, `bar`, `doSomething`, etc.), and accepts an integer indicating the max number of arguments for a call to `functionName`. This overrides the global limit. You can add as many keys for as many function names you would like to override/set a limit to
|
|
16
|
+
|
|
17
|
+
If you have a need to set the value of an option to `0`, it is a valid limit that's supported by this rule.
|
|
18
|
+
|
|
19
|
+
If you want to disable this rule (removing all restrictions) for any of the options, you can set its value to `-1`. For example, adding an option like `"baz": -1` in the config, allows you to call `baz` with any number of arguments (basically from 0 to an unlimited number of argument). This overrides the global limit.
|
|
20
|
+
|
|
21
|
+
**Error message example:** `foo has been called with too many arguments (3). Maximum allowed is (2).`
|
|
22
|
+
|
|
23
|
+
#### Example (A)
|
|
24
|
+
|
|
25
|
+
With a config like:
|
|
26
|
+
|
|
27
|
+
```json
|
|
28
|
+
{
|
|
29
|
+
"rules": {
|
|
30
|
+
"func-params-args/func-args": [
|
|
31
|
+
"warn",
|
|
32
|
+
{
|
|
33
|
+
"global": 3,
|
|
34
|
+
"bar": 2,
|
|
35
|
+
"baz": 1
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Examples of **incorrect** code for this rule:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
foo('arg1', 'arg2', arg3, arg4);
|
|
46
|
+
a.foo('arg1', 'arg2', arg3, arg4);
|
|
47
|
+
|
|
48
|
+
bar('arg1', 'arg2', arg3);
|
|
49
|
+
b.bar('arg1', 'arg2', arg3);
|
|
50
|
+
|
|
51
|
+
baz('arg1', arg2);
|
|
52
|
+
b.baz('arg1', arg2);
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Examples of **correct** code for this rule:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
foo('arg1', 'arg2', arg3);
|
|
59
|
+
foo('arg1', 'arg2');
|
|
60
|
+
foo('arg1');
|
|
61
|
+
a.foo('arg1', 'arg2', arg3);
|
|
62
|
+
a.foo('arg1', 'arg2');
|
|
63
|
+
a.foo('arg1');
|
|
64
|
+
|
|
65
|
+
bar('arg1', arg2);
|
|
66
|
+
bar('arg1');
|
|
67
|
+
b.bar('arg1', arg2);
|
|
68
|
+
b.bar('arg1');
|
|
69
|
+
|
|
70
|
+
baz();
|
|
71
|
+
a.baz();
|
|
72
|
+
baz('arg1');
|
|
73
|
+
b.baz('arg1');
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### Example (B)
|
|
77
|
+
|
|
78
|
+
With a config like:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"rules": {
|
|
83
|
+
"func-params-args/func-args": [
|
|
84
|
+
"warn",
|
|
85
|
+
{
|
|
86
|
+
"foo": 2
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Examples of **incorrect** code for this rule:
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
foo('arg1', 'arg2', arg3);
|
|
97
|
+
a.foo('arg1', 'arg2', arg3);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Examples of **correct** code for this rule:
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
foo('arg1', 'arg2');
|
|
104
|
+
foo('arg1');
|
|
105
|
+
foo();
|
|
106
|
+
a.b.foo('arg1', 'arg2');
|
|
107
|
+
a.b.c.foo('arg1');
|
|
108
|
+
a.b.foo();
|
|
109
|
+
|
|
110
|
+
bar('arg1', 'arg2', arg3, arg4);
|
|
111
|
+
a.bar('arg1', 'arg2', arg3, arg4);
|
|
112
|
+
|
|
113
|
+
// whatever else function calls
|
|
114
|
+
|
|
115
|
+
// any other function call than foo would have no restrictions
|
|
116
|
+
// since the 'global' option is not configured
|
|
117
|
+
```
|
|
@@ -1,180 +1,180 @@
|
|
|
1
|
-
# enforce the number of parameters used in a function definition or expression (func-params)
|
|
2
|
-
|
|
3
|
-
This rule allows you to set a max limit for the number of parameters used in function definitions, function expressions, and arrow function expressions. It allows you to set a global limit, and to override this global limit for each of the types (definitions and expressions).
|
|
4
|
-
|
|
5
|
-
## Rule Details
|
|
6
|
-
|
|
7
|
-
By design, this plugin's rules don't have pre-set defaults. So, you've to configure this rule as described here in order to use it. Noting that all the options are used as keys in a single config object (no arrays or nested objects).
|
|
8
|
-
|
|
9
|
-
### Options
|
|
10
|
-
|
|
11
|
-
Here are the available options for this rule:
|
|
12
|
-
|
|
13
|
-
- `global`: accepts an integer indicating the max number of parameters used in a function definition or expression. This applies to all types unless overridden for a specific type
|
|
14
|
-
|
|
15
|
-
- `funcDefinition`: accepts an integer indicating the max number of parameters used in a function definition. This overrides the global limit
|
|
16
|
-
|
|
17
|
-
- `funcExpression`: accepts an integer indicating the max number of parameters used in a function expression. This overrides the global limit
|
|
18
|
-
|
|
19
|
-
- `arrowFuncExpression`: accepts an integer indicating the max number of parameters used in an arrow function expression. This overrides the global limit
|
|
20
|
-
|
|
21
|
-
- `funcTypeAnnotation`: accepts an integer indicating the max number of parameters used in a TypeScript function type annotation. This overrides the global limit
|
|
22
|
-
|
|
23
|
-
If you have a need to set the value of an option to `0`, it is a valid limit that's supported by this rule.
|
|
24
|
-
|
|
25
|
-
If you want to disable this rule (removing all restrictions) for any of the options, you can set its value to `-1`. For example, setting an option like `"arrowFuncExpression": -1` in the config, allows you to use arrow functions with any number of parameters (basically from 0 to an unlimited number of parameters). This overrides the global limit.
|
|
26
|
-
|
|
27
|
-
**Error message examples:**
|
|
28
|
-
|
|
29
|
-
- `function 'foo' has too many parameters (3). Maximum allowed is (1).`
|
|
30
|
-
- `arrow function 'b' has too many parameters (3). Maximum allowed is (1).`
|
|
31
|
-
- `arrow function has too many parameters (3). Maximum allowed is (1).`
|
|
32
|
-
- `function 'onBar' has too many parameters (3). Maximum allowed is (1).` [TS key in interface or object type]
|
|
33
|
-
- `function 'onBarFn' has too many parameters (3). Maximum allowed is (1).` [TS function type alias]
|
|
34
|
-
- `function 'myFunction' has too many parameters (3). Maximum allowed is (1).` [TS method signature]
|
|
35
|
-
|
|
36
|
-
#### Example (A)
|
|
37
|
-
|
|
38
|
-
With a config like:
|
|
39
|
-
|
|
40
|
-
```json
|
|
41
|
-
{
|
|
42
|
-
"rules": {
|
|
43
|
-
"func-params-args/func-params": [
|
|
44
|
-
"warn",
|
|
45
|
-
{
|
|
46
|
-
"global": 3,
|
|
47
|
-
"arrowFuncExpression": 4
|
|
48
|
-
}
|
|
49
|
-
]
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
Examples of **incorrect** code for this rule:
|
|
55
|
-
|
|
56
|
-
```ts
|
|
57
|
-
function foo(param1, param2, param3, param4) {}
|
|
58
|
-
|
|
59
|
-
a = function (param1, param2, param3, param4) {};
|
|
60
|
-
|
|
61
|
-
b = (param1, param2, param3, param4, param5) => {};
|
|
62
|
-
|
|
63
|
-
c = async function (param1, param2, param3, param4) {};
|
|
64
|
-
|
|
65
|
-
c.reduce((param1, param2, param3, param4, param5) => {});
|
|
66
|
-
|
|
67
|
-
interface IFoo {
|
|
68
|
-
onBar: (
|
|
69
|
-
param1: string,
|
|
70
|
-
param2: string,
|
|
71
|
-
param3: string,
|
|
72
|
-
param4: string
|
|
73
|
-
) => void;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
type FooType = {
|
|
77
|
-
onBar: (
|
|
78
|
-
param1: number,
|
|
79
|
-
param2: number,
|
|
80
|
-
param3: number,
|
|
81
|
-
param4: number
|
|
82
|
-
) => void;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
type onBarFn = (
|
|
86
|
-
param1: number,
|
|
87
|
-
param2: number,
|
|
88
|
-
param3: number,
|
|
89
|
-
param4: number
|
|
90
|
-
) => void;
|
|
91
|
-
|
|
92
|
-
interface MyInterface {
|
|
93
|
-
myFunction(
|
|
94
|
-
param1: string,
|
|
95
|
-
param2: string,
|
|
96
|
-
param3: string,
|
|
97
|
-
param4: string
|
|
98
|
-
): void;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const func2: (
|
|
102
|
-
param1: string,
|
|
103
|
-
param2: string,
|
|
104
|
-
param3: string,
|
|
105
|
-
param3: string
|
|
106
|
-
) => void = (arg1, arg2, arg3, arg4) => {};
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
Examples of **correct** code for this rule:
|
|
110
|
-
|
|
111
|
-
```ts
|
|
112
|
-
function foo(param1, param2, param3) {}
|
|
113
|
-
|
|
114
|
-
a = function (param1, param2, param3) {};
|
|
115
|
-
|
|
116
|
-
b = (param1, param2, param3, param4) => {};
|
|
117
|
-
|
|
118
|
-
c.reduce((param1, param2, param3, param4) => {});
|
|
119
|
-
|
|
120
|
-
function foo(param1) {}
|
|
121
|
-
|
|
122
|
-
a = function (param1, param2) {};
|
|
123
|
-
|
|
124
|
-
b = () => {};
|
|
125
|
-
|
|
126
|
-
c.reduce((param1, param2, param3) => {});
|
|
127
|
-
|
|
128
|
-
interface IFoo {
|
|
129
|
-
onBar: (param1: string, param2: string, param3: string) => void;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
type FooType = {
|
|
133
|
-
onBar: (param1: number, param2: number, param3: number) => void;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
type onBarFn = (param1: number, param2: number, param3: number) => void;
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
#### Example (B)
|
|
140
|
-
|
|
141
|
-
With a config like:
|
|
142
|
-
|
|
143
|
-
```json
|
|
144
|
-
{
|
|
145
|
-
"rules": {
|
|
146
|
-
"func-params-args/func-params": [
|
|
147
|
-
"warn",
|
|
148
|
-
{
|
|
149
|
-
"funcDefinition": 1,
|
|
150
|
-
"funcExpression": 2
|
|
151
|
-
}
|
|
152
|
-
]
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
Examples of **incorrect** code for this rule:
|
|
158
|
-
|
|
159
|
-
```js
|
|
160
|
-
function foo(param1, param2) {}
|
|
161
|
-
|
|
162
|
-
a = function (param1, param2, param3) {};
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
Examples of **correct** code for this rule:
|
|
166
|
-
|
|
167
|
-
```js
|
|
168
|
-
function foo(param1) {}
|
|
169
|
-
|
|
170
|
-
a = function (param1, param2) {};
|
|
171
|
-
|
|
172
|
-
// No restrictions below on arrow function expressions
|
|
173
|
-
// since the 'global' option is not configured
|
|
174
|
-
|
|
175
|
-
b = (param1, param2, param3, param4, param5) => {};
|
|
176
|
-
|
|
177
|
-
c = () => {};
|
|
178
|
-
|
|
179
|
-
c.reduce((param1, param2, param3, param4) => {});
|
|
180
|
-
```
|
|
1
|
+
# enforce the number of parameters used in a function definition or expression (func-params)
|
|
2
|
+
|
|
3
|
+
This rule allows you to set a max limit for the number of parameters used in function definitions, function expressions, and arrow function expressions. It allows you to set a global limit, and to override this global limit for each of the types (definitions and expressions).
|
|
4
|
+
|
|
5
|
+
## Rule Details
|
|
6
|
+
|
|
7
|
+
By design, this plugin's rules don't have pre-set defaults. So, you've to configure this rule as described here in order to use it. Noting that all the options are used as keys in a single config object (no arrays or nested objects).
|
|
8
|
+
|
|
9
|
+
### Options
|
|
10
|
+
|
|
11
|
+
Here are the available options for this rule:
|
|
12
|
+
|
|
13
|
+
- `global`: accepts an integer indicating the max number of parameters used in a function definition or expression. This applies to all types unless overridden for a specific type
|
|
14
|
+
|
|
15
|
+
- `funcDefinition`: accepts an integer indicating the max number of parameters used in a function definition. This overrides the global limit
|
|
16
|
+
|
|
17
|
+
- `funcExpression`: accepts an integer indicating the max number of parameters used in a function expression. This overrides the global limit
|
|
18
|
+
|
|
19
|
+
- `arrowFuncExpression`: accepts an integer indicating the max number of parameters used in an arrow function expression. This overrides the global limit
|
|
20
|
+
|
|
21
|
+
- `funcTypeAnnotation`: accepts an integer indicating the max number of parameters used in a TypeScript function type annotation. This overrides the global limit
|
|
22
|
+
|
|
23
|
+
If you have a need to set the value of an option to `0`, it is a valid limit that's supported by this rule.
|
|
24
|
+
|
|
25
|
+
If you want to disable this rule (removing all restrictions) for any of the options, you can set its value to `-1`. For example, setting an option like `"arrowFuncExpression": -1` in the config, allows you to use arrow functions with any number of parameters (basically from 0 to an unlimited number of parameters). This overrides the global limit.
|
|
26
|
+
|
|
27
|
+
**Error message examples:**
|
|
28
|
+
|
|
29
|
+
- `function 'foo' has too many parameters (3). Maximum allowed is (1).`
|
|
30
|
+
- `arrow function 'b' has too many parameters (3). Maximum allowed is (1).`
|
|
31
|
+
- `arrow function has too many parameters (3). Maximum allowed is (1).`
|
|
32
|
+
- `function 'onBar' has too many parameters (3). Maximum allowed is (1).` [TS key in interface or object type]
|
|
33
|
+
- `function 'onBarFn' has too many parameters (3). Maximum allowed is (1).` [TS function type alias]
|
|
34
|
+
- `function 'myFunction' has too many parameters (3). Maximum allowed is (1).` [TS method signature]
|
|
35
|
+
|
|
36
|
+
#### Example (A)
|
|
37
|
+
|
|
38
|
+
With a config like:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"rules": {
|
|
43
|
+
"func-params-args/func-params": [
|
|
44
|
+
"warn",
|
|
45
|
+
{
|
|
46
|
+
"global": 3,
|
|
47
|
+
"arrowFuncExpression": 4
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Examples of **incorrect** code for this rule:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
function foo(param1, param2, param3, param4) {}
|
|
58
|
+
|
|
59
|
+
a = function (param1, param2, param3, param4) {};
|
|
60
|
+
|
|
61
|
+
b = (param1, param2, param3, param4, param5) => {};
|
|
62
|
+
|
|
63
|
+
c = async function (param1, param2, param3, param4) {};
|
|
64
|
+
|
|
65
|
+
c.reduce((param1, param2, param3, param4, param5) => {});
|
|
66
|
+
|
|
67
|
+
interface IFoo {
|
|
68
|
+
onBar: (
|
|
69
|
+
param1: string,
|
|
70
|
+
param2: string,
|
|
71
|
+
param3: string,
|
|
72
|
+
param4: string,
|
|
73
|
+
) => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type FooType = {
|
|
77
|
+
onBar: (
|
|
78
|
+
param1: number,
|
|
79
|
+
param2: number,
|
|
80
|
+
param3: number,
|
|
81
|
+
param4: number,
|
|
82
|
+
) => void;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
type onBarFn = (
|
|
86
|
+
param1: number,
|
|
87
|
+
param2: number,
|
|
88
|
+
param3: number,
|
|
89
|
+
param4: number,
|
|
90
|
+
) => void;
|
|
91
|
+
|
|
92
|
+
interface MyInterface {
|
|
93
|
+
myFunction(
|
|
94
|
+
param1: string,
|
|
95
|
+
param2: string,
|
|
96
|
+
param3: string,
|
|
97
|
+
param4: string,
|
|
98
|
+
): void;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const func2: (
|
|
102
|
+
param1: string,
|
|
103
|
+
param2: string,
|
|
104
|
+
param3: string,
|
|
105
|
+
param3: string,
|
|
106
|
+
) => void = (arg1, arg2, arg3, arg4) => {};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Examples of **correct** code for this rule:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
function foo(param1, param2, param3) {}
|
|
113
|
+
|
|
114
|
+
a = function (param1, param2, param3) {};
|
|
115
|
+
|
|
116
|
+
b = (param1, param2, param3, param4) => {};
|
|
117
|
+
|
|
118
|
+
c.reduce((param1, param2, param3, param4) => {});
|
|
119
|
+
|
|
120
|
+
function foo(param1) {}
|
|
121
|
+
|
|
122
|
+
a = function (param1, param2) {};
|
|
123
|
+
|
|
124
|
+
b = () => {};
|
|
125
|
+
|
|
126
|
+
c.reduce((param1, param2, param3) => {});
|
|
127
|
+
|
|
128
|
+
interface IFoo {
|
|
129
|
+
onBar: (param1: string, param2: string, param3: string) => void;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
type FooType = {
|
|
133
|
+
onBar: (param1: number, param2: number, param3: number) => void;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
type onBarFn = (param1: number, param2: number, param3: number) => void;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### Example (B)
|
|
140
|
+
|
|
141
|
+
With a config like:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"rules": {
|
|
146
|
+
"func-params-args/func-params": [
|
|
147
|
+
"warn",
|
|
148
|
+
{
|
|
149
|
+
"funcDefinition": 1,
|
|
150
|
+
"funcExpression": 2
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Examples of **incorrect** code for this rule:
|
|
158
|
+
|
|
159
|
+
```js
|
|
160
|
+
function foo(param1, param2) {}
|
|
161
|
+
|
|
162
|
+
a = function (param1, param2, param3) {};
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Examples of **correct** code for this rule:
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
function foo(param1) {}
|
|
169
|
+
|
|
170
|
+
a = function (param1, param2) {};
|
|
171
|
+
|
|
172
|
+
// No restrictions below on arrow function expressions
|
|
173
|
+
// since the 'global' option is not configured
|
|
174
|
+
|
|
175
|
+
b = (param1, param2, param3, param4, param5) => {};
|
|
176
|
+
|
|
177
|
+
c = () => {};
|
|
178
|
+
|
|
179
|
+
c.reduce((param1, param2, param3, param4) => {});
|
|
180
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-func-params-args",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.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": ">=16"
|
|
28
28
|
},
|
|
29
29
|
"main": "dist/index.js",
|
|
30
30
|
"scripts": {
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
"eslint": "^6 || ^7.1.0 || ^8.0.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@typescript-eslint/parser": "^
|
|
48
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
49
49
|
"babel-minify": "^0.5.1",
|
|
50
50
|
"coveralls": "^3.1.0",
|
|
51
51
|
"eslint": "^8.2.0",
|
|
52
52
|
"husky": "^8.0.2",
|
|
53
|
-
"lint-staged": "^
|
|
53
|
+
"lint-staged": "^15.0.2",
|
|
54
54
|
"mocha": "^10.0.0",
|
|
55
55
|
"nyc": "^15.1.0",
|
|
56
|
-
"prettier": "^
|
|
57
|
-
"rimraf": "^
|
|
56
|
+
"prettier": "^3.1.0",
|
|
57
|
+
"rimraf": "^5.0.5",
|
|
58
58
|
"typescript": "^5.0.2"
|
|
59
59
|
},
|
|
60
60
|
"files": [
|