0

let's say, I have following project structure:

back/package.json
back/lib/Content/*.js
front/package.json
slices/budget/back/package.json
slices/budget/back/lib/Content/*.js
slices/budget/front/package.json
slices/accounting/back/package.json
slices/accounting/back/lib/Content/*.js
slices/accounting/front/package.json

how do I?

cd back && eslint ./lib/**/*.js ../slices/**/lib/Content/*.js

specifically, I want to

  • install eslint one time as devDependencies
  • somewhere in /back of root module
  • config eslint one time somewhere in /back/package.json:eslint key of root module
  • add eslint config in /back/package.json of root module just one time
  • eslint entire tree of modules
  • not in each slice seperatly
  • run from ci cd
  • so I need a way to run from /back
  • and later - maybe someway to respect eslint config hierarchy
  • not change project directory structure at all

what I receive

cd back && npm run lint

> back@1.0.0 lint
> eslint ../


Oops! Something went wrong! :(

ESLint: 8.23.1

ESLint couldn't find a configuration file

reason: https://eslint.org/docs/latest/user-guide/configuring/configuration-files#using-configuration-files

jonny
  • 1,326
  • 9
  • 44
  • 62
  • https://github.com/eslint/eslint/discussions/16329 – jonny Oct 05 '22 at 09:16
  • What is "sast"? The tag has no description or wiki. – starball Oct 06 '22 at 09:00
  • I find the list of requirements hard to read and confusing. You should also provide more debugging details so others can reproduce your issue. Try to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – starball Oct 06 '22 at 09:06
  • Is it acceptable to put the eslint config in a .eslintrc file @jonny? – cascading-jox Oct 06 '22 at 13:23
  • already have back/.eslintrc, tried to specify --ignore-path ../.eslintignore --config ../.eslintrc; it looks like I am forced to create one more package.json with devDependencies only at project root / – jonny Oct 06 '22 at 14:55
  • I believe that is usually how you do it. It's still weird that it doesn't work for you. I tried mimicking your project structure and for me it worked. Do you have the .eslintrc file in the parent folder of back? Otherwise the path is just .eslintrc. – cascading-jox Oct 07 '22 at 08:33

5 Answers5

1

no real answer, except to create .eslintignore, .eslintrc, package.json at project root

jonny
  • 1,326
  • 9
  • 44
  • 62
0

The error is probably because you haven't specified the eslint config file explicitly. To run eslint on all the modules, starting from the parent folder, run: eslint ../ -c .eslintrc.js (or whatever .eslintrc file you use in back). It seems like eslint is confused if it does not have the config file in the same directory it is running from hence you need to manually specify the path to it.

cascading-jox
  • 982
  • 1
  • 7
  • 21
0

You can use the --ignore-path option to specify a file with patterns that should be ignored. The file should contain one pattern per line. For example, to ignore all files in the node_modules directory, you could create a .eslintignore file with the following contents:

node_modules

You can also use the --ignore-pattern option to specify a pattern that should be ignored. For example, to ignore all files in the node_modules directory, you could run:

eslint . --ignore-pattern node_modules
Tibic4
  • 3,709
  • 1
  • 13
0

The correct way of solving this issue would be creating sharable config file with configuration you have in back right now:

module.exports = {
    rules: {
        semi: [2, "always"]
    }
};

Then you publish it to public or private npm with a name @your-project/eslint-config and use it in .eslintrc.json that is the same in all your projects:

{
    "extends": [
        "@your-project/eslint-config"
    ]
}

This way gives you ability to configure CI in a simple and independent way if you have lots of repositories: just run eslint lib/*.js.

If you have all the repositories in one computer and want to lint all of them using one command, you can use one of my tools:

  • redfork, install eslint and redfork globally and run:
redfork 'eslint lib/*.js'

But maybe you need to have some changes in project structure.

  • runny, if you don't want to make changes in project structure, just add configuration file .runny.json:
{
    "command": "eslint lib/*.js",
    "directories": [
        "~/one",
        "~/two",
        "~/three"
    ]
}

It will run the same command for any directory you need.

coderaiser
  • 749
  • 5
  • 15
0

I had a similar issue and the following has solved my problem.

I guess you haven't specified the eslint config file explicitly.

To run eslint on all the modules

run: eslint ../ -c .eslintrc.js

It seems like eslint is confused if it does not have the config file in the same directory it is running from, so you need to manually specify the path to it.

Mehdi
  • 385
  • 1
  • 12