admin管理员组

文章数量:1434934

I have two projects that share mon files from the mon folder.

Now, I am trying to setup eslint so I can lint both the project folder and the mon 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?

I have two projects that share mon files from the mon folder.

Now, I am trying to setup eslint so I can lint both the project folder and the mon 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?

Share Improve this question asked Nov 29, 2022 at 0:35 perun_the_mightyperun_the_mighty 1211 silver badge5 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

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./devityoself/monorepo-eslint-vscode-6f5982c8404d

I hope this is helpful.

The .eslintrc* file should work as expected on its own, but if you're using VS Code, it may not behave. The eslint.workingDirectories setting is what you probably want.

Just adding the folder path may not work. Consider using mode:

"eslint.workingDirectories": [{ "mode": "auto" }]

According to the docs: https://marketplace.visualstudio./items?itemName=dbaeumer.vscode-eslint#settings-options

[{ "mode": "auto" }] (@since 2.0.0): instructs ESLint to infer a working directory based on the location of package.json, .eslintignore and .eslintrc* files. This might work in many cases but can lead to unexpected results as well.

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.

本文标签: javascriptHow to include a folder for linting that is not in root folder of eslintrc fileStack Overflow