eslint: [func-style] error when anonymous function is exported as default

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.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (16 by maintainers)

Commits related to this issue

Most upvoted comments

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

😒 unnamed default exports