最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ESLint - Prefer Export Default to Module.Exports - Stack Overflow

programmeradmin3浏览0评论

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,
},
发布评论

评论列表(0)

  1. 暂无评论