flddef_assign
- Value
trueorfalse- 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 class field holding a function,
onClick = function (e) { ... }; - a class method,
onKey(e) { ... }; - a method in an object literal,
{ onClick(e) { ... } }; - an object property holding a function,
{ onKey: function (e) { ... } }.
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: truewidget.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.