Home > Enterprise >  javascript/typescript - force to pass object as function argument by eslint rule
javascript/typescript - force to pass object as function argument by eslint rule

Time:01-27

Is it possible to force the following rule by eslint?

  • if the number of function arguments is more than one, use "object" as an argument.

For example,

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

I checked the official document ( https://eslint.org/docs/rules/ ), but I couldn't find appropriate rules. I wonder if some kind of custom rules can realize this.

CodePudding user response:

You can use max-params rule. https://eslint.org/docs/rules/max-params Set the max value to 1.

  •  Tags:  
  • Related