简体   繁体   中英

NodeJS: ESLint Rule to Force “Correct” Import Names

In a NodeJS, if a module exports a symbol with one name

// File: module-a.js
class Foo {}
module.exports = Foo

it's possible, and common, for that export to imported with a different name

// file: module-b.js
const Baz = require('./module-a')

Is there an ESLint rule that can flag exported classes and constructor functions that are imported with variable names different from their actual symbol name?

Unfortunately this rule is not yet there in ESLint, but there's a PR open for this Add rule to enforce default import naming in eslint-plugin-import

If you need it very badly you could add the rule manually into your project as a custom rule.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM