eslint-plugin-func-params-args 2.0.1 → 3.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 CHANGED
@@ -4,7 +4,7 @@ Limit the number of function parameters and arguments with ease and flexibility!
4
4
 
5
5
  This plugin intends to give you control over how many parameters are used in function definitions (declarations), function expressions, and arrow function expressions. In addition to this, you can also set limits on how many arguments can be used when calling functions, where you can set a global limit, and have even finer control by providing limits for specific function calls (set by configuring/providing the name of a function).
6
6
 
7
- [![Travis (.org) branch](https://img.shields.io/travis/abdusabri/eslint-plugin-func-params-args/master?logo=travis&style=flat-square)](https://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)
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
8
 
9
9
  ## Table of contents
10
10
 
@@ -1 +1 @@
1
- 'use strict';const{BASE_URL,isOptionConfigured}=require("../utils");function mapTypeToConfigKey(a){return"FunctionDeclaration"===a?"funcDefinition":"ArrowFunctionExpression"===a?"arrowFuncExpression":"FunctionExpression"===a?"funcExpression":"TSFunctionType"===a?"funcTypeAnnotation":void 0}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:"function 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})}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}}};
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}}};
@@ -24,7 +24,14 @@ If you have a need to set the value of an option to `0`, it is a valid limit tha
24
24
 
25
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
26
 
27
- **Error message example:** `function has too many parameters (3). Maximum allowed is (1).`
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]
28
35
 
29
36
  #### Example (A)
30
37
 
@@ -53,6 +60,8 @@ a = function (param1, param2, param3, param4) {};
53
60
 
54
61
  b = (param1, param2, param3, param4, param5) => {};
55
62
 
63
+ c = async function (param1, param2, param3, param4) {};
64
+
56
65
  c.reduce((param1, param2, param3, param4, param5) => {});
57
66
 
58
67
  interface IFoo {
@@ -72,6 +81,29 @@ type FooType = {
72
81
  param4: number
73
82
  ) => void;
74
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) => {};
75
107
  ```
76
108
 
77
109
  Examples of **correct** code for this rule:
@@ -100,6 +132,8 @@ interface IFoo {
100
132
  type FooType = {
101
133
  onBar: (param1: number, param2: number, param3: number) => void;
102
134
  };
135
+
136
+ type onBarFn = (param1: number, param2: number, param3: number) => void;
103
137
  ```
104
138
 
105
139
  #### Example (B)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-func-params-args",
3
- "version": "2.0.1",
3
+ "version": "3.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": ">=12"
27
+ "node": ">=14"
28
28
  },
29
29
  "main": "dist/index.js",
30
30
  "scripts": {
@@ -38,23 +38,24 @@
38
38
  "build": "rimraf dist && minify lib -d dist"
39
39
  },
40
40
  "dependencies": {
41
- "requireindex": "~1.2.0"
41
+ "requireindex": "~1.2.0",
42
+ "eslint-utils": "^3.0.0"
42
43
  },
43
44
  "peerDependencies": {
44
- "eslint": "^4 || ^5 || ^6 || ^7.1.0 || ^8.0.0"
45
+ "eslint": "^6 || ^7.1.0 || ^8.0.0"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@typescript-eslint/parser": "^5.4.0",
48
49
  "babel-minify": "^0.5.1",
49
50
  "coveralls": "^3.1.0",
50
51
  "eslint": "^8.2.0",
51
- "husky": "^7.0.1",
52
- "lint-staged": "^12.1.2",
52
+ "husky": "^8.0.2",
53
+ "lint-staged": "^13.0.4",
53
54
  "mocha": "^10.0.0",
54
55
  "nyc": "^15.1.0",
55
56
  "prettier": "^2.2.1",
56
- "rimraf": "^3.0.2",
57
- "typescript": "^4.3.4"
57
+ "rimraf": "^4.4.0",
58
+ "typescript": "^5.0.2"
58
59
  },
59
60
  "files": [
60
61
  "*.md",