Movatterモバイル変換


[0]ホーム

URL:


CodeQL documentation
CodeQL resources

Ignoring result from pure array method

ID: js/ignore-array-resultKind: problemSecurity severity: Severity: warningPrecision: highTags:   - quality   - reliability   - correctnessQuery suites:   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

Theconcat,join andslice methods are pure and do not modify any of the inputs or the array the method is called on. It is therefore generally an error to ignore the return value from a call to one of these methods.

Recommendation

Use the returned value from the calls toconcat,join orslice.

Example

A functionextend is defined in the following example. The function uses theconcat method to add elements to thearr array. However, theextend function has no effect as the return value fromconcat is ignored:

vararr=[1,2,3];functionextend(others){arr.concat(others);}

Assigning the returned value from the call toconcat to thearr variable fixes the error:

vararr=[1,2,3];functionextend(others){arr=arr.concat(others);}

References


[8]ページ先頭

©2009-2025 Movatter.jp