Unused parameters of local function should be removed

  • UNUSED_PARAM
  • Code Quality
  • Low
  • No tags

This rule applies when parameters are specified but not used in the body of a locally declared function.

In general, function parameters could be part of an API contract that cannot be changed easily.

However, local functions do not have such restrictions because they are only used inside the declaring file. So, for code readability and maintainability, it is recommended to remove unused parameters of a local function and cleanup unnecessary code at call sites.

Also, it might be a mistake that a programmer forgets to use the specified parameters.

Note:

  1. Not applied when the parameter name starts with _ because we regard it as intentionally unused.
  2. Not applied for callback function.
  3. Not applied when the call sites of a function cannot be determined statically.
  4. Not applied when the call sites of a function may call other functions.
  5. Not applied if the function is empty or uses arguments variable.
  6. Not applied at test case code because unused parameters are usually harmless at tests. Currently, BDD, TDD and QUnit style test cases are recognized.

Noncompliant Code Example

View with compliant examples side by side
function foo(x) {
    function helper(width, height) { // UNUSED_PARAM alarm on 'width' because it is not used in the function body.
        doSomething(height);
    }
    let width = computeWidth(x);
    let height = computeHeight(x);
    helper(width, height);
}

Compliant Code Example

View with noncompliant examples side by side
function foo(x) {
    function helper(height) {
        doSomething(height);
    }
    let height = computeHeight(x);
    helper(height);
}

Version

This rule was introduced in DeepScan 1.30.0.

Was this documentation helpful?