unicorn/no-anonymous-default-export
Require a name for a function or class that is the default export
A default export without a name gives you nothing to search for, and every file that imports it makes up its own name. Stack traces show it as default or <anonymous>.
The rule looks at functions and classes, in export default and in module.exports =. Other values, such as objects and numbers, aren't reported.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"unicorn/no-anonymous-default-export" = "error" # or "warn"Examples#
example.js1 problem
export default function (user) {This function default export is missing a name
return `${user.first} ${user.last}`;
}example.js1 problem
export default (user) => `${user.first} ${user.last}`This function default export is missing a name;example.js1 problem
module.exports = class {This class default export is missing a name
items = [];
};example.jsNo problems
export default function fullName(user) {
return `${user.first} ${user.last}`;
}An arrow function doesn't have a name. Give it one with a variable:
example.jsNo problems
const fullName = (user) => `${user.first} ${user.last}`;
export default fullName;example.jsNo problems
module.exports = class Cart {
items = [];
};