Как заставить ESLint сканировать все файлы (рекурсивно) из root? - PullRequest
0 голосов
/ 03 августа 2020

Я прохожу курс по веб-разработке full stack. В курсах есть раздел на ESLint , в котором говорится, что вы можете запустить ESLint и рекурсивно сканировать все файлы и каталоги из root с помощью команды

./node_modules/.bin/eslint .

Однако, когда я это сделаю ошибка

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)

Я перепробовал все, чтобы заставить это работать. Я могу успешно запустить eslint для определенных c файлов и c вот так

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

Однако я не могу заставить его сканировать из root рекурсивно. Вот список вещей, которые я пробовал, среди бесчисленного множества других вариантов

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

Даже пытался установить и сделать это на другом компьютере, та же проблема, поэтому я могу только заключить, что команда неверна. Если у кого-то есть совет, я был бы очень признателен!

Вот 'ls -a' каталога root, если он полезен:

.           .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: Вот содержимое моего файла .eslintr c. js

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'
        ]
    }
}

, а в файле .eslintignore у меня просто

build

package. json файл

{
  "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"
  }
}

1 Ответ

0 голосов
/ 03 августа 2020

Я исправил! Оказывается, проблема заключалась в том, что я использовал старую версию Node (v10.5). Обновлен до версии V12, и теперь все работает нормально.

Вот руководство как обновить для всех, кто это читает.

Что привело меня к решению, я получал другие проблемы с запуском Jest, говорящего

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

, что привело меня к сообщению об обновлении Node. После обновления я обнаружил, что обе мои проблемы были исправлены. Так что, если у кого-то есть аналогичные проблемы с Jest - попробуйте

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...