admin管理员组

文章数量:1246585

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 badges
Add a ment  | 

2 Answers 2

Reset to default 8

There 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,
},

本文标签: javascriptESLintPrefer Export Default to ModuleExportsStack Overflow