Skip to content
Advertisement

How to configure ESLint so that it disallows default exports

I’ve been searching the web and StackOverflow for this for quite some time with no success.

What I’m trying to do have ESLint mark the following as errors:

export default ...;

with default being the key here. So far the best I’ve got is a reference to eslint-plugin-import plugin and some of its rules that can make me closer to the target, namely the no-anonymous-default-export rule. But even with this rule the following default exports would be valid:

const foo = 123
export default foo

export default class MyClass() {}

export default function foo() {}

How can I configure ESLint in such a way that these four would also be considered errors?

Advertisement

Answer

If you’re already using eslint-plugin-import, you can use the no-default-export rule (which was added around February 2018).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement