eslint: func-style ignores function expressions not starting with var keyword

The func-style rule has been set to enforce use of function declarations.

var eslintConfig = {
	'root': true,
	'env': {
		'browser': true
	},
	'extends': 'eslint:recommended',
	'rules': {
		/** Coding Style Standards **/
		'func-style': ['error', 'declaration', { 'allowArrowFunctions': true }]
	}
}

module.exports = eslintConfig;

I would expect that with this configuration, code such as the one below would lead to an error. But it doesn’t.

var fnVariable;

fnVariable = function() {
      return true;
}

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 25 (13 by maintainers)

Most upvoted comments

That code could also be written by declaring the function separately and then assigning it to the variable foo as and when required.

let foo = 5

assert.equal(foo + 5, 10);

foo = _myFunction;

/**
 * JSDoc what the function is meant to do.
 */
function _myFunction() {
         // Do what it is meant to do...
}

My idea is to enforce a consistent coding style across many developers so that code is easily recognizable for the entire team. After this discussion, I realize that func-style disallowing all Function Expressions might be overkill. However, I do believe func-style should include an option to disallow assignment of function expressions to variables.