繁体   English   中英

"是否可以忽略某些(但不是全部)父目录中的 ESLint 配置文件?"

[英]Is it possible to ignore ESLint configuration files in certain, but not all, parent directories?

根据ESLint 文档<\/a>,当 ESLint 运行时,它会在当前目录和所有父目录中搜索配置文件,包括根目录 ( \/<\/code> )、主目录或指定了root: true<\/code>选项的目录在 ESLint 配置文件中。

是否可以配置 ESLint 以检查某些父目录中的 ESLint 配置文件,但不能检查其他父目录中的 ESLint 配置文件?

为了使事情更具体,以我目前正在从事的基于 Drupal 9 的项目为例。 项目树具有以下一般形状:

.
├── .eslintrc.js
├── node_modules
├── package-lock.json
├── package.json
└── web
    ├── .eslintrc.json
    └── modules
        └── custom
            └── some_module
                ├── .eslintrc.js
                ├── node_modules
                ├── package-lock.json
                └── package.json

经过一番研究和思考,我意识到extends<\/code>关键字可以帮助解决这个问题。 我最终将以下内容添加到some_module\/.eslintrc.js<\/em>配置文件中:

module.exports = {
  // Do not search for ESLint configuration files in parent directories because
  // Drupal 9 puts one in the *web* directory which we do not want applied.
  //
  // However, do manually extend from the ESLint configuration at the root of
  // this repository.
  root: true,
  extends: ["../../../../.eslintrc.js"],

  // [other ESlint configuration]
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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