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] error when anonymous function is exported as default

See original GitHub issue

Consider 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:closed
  • Created 8 years ago
  • Comments:18 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
jrenczcommented, Feb 19, 2016

maybe this rule should just ignore exports and we need another rule just to handle exports?

1reaction
michaelficarracommented, Feb 14, 2016

😒 unnamed default exports

Read more comments on GitHub >

github_iconTop 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 >

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