Skip to content

Latest commit

 

History

History
69 lines (45 loc) · 2.43 KB

no-hide-core-modules.md

File metadata and controls

69 lines (45 loc) · 2.43 KB

Disallow third-party modules which are hiding core modules (n/no-hide-core-modules)

❌ This rule is deprecated.

⚠️ This is deprecated since v4.2.0. This rule was based on an invalid assumption. See also #69.

If you have dependencies which have the same name as core modules, your module would use the third-party modules instead of core modules. Especially, if you depends on such modules indirectly and npm flattens dependencies, you can depend on such third-party modules before as you know it. This might cause unintentional behaviors.

This rule warns require() expressions and import declarations if those import a third-party module which has the same name as core modules.

📖 Rule Details

👎 Examples of incorrect code for this rule:

/*eslint n/no-hide-core-modules: "error"*/

const util = require("util")  // ERROR if `util` module exists in node_modules directory.
const path = require("path")  // ERROR if `path` module exists in node_modules directory.
// ...

👍 Examples of correct code for this rule:

/*eslint n/no-hide-core-modules: "error"*/

const util = require("util")  // OK if this is the core module 'util' surely.
const path = require("path")  // OK if this is the core module 'path' surely.

Options

{
    "n/no-hide-core-modules": ["error", {
        "allow": [],
        "ignoreDirectDependencies": false,
        "ignoreIndirectDependencies": false,
    }]
}

allow

If you are sure that your module depends on the third-party module which has the same name as a core module, you can allow it by allow option. E.g. {"allow": ["util", "path"]}. Default is en empty array.

ignoreDirectDependencies

If ignoreDirectDependencies: true, if the third-party module which has the same name as a core module exists in your package.json, this rule ignores it.

This option would allow all explicit dependencies which are hiding core modules.

ignoreIndirectDependencies

If ignoreIndirectDependencies: true, if the third-party module which has the same name as a core module does not exist in your package.json, this rule ignores it.

This option would allow all implicit dependencies which are hiding core modules.

🔎 Implementation