SonarTS icon indicating copy to clipboard operation
SonarTS copied to clipboard

bool-param-default should ignore params beginning with underscore

Open slubowsky opened this issue 5 years ago • 1 comments

I want to request a feature.

Typescript noUnusedParameters option ignores params beginning with underscore (understand that some people dislike this, but this is how it is). For such params that are being ignored it would seem preferable to use the optional parameter syntax over providing an unused default value. A default value makes it LESS clear that the parameter is actually not used.

slubowsky avatar Jan 21 '19 15:01 slubowsky

@slubowsky thanks for the feedback. Sounds reasonable!

function foo(p1: number, _p2?: boolean) { // '_p2' should not be reported as it unused
   return p1 * 2;
}

When implementing the fix we should consider 2 options:

  • relying on parameter name (starts with _) -> suggested by @slubowsky
  • relying on symbol table (parameter is not used), not sure if it's better or worse

RSPEC -> https://jira.sonarsource.com/browse/RSPEC-4798

vilchik-elena avatar Feb 01 '19 12:02 vilchik-elena