arrow_is_function
- Value
trueorfalse- Default
true- See also
flddef_assign
Two function forms match each other while this option is on:
- a function pattern
function (...) { ... }also matches an arrow function, with a block body,(req) => { ... }, or without,(req) => 1; - a function declaration pattern
function $F(req) { ... }also matches a variable holding an arrow function or a function expression, such asconst handler = (req) => { ... }.
With arrow_is_function: false, each pattern matches only its own form.
Examples
Callbacks
The rule route-handler turns the option off.
handlers.yaml
rules: - id: route-handler-default pattern: app.get($PATH, function (...) { ... }) message: route handler languages: [javascript] severity: WARNING - id: route-handler pattern: app.get($PATH, function (...) { ... }) message: route handler languages: [javascript] severity: WARNING options: arrow_is_function: falsehandlers.js
// ruleid: route-handler-default, route-handlerapp.get("/", function (req, res) { res.send("hi"); });// ruleid: route-handler-defaultapp.get("/a", (req, res) => { res.send("hi"); });// ruleid: route-handler-defaultapp.get("/b", (req, res) => res.send("hi"));Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.Functions held in variables
declared.yaml
rules: - id: request-handler-default pattern: function $F(req) { ... } message: request handler languages: [javascript] severity: WARNING - id: request-handler pattern: function $F(req) { ... } message: request handler languages: [javascript] severity: WARNING options: arrow_is_function: falsedeclared.js
// ruleid: request-handler-default, request-handlerfunction a(req) { return 1; }// ruleid: request-handler-defaultconst b = (req) => { return 1; };// ruleid: request-handler-defaultconst c = function (req) { return 1; };Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.