reference Rule options

flddef_assign

Value
true or false
Default
false
See also
arrow_is_function, vardef_assign

With flddef_assign: true, a pattern that assigns a function, such as $X = function (...) { ... }, also matches a function defined as a member:

A function declared at the top level, function top(e) { ... }, is not matched.

Examples

Functions defined in a class

The rule function-member turns the option on.

widget.yaml
rules:  - id: function-member-default    pattern: $X = function (...) { ... }    message: function assigned to a name    languages: [javascript]    severity: WARNING  - id: function-member    pattern: $X = function (...) { ... }    message: function assigned to a name    languages: [javascript]    severity: WARNING    options:      flddef_assign: true
widget.js
class Widget {  // ruleid: function-member  onClick = function (e) { return e; };  // ruleid: function-member  onKey(e) { return e; }}// ruleid: function-member-default, function-memberobj.onClick = function (e) { return e; };// ok: function-memberfunction top(e) { return e; }
Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.