I was wondering if an ESLint rule exists, or how to make one, that does the following:
Allows exports only in the form export default foo
and not in the form module.exports = foo
Is there a way to do this?
I was wondering if an ESLint rule exists, or how to make one, that does the following:
Allows exports only in the form export default foo
and not in the form module.exports = foo
Is there a way to do this?
Share Improve this question asked Sep 4, 2016 at 14:12 Code WhispererCode Whisperer 23.7k22 gold badges71 silver badges88 bronze badges2 Answers
Reset to default 8There are no core rules that can do this, but the following plugin rule might be what you are looking for:
https://github./benmosher/eslint-plugin-import/blob/master/docs/rules/no-monjs.md
It will report any usage of CommonJS-style modules:
Invalid:
/*eslint no-monjs: "error"*/
module.exports = foo;
Valid:
/*eslint no-monjs: "error"*/
export default foo;
module.exports is specific to Node. so add it to the env, like below
env: {
browser: true,
node: true,
es2021: true,
},