Array callback function should not be used for an array with empty slots.

  • UNINVOKED_ARRAY_CALLBACK
  • Error
  • Medium
  • No tags

This rule applies when the Array functions having callback argument are used for an array with empty slots.

When the Array constructor is called with a single number argument, an array with the specified number of empty slots (not actual undefined values) is constructed.

If a callback function is passed to the function of this array, the callback function is never invoked because the array has no actual elements.

Noncompliant Code Example

View with compliant examples side by side
const list = new Array(5).map(_ => createElement()); // UNINVOKED_ARRAY_CALLBACK alarm

Compliant Code Example

View with noncompliant examples side by side
const list = new Array(5).fill().map(_ => createElement());

Version

This rule was introduced in DeepScan 1.12.0-beta.

See