简体   繁体   English

如何包含不在 eslintrc 文件根文件夹中的 linting 文件夹?

[英]How to include a folder for linting that is not in root folder of eslintrc file?

I have two projects that share common files from the common folder.我有两个项目共享公共文件夹中的公共文件。

Now, I am trying to setup eslint so I can lint both the project folder and the common folder.现在,我正在尝试设置 eslint,这样我就可以同时检查项目文件夹和公共文件夹。

Folder structure is like this:文件夹结构是这样的:

  • MyProjectFolder我的项目文件夹

  • .eslintrc.js .eslintrc.js

  •  src
  • CommonFolder普通文件夹

  • src

I am trying to add an "override: [ files: ["src/**/*.js", "../CommonFolder/src/**/*.js"] }] " to eslint with relative path, but eslint is telling me that it is an invalid override path.我正在尝试添加一个"override: [ files: ["src/**/*.js", "../CommonFolder/src/**/*.js"] }]到 eslint 相对路径,但是eslint 告诉我这是一个无效的覆盖路径。

So, does anyone know how I can add CommonFolder into.eslintrc.js file?那么,有谁知道如何将 CommonFolder 添加到 .eslintrc.js 文件中?

If using VS-Code, you can add both directories to the ESLint working directory settings in the VS-Code Workspace Extensions settings.如果使用 VS-Code,您可以将这两个目录添加到 VS-Code 工作区扩展设置中的 ESLint 工作目录设置中。

  1. cmd + shift + p / ctrl + shift + p cmd + shift + p / ctrl + shift + p

  2. type workspace setting!输入工作区设置!

  3. Select ESLint from the Extensions menu. Select 扩展菜单中的 ESLint。

  4. Look for the working directory configuration and open it in JSON format.查找工作目录配置,以JSON格式打开。

  5. Include a directory path.包括目录路径。

     { "eslint.workingDirectories": [ "path1/", "path2/" ] }

you cant visit this link https://medium.com/devityoself/monorepo-eslint-vscode-6f5982c8404d你不能访问这个链接https://medium.com/devityoself/monorepo-eslint-vscode-6f5982c8404d

I hope this is helpful.我希望这是有帮助的。

I solved this by moving the.eslinrc.js config file to the parent folder which consists of both CommonFolder and ProjectFolder, and gave it a property of root: true .我通过将 .eslinrc.js 配置文件移动到由 CommonFolder 和 ProjectFolder 组成的父文件夹解决了这个问题,并为其赋予了root: true的属性。

If builder doesn't find a config file in it's root folder, it will begin searching parent folders until it finds a config file with root option set to true.如果构建器在其根文件夹中未找到配置文件,它将开始搜索父文件夹,直到找到根选项设置为 true 的配置文件。

This way, both my projects can use only one eslint config file, even if they use different build files.这样,我的两个项目都只能使用一个 eslint 配置文件,即使它们使用不同的构建文件也是如此。

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

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