chopsalot
chopsalot

Reputation: 384

How do I get ESLint to scan all files (recursively) from the root?

I am going through a course on full stack web dev. The courses has a section on ESLint, which advises that you can run ESLint and scan all files and directories recursively from the root with the command

./node_modules/.bin/eslint .

However when I do this the error

Oops! Something went wrong! :(

ESLint: 7.6.0

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.join (path.js:1157:7)
    at FileEnumerator._iterateFilesRecursive (/Users/David/iPhone/Full Stack Course/Exercises Backend/part3/node_modules/eslint/lib/cli-engine/file-enumerator.js:426:35)
    at _iterateFilesRecursive.next (<anonymous>)
    at FileEnumerator.iterateFiles (/Users/David/iPhone/Full Stack Course/Exercises Backend/part3/node_modules/eslint/lib/cli-engine/file-enumerator.js:287:49)
    at iterateFiles.next (<anonymous>)
    at CLIEngine.executeOnFiles (/Users/David/iPhone/Full Stack Course/Exercises Backend/part3/node_modules/eslint/lib/cli-engine/cli-engine.js:751:48)
    at ESLint.lintFiles (/Users/David/iPhone/Full Stack Course/Exercises Backend/part3/node_modules/eslint/lib/eslint/eslint.js:515:23)
    at Object.execute (/Users/David/iPhone/Full Stack Course/Exercises Backend/part3/node_modules/eslint/lib/cli.js:294:36)
    at main (/Users/David/iPhone/Full Stack Course/Exercises Backend/part3/node_modules/eslint/bin/eslint.js:142:52)

I have tried everything trying to get this to work. I can successfully run eslint on specific files etc like so

./node_modules/.bin/eslint index.js    //Successfully scans index.js
npx eslint model/**   //Scans all files in the model directory
npx eslint *.js  //Scans all .js files at the root but not directories 

However I cannot get it to scan from the root recursively. Here are a list of things I have tried, amongst countless other variations

npx eslint ./
npx eslint ./**
npx eslint "./**"
npx eslint models/../**

Even tried installing and doing this on another machine, same issue, so I can only conclude the command is wrong. If anyone has any advice I would be most appreciative!

Here is a 'ls -a' of the root directory incase its useful:

.           .eslintrc.js        build           package-lock.json
..          .git            index.js        package.json
.DS_Store       .gitignore      models          requests
.env            Procfile        mongo.js
.eslintignore       README.md       node_modules

EDIT: Here is the contents of my .eslintrc.js file

module.exports = {
    'env': {
        'browser': true,
        'es2020': true
    },
    'extends': 'eslint:recommended',
    'parserOptions': {
        'ecmaVersion': 11,
        'sourceType': 'module'
    },
    'rules': {
        'eqeqeq': 'error',
        'no-trailing-spaces': 'error',
        'object-curly-spacing': [
            'error', 'always'
        ],
        'arrow-spacing': [
            'error', { 'before': true, 'after': true }
        ],
        'no-console': 0,
        'indent': [
            'error',
            2
        ],
        'linebreak-style': [
            'error',
            'unix'
        ],
        'quotes': [
            'error',
            'single'
        ],
        'semi': [
            'error',
            'never'
        ]
    }
}

and in the .eslintignore file I simply have

build

package.json file

{
  "name": "backend",
  "version": "0.0.1",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "test": "echo \"Error: no test specified\" && exit 1",
    "build:ui": "rm -rf build && cd ../../part2/1_rendering_collection && npm run build --prod && cp -r build ../../part3/backend/",
    "deploy": "git push heroku master",
    "deploy:full": "npm run build:ui && git add . && git commit -m uibuild && npm run deploy",
    "logs:prod": "heroku logs --tail",
    "lint": "eslint ."
  },
  "author": "David Blake",
  "license": "MIT",
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "mongoose": "^5.9.26"
  },
  "devDependencies": {
    "eslint": "^7.5.0",
    "nodemon": "^2.0.4"
  }
}

Upvotes: 1

Views: 5154

Answers (1)

chopsalot
chopsalot

Reputation: 384

I fixed it! Turns out the problem was I running an old version of Node (v10.5). Updated to V12 and now it all works fine.

Here is a guide how to update for anyone reading this.

What led me to the solution was I was getting other issues running Jest saying

Test suite failed to run
    TypeError: (0 , _vm(...).compileFunction) is not a function

which led me to a post saying to update Node. After updating I found it fixed both my problems. So if anyone is having similar issues with Jest also - try that

Upvotes: 1

Related Questions