require function names to match the name of the variable or property to which they are assigned (func-name-matching)
This rule requires function names to match the name of the variable or property to which they are assigned. The rule will ignore property assignments where the property name is a literal that is not a valid identifier in the ECMAScript version specified in your configuration (default ES5).
This rule takes an options object with one key, includeCommonJSModuleExports
, and a boolean value. This option defaults to false
, which means that module.exports
and module["exports"]
are ignored by this rule. If includeCommonJSModuleExports
is set to true, module.exports
and module["exports"]
will be checked by this rule.
Examples of incorrect code for this rule:
/*eslint func-name-matching: "error"*/
var foo = function bar() {};
foo = function bar() {};
obj.foo = function bar() {};
obj['foo'] = function bar() {};
var obj = {foo: function bar() {}};
/*eslint func-name-matching: ["error", { "includeCommonJSModuleExports": true }]*/
module.exports = function foo(name) {};
module['exports'] = function foo(name) {};
Examples of correct code for this rule:
/*eslint func-name-matching: "error"*/
/*eslint-env es6*/
var foo = function foo() {};
var foo = function() {};
var foo = () => {};
foo = function foo() {};
obj.foo = function foo() {};
obj['foo'] = function foo() {};
obj['foo//bar'] = function foo() {};
obj[foo] = function bar() {};
var obj = {foo: function foo() {}};
var obj = {[foo]: function bar() {}};
var obj = {'foo//bar': function foo() {}};
var obj = {foo: function() {}};
obj['x' + 2] = function bar(){};
var [ bar ] = [ function bar(){} ];
module.exports = function foo(name) {};
module['exports'] = function foo(name) {};
Do not use this rule if you want to allow named functions to have different names from the variable or property to which they are assigned.