Write me a CodeQL JS query to find calls to the map function from lodash.
- User
Write me a CodeQL JS query to find calls to the map function from lodash.
Assistant
/** * @name Find calls to lodash map function * @description Identifies calls to the map function from the lodash library * @kind problem * @problem.severity recommendation * @id javascript/lodash-map-call */ import javascript /** * Gets a reference to the lodash library */ DataFlow::Node getLodashRef() { // Full lodash import: const _ = require('lodash') exists(DataFlow::ModuleImportNode mod | mod.getPath() = "lodash" and result = mod ) or // ES6 import of full lodash: import _ from 'lodash' exists(ESModule::ImportDeclaration decl | decl.getImportedPath().getValue() = "lodash" and result = DataFlow::importNode(decl).getAChild() ) } /** * Gets a call to the lodash map function */ DataFlow::CallNode getLodashMapCall() { // Direct call on lodash: _.map(...) exists(DataFlow::PropRef prop | prop.getPropertyName() = "map" and prop.getBase() = getLodashRef() and result.getCalleeNode() = prop ) or // Direct import of map: const map = require('lodash/map') exists(DataFlow::ModuleImportNode mod | mod.getPath() = "lodash/map" and result.getCalleeNode() = mod ) or // ES6 named import: import { map } from 'lodash' exists(ESModule::ImportDeclaration decl, ESModule::ImportSpecifier spec | decl.getImportedPath().getValue() = "lodash" and spec = decl.getASpecifier() and spec.getImported().getName() = "map" and result.getCalleeNode() = DataFlow::importNode(spec) ) } from DataFlow::CallNode call where call = getLodashMapCall() select call, "Call to lodash map function."
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.