eslint-plugin-func-params-args 3.0.1 → 4.0.1

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2020 Abdulrahman (Abdu) Assabri
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Abdulrahman (Abdu) Assabri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,235 +1,232 @@
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
- [![Travis (.com) branch](https://img.shields.io/travis/com/abdusabri/eslint-plugin-func-params-args/master)](https://app.travis-ci.com/github/abdusabri/eslint-plugin-func-params-args) [![Coveralls github branch](https://img.shields.io/coveralls/github/abdusabri/eslint-plugin-func-params-args/master?logo=coveralls&style=flat-square)](https://coveralls.io/github/abdusabri/eslint-plugin-func-params-args) ![Depfu](https://img.shields.io/depfu/abdusabri/eslint-plugin-func-params-args?style=flat-square)
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/)
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
+ [![Travis (.com) branch](https://img.shields.io/travis/com/abdusabri/eslint-plugin-func-params-args/master)](https://app.travis-ci.com/github/abdusabri/eslint-plugin-func-params-args) [![Coveralls github branch](https://img.shields.io/coveralls/github/abdusabri/eslint-plugin-func-params-args/master?logo=coveralls&style=flat-square)](https://coveralls.io/github/abdusabri/eslint-plugin-func-params-args) [![Renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)
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
+ - Add a summary explaining your changes
182
+
183
+ - Add `Fixes #[issue number]` or `Closes #[issue number]` in the PR description
184
+
185
+ - 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)
186
+
187
+ #### Development notes
188
+
189
+ - Please run `npm install` or `yarn` to ensure that the required dev dependencies are properly installed
190
+
191
+ - 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
192
+
193
+ - 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
194
+
195
+ ## Code of conduct
196
+
197
+ This project adopts Contributor Covenant's Code of Conduct. You can read it in full in [CODE_OF_CONDUCT](./CODE_OF_CONDUCT.md), which has my email address included.
198
+
199
+ ## Inspiration and credits
200
+
201
+ 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.
202
+
203
+ - [@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) :)
204
+
205
+ - [AST explorer](https://astexplorer.net/)
206
+
207
+ - ESLint's developer guide, especially [Working with Plugins](https://eslint.org/docs/developer-guide/working-with-plugins) and [Working with Rules](https://eslint.org/docs/developer-guide/working-with-rules)
208
+
209
+ - 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
210
+
211
+ - [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import)
212
+
213
+ - [You-Dont-Need-Lodash-Underscore](https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore)
214
+
215
+ - Articles and Q&A
216
+ - [Create custom ESLint rules in 2 minutes](https://blog.webiny.com/create-custom-eslint-rules-in-2-minutes-e3d41cb6a9a0)
217
+
218
+ - [Writing custom EsLint rules](https://www.kenneth-truyers.net/2016/05/27/writing-custom-eslint-rules/)
219
+
220
+ - [How To Write Your First ESLint Plugin](https://dev.to/spukas/how-to-write-your-first-eslint-plugin-145)
221
+
222
+ - [I can't make my custom eslint rule to work](https://stackoverflow.com/questions/60750019/i-cant-make-my-custom-eslint-rule-to-work)
223
+
224
+ - [Writing Custom Lint Rules for Your Picky Developers](https://flexport.engineering/writing-custom-lint-rules-for-your-picky-developers-67732afa1803)
225
+
226
+ - [Creating an ESLint Plugin](https://medium.com/@bjrnt/creating-an-eslint-plugin-87f1cb42767f)
227
+
228
+ - 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)
229
+
230
+ - This course [Code Transformation and Linting with ASTs](https://frontendmasters.com/courses/linting-asts/)
231
+
232
+ - Badges from [shields.io](https://shields.io/)
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var requireIndex=require("requireindex");module.exports.rules=requireIndex(__dirname+"/rules");
1
+ "use strict";var requireIndex=require("requireindex");module.exports.rules=requireIndex(__dirname+"/rules");
@@ -1 +1 @@
1
- 'use strict';const{BASE_URL,isOptionConfigured}=require("../utils"),getFuncName=a=>{switch(a.callee.type){case"MemberExpression":return a.callee.property.name;case"Identifier":return a.callee.name;}};module.exports={meta:{type:"problem",docs:{description:"enforce the number of arguments used in a function call",url:BASE_URL+"func-args.md"},schema:[{type:"object",properties:{global:{type:"integer",minimum:-1}},additionalProperties:{type:"integer",minimum:-1}}],messages:{exceed:"{{name}} has been called with too many arguments ({{count}}). Maximum allowed is ({{max}})."}},create(a){function b(b,c){a.report({node:b,messageId:"exceed",data:c})}function c(a,c,d){0<=d&&a.arguments.length>d&&b(a,{name:c,count:a.arguments.length,max:d})}const d=a.options[0]||{};return{CallExpression(a){const b=getFuncName(a);let e=-1;isOptionConfigured(d,b)?e=d[b]:isOptionConfigured(d,"global")&&(e=d.global),c(a,b,e)}}}};
1
+ "use strict";const{BASE_URL,isOptionConfigured}=require("../utils"),getFuncName=a=>{switch(a.callee.type){case"MemberExpression":return a.callee.property.name;case"Identifier":return a.callee.name}};module.exports={meta:{type:"problem",docs:{description:"enforce the number of arguments used in a function call",url:BASE_URL+"func-args.md"},schema:[{type:"object",properties:{global:{type:"integer",minimum:-1}},additionalProperties:{type:"integer",minimum:-1}}],messages:{exceed:"{{name}} has been called with too many arguments ({{count}}). Maximum allowed is ({{max}})."}},create(a){function b(b,c){a.report({node:b,messageId:"exceed",data:c})}function c(a,c,d){0<=d&&a.arguments.length>d&&b(a,{name:c,count:a.arguments.length,max:d})}const d=a.options[0]||{};return{CallExpression(a){const b=getFuncName(a);let e=-1;isOptionConfigured(d,b)?e=d[b]:isOptionConfigured(d,"global")&&(e=d.global),c(a,b,e)}}}};
@@ -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-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/dist/utils.js CHANGED
@@ -1 +1 @@
1
- 'use strict';function isOptionConfigured(a,b=""){return a&&b in a}module.exports={isOptionConfigured,BASE_URL:"https://github.com/abdusabri/eslint-plugin-func-params-args/blob/master/docs/rules/"};
1
+ "use strict";function isOptionConfigured(a,b=""){return a&&b in a}module.exports={isOptionConfigured,BASE_URL:"https://github.com/abdusabri/eslint-plugin-func-params-args/blob/master/docs/rules/"};
@@ -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,74 +1,74 @@
1
- {
2
- "name": "eslint-plugin-func-params-args",
3
- "version": "3.0.1",
4
- "description": "Limit the number of function parameters and arguments with ease and flexibility",
5
- "author": "Abdulrahman (Abdu) Assabri <abdusabri@abdusabri.com>",
6
- "keywords": [
7
- "eslint",
8
- "eslintplugin",
9
- "eslint-plugin",
10
- "function",
11
- "func",
12
- "args",
13
- "params",
14
- "parameters",
15
- "arguments"
16
- ],
17
- "repository": {
18
- "type": "git",
19
- "url": "https://github.com/abdusabri/eslint-plugin-func-params-args.git"
20
- },
21
- "homepage": "https://github.com/abdusabri/eslint-plugin-func-params-args",
22
- "bugs": {
23
- "url": "https://github.com/abdusabri/eslint-plugin-func-params-args/issues"
24
- },
25
- "license": "MIT",
26
- "engines": {
27
- "node": ">=14"
28
- },
29
- "main": "dist/index.js",
30
- "scripts": {
31
- "prettier:fix": "prettier --write **/*.{js,json,md}",
32
- "prettier:check": "prettier --check **/*.{js,json,md}",
33
- "test:unit": "mocha tests --recursive",
34
- "test": "nyc mocha tests --recursive",
35
- "check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
36
- "cover": "nyc report --reporter=lcov",
37
- "coveralls": "cat ./coverage/lcov.info | coveralls",
38
- "build": "rimraf dist && minify lib -d dist"
39
- },
40
- "dependencies": {
41
- "requireindex": "~1.2.0",
42
- "eslint-utils": "^3.0.0"
43
- },
44
- "peerDependencies": {
45
- "eslint": "^6 || ^7.1.0 || ^8.0.0"
46
- },
47
- "devDependencies": {
48
- "@typescript-eslint/parser": "^5.4.0",
49
- "babel-minify": "^0.5.1",
50
- "coveralls": "^3.1.0",
51
- "eslint": "^8.2.0",
52
- "husky": "^8.0.2",
53
- "lint-staged": "^13.0.4",
54
- "mocha": "^10.0.0",
55
- "nyc": "^15.1.0",
56
- "prettier": "^2.2.1",
57
- "rimraf": "^4.4.0",
58
- "typescript": "^5.0.2"
59
- },
60
- "files": [
61
- "*.md",
62
- "LICENSE",
63
- "docs",
64
- "dist"
65
- ],
66
- "husky": {
67
- "hooks": {
68
- "pre-commit": "lint-staged"
69
- }
70
- },
71
- "lint-staged": {
72
- "*.{js,json,md}": "prettier --write"
73
- }
74
- }
1
+ {
2
+ "name": "eslint-plugin-func-params-args",
3
+ "version": "4.0.1",
4
+ "description": "Limit the number of function parameters and arguments with ease and flexibility",
5
+ "author": "Abdulrahman (Abdu) Assabri <abdusabri@abdusabri.com>",
6
+ "keywords": [
7
+ "eslint",
8
+ "eslintplugin",
9
+ "eslint-plugin",
10
+ "function",
11
+ "func",
12
+ "args",
13
+ "params",
14
+ "parameters",
15
+ "arguments"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/abdusabri/eslint-plugin-func-params-args.git"
20
+ },
21
+ "homepage": "https://github.com/abdusabri/eslint-plugin-func-params-args",
22
+ "bugs": {
23
+ "url": "https://github.com/abdusabri/eslint-plugin-func-params-args/issues"
24
+ },
25
+ "license": "MIT",
26
+ "engines": {
27
+ "node": ">=16"
28
+ },
29
+ "main": "dist/index.js",
30
+ "scripts": {
31
+ "prettier:fix": "prettier --write **/*.{js,json,md}",
32
+ "prettier:check": "prettier --check **/*.{js,json,md}",
33
+ "test:unit": "mocha tests --recursive",
34
+ "test": "nyc mocha tests --recursive",
35
+ "check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
36
+ "cover": "nyc report --reporter=lcov",
37
+ "coveralls": "cat ./coverage/lcov.info | coveralls",
38
+ "build": "rimraf dist && minify lib -d dist"
39
+ },
40
+ "dependencies": {
41
+ "requireindex": "~1.2.0",
42
+ "eslint-utils": "^3.0.0"
43
+ },
44
+ "peerDependencies": {
45
+ "eslint": "^6 || ^7.1.0 || ^8.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@typescript-eslint/parser": "^6.12.0",
49
+ "babel-minify": "^0.5.1",
50
+ "coveralls": "^3.1.0",
51
+ "eslint": "^8.2.0",
52
+ "husky": "^8.0.2",
53
+ "lint-staged": "^15.0.2",
54
+ "mocha": "^10.0.0",
55
+ "nyc": "^15.1.0",
56
+ "prettier": "^3.1.0",
57
+ "rimraf": "^5.0.5",
58
+ "typescript": "^5.0.2"
59
+ },
60
+ "files": [
61
+ "*.md",
62
+ "LICENSE",
63
+ "docs",
64
+ "dist"
65
+ ],
66
+ "husky": {
67
+ "hooks": {
68
+ "pre-commit": "lint-staged"
69
+ }
70
+ },
71
+ "lint-staged": {
72
+ "*.{js,json,md}": "prettier --write"
73
+ }
74
+ }