📌  相关文章
📜  eslint 停止从 node_modules 兼容导入 - Javascript (1)

📅  最后修改于: 2023-12-03 15:30:38.815000             🧑  作者: Mango

ESLint: Disallow Compatibility Imports from node_modules

ESLint is a linting tool that helps programmers identify and fix common errors in their code. One of the features of ESLint is the ability to disallow compatibility imports from node_modules.

Compatibility imports are imports that are used to make code written for one version of a module compatible with a different version. These imports are typically added as a temporary fix during a transition period when code is being migrated from one module version to another.

While compatibility imports can be useful during the transition period, they can also introduce new errors into the code, and can make it difficult to maintain the code over time. As a result, it's often a good practice to avoid using compatibility imports altogether.

To disallow compatibility imports from node_modules in ESLint, you can add the following rule to your ESLint configuration file:

{
  "rules": {
    "import/no-extraneous-dependencies": ["error", {"devDependencies": false}]
  }
}

This rule disables the use of compatibility imports from node_modules by disallowing the use of "devDependencies" in import statements. This ensures that only "dependencies" and "peerDependencies" are used in import statements, and that compatibility imports are avoided.

By avoiding compatibility imports, you can make your code more maintainable over time, and reduce the risk of introducing new errors into your code. With ESLint, you can easily enforce this best practice in your codebase, and ensure that all programmers on your team are following the same guidelines.