eslint-plugin-func-params-args 1.0.6 → 2.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.
@@ -1 +1 @@
1
- 'use strict';const{BASE_URL,isOptionConfigured}=require("../utils");function mapTypeToConfigKey(a){return"FunctionDeclaration"===a?"funcDefinition":"ArrowFunctionExpression"===a?"arrowFuncExpression":"FunctionExpression"===a?"funcExpression":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}},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}}};
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}}};
@@ -18,6 +18,8 @@ Here are the available options for this rule:
18
18
 
19
19
  - `arrowFuncExpression`: accepts an integer indicating the max number of parameters used in an arrow function expression. This overrides the global limit
20
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
+
21
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.
22
24
 
23
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.
@@ -44,7 +46,7 @@ With a config like:
44
46
 
45
47
  Examples of **incorrect** code for this rule:
46
48
 
47
- ```js
49
+ ```ts
48
50
  function foo(param1, param2, param3, param4) {}
49
51
 
50
52
  a = function (param1, param2, param3, param4) {};
@@ -52,11 +54,29 @@ a = function (param1, param2, param3, param4) {};
52
54
  b = (param1, param2, param3, param4, param5) => {};
53
55
 
54
56
  c.reduce((param1, param2, param3, param4, param5) => {});
57
+
58
+ interface IFoo {
59
+ onBar: (
60
+ param1: string,
61
+ param2: string,
62
+ param3: string,
63
+ param4: string
64
+ ) => void;
65
+ }
66
+
67
+ type FooType = {
68
+ onBar: (
69
+ param1: number,
70
+ param2: number,
71
+ param3: number,
72
+ param4: number
73
+ ) => void;
74
+ };
55
75
  ```
56
76
 
57
77
  Examples of **correct** code for this rule:
58
78
 
59
- ```js
79
+ ```ts
60
80
  function foo(param1, param2, param3) {}
61
81
 
62
82
  a = function (param1, param2, param3) {};
@@ -72,6 +92,14 @@ a = function (param1, param2) {};
72
92
  b = () => {};
73
93
 
74
94
  c.reduce((param1, param2, param3) => {});
95
+
96
+ interface IFoo {
97
+ onBar: (param1: string, param2: string, param3: string) => void;
98
+ }
99
+
100
+ type FooType = {
101
+ onBar: (param1: number, param2: number, param3: number) => void;
102
+ };
75
103
  ```
76
104
 
77
105
  #### Example (B)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-func-params-args",
3
- "version": "1.0.6",
3
+ "version": "2.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": ">=10"
27
+ "node": ">=12"
28
28
  },
29
29
  "main": "dist/index.js",
30
30
  "scripts": {
@@ -41,18 +41,20 @@
41
41
  "requireindex": "~1.2.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "eslint": "^4 || ^5 || ^6 || ^7.1.0"
44
+ "eslint": "^4 || ^5 || ^6 || ^7.1.0 || ^8.0.0"
45
45
  },
46
46
  "devDependencies": {
47
+ "@typescript-eslint/parser": "^5.4.0",
47
48
  "babel-minify": "^0.5.1",
48
49
  "coveralls": "^3.1.0",
49
- "eslint": "^7.25.0",
50
- "husky": "^6.0.0",
51
- "lint-staged": "^11.0.0",
52
- "mocha": "^8.3.2",
50
+ "eslint": "^8.2.0",
51
+ "husky": "^7.0.1",
52
+ "lint-staged": "^12.1.2",
53
+ "mocha": "^9.0.2",
53
54
  "nyc": "^15.1.0",
54
55
  "prettier": "^2.2.1",
55
- "rimraf": "^3.0.2"
56
+ "rimraf": "^3.0.2",
57
+ "typescript": "^4.3.4"
56
58
  },
57
59
  "files": [
58
60
  "*.md",