S1854 FP with inline preincrement

SonarQube 8.9.7-community, Docker

Since index is actually being used in string interpolation here, the increment/assignment of index is not useless.

Maybe id should raise a positive as well, since it’s not being used and convention might prefer it being named ‘_’, but I’m not sure if that’s just preference or something that should actually be enforced.

const someIds = [1, 5, 8];

const queryParams = someIds.map((id, index) => {
    return `(${++index}::int)`; // Remove this useless assignment to variable "index" javascript:S1854
}).join(',');

Hi,

Welcome to the community!

When I analyze this with the newest version of SonarQube, I don’t get any issues, so I guess this FP has been eliminated in more recent versions.

 
HTH,
Ann