[func-style] error when anonymous function is exported as default
See original GitHub issueConsider the following one-liner:
export default function () {}
Eslint config (from demo): ECMA features:
- modules
Rules:
- func-style
Error is reported:
1:16 - Expected a function expression. (func-style)
Although the example given is obviously not a function expression there might be a way to define exception in the rule for the case when one want to have all functions created using function expressions but allow anonymous (or maybe even named?) function to be exported as default from a module.
It makes sense to do so for short modules that export one single function as default.
Without a way to express this exception one valid way to default-export a function is this:
const init = function () {};
export {init as default};
which makes us define provisional variable which would be unneeded otherwise.
Issue Analytics
- State:
- Created 8 years ago
- Comments:18 (16 by maintainers)
Top Results From Across the Web
Unexpected default export of anonymous function [Solved]
The "Unexpected default export of anonymous function" warning is caused when we try to export an anonymous function using a default export.
Read more >Unexpected default export of anonymous function import/no ...
In OP's code, they had export a default function without a name. However, in the above answer, we have given the function the...
Read more >JS.BASE.FUNC.NAMES - Klocwork Static Code Analysis
This rule has a string option: "always" (default) requires function expressions to have a name; "as-needed" requires function expressions to have a name,...
Read more >You can export as default an anonymous function just like you ...
You can export as default an anonymous function just like you would do with an object. One usual pattern is to write something...
Read more >Airbnb JavaScript Style Guide()
8.1 When you must use an anonymous function (as when passing an inline callback), ... bad // filename es6.js export { es6 as...
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
maybe this rule should just ignore exports and we need another rule just to handle exports?
😒 unnamed default exports