简体   繁体   中英

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.

Folder structure is like this:

  • MyProjectFolder

  • .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.

So, does anyone know how I can add CommonFolder into.eslintrc.js file?

If using VS-Code, you can add both directories to the ESLint working directory settings in the VS-Code Workspace Extensions settings.

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

  2. type workspace setting!

  3. Select ESLint from the Extensions menu.

  4. Look for the working directory configuration and open it in JSON format.

  5. Include a directory path.

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

you cant visit this link 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 .

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.

This way, both my projects can use only one eslint config file, even if they use different build files.

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