Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 632
perun_the_mighty Avatar asked Oct 23 '25 09:10

perun_the_mighty


2 Answers

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.

like image 168
zaN-121 Avatar answered Oct 25 '25 21:10

zaN-121


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.com/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.

like image 39
aarowman Avatar answered Oct 25 '25 23:10

aarowman