question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

func-style ignores function expressions not starting with var keyword

See original GitHub issue

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;
}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kiranjhollacommented, Jan 19, 2017

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.

0reactions
albertocommented, Mar 11, 2017

Thanks for your interest in improving eslint. Unfortunately, it looks like this issue didn’t get enough support from the team and so I’m closing it. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach consensus after 21 days tend to never do it, and as such, we close those issues. This doesn’t mean the idea isn’t interesting, just that it’s not something the team can commit to.

Read more comments on GitHub >

github_iconTop Results From Across the Web

func-style - Pluggable JavaScript Linter - ESLint
Equivalent function expressions begin with the var keyword, followed by a name and then the function itself, such as: var doSomething = function()...
Read more >
Function expression - JavaScript - MDN Web Docs
The function keyword can be used to define a function inside an expression. ... The expression is not allowed at the start of...
Read more >
Require or disallow a space before function parenthesis ...
Style guides may require a space after the function keyword for anonymous functions, while others specify no whitespace. Similarly, the space after a ......
Read more >
Only arrow functions in eslint? - javascript - Stack Overflow
I use the eslint-plugin-prefer-arrow package (npmjs.com/package/eslint-plugin-prefer-arrow) in conjunction with "func-style": ["error", " ...
Read more >
Regular Expressions :: Eloquent JavaScript
If abc occurs anywhere in the string we are testing against (not just at the start), test will return true . Sets of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found