func-style ignores function expressions not starting with var keyword
See original GitHub issueThe 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:
- Created 7 years ago
- Reactions:1
- Comments:25 (13 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That code could also be written by declaring the function separately and then assigning it to the variable foo as and when required.
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 believefunc-style
should include an option to disallow assignment of function expressions to variables.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.