简体   繁体   English

javascript/typescript - 通过 eslint 规则强制将 object 作为 function 参数传递

[英]javascript/typescript - force to pass object as function argument by eslint rule

Is it possible to force the following rule by eslint?是否可以通过 eslint 强制执行以下规则?

  • if the number of function arguments is more than one, use "object" as an argument.如果 function arguments 的数量多于一个,则使用“object”作为参数。

For example,例如,

  • good好的
    • const f = (x: string) =>... const f = (x: string) =>...
    • const f = (x: {id: string}) =>... const f = (x: {id: string}) =>...
    • const f = (x: {id: string; name: string}) =>... const f = (x: {id: string; name: string}) =>...
  • bad坏的
    • const f= (x: string; y: string) =>... const f= (x: string; y: string) =>...

I checked the official document ( https://eslint.org/docs/rules/ ), but I couldn't find appropriate rules.我查看了官方文档( https://eslint.org/docs/rules/ ),但找不到合适的规则。 I wonder if some kind of custom rules can realize this.我想知道是否某种自定义规则可以实现这一点。

You can use max-params rule.您可以使用max-params规则。 https://eslint.org/docs/rules/max-params Set the max value to 1 . https://eslint.org/docs/rules/max-paramsmax设置为1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM