gpt4 book ai didi

javascript - 如何让 eslint 为 Node js 中的整个目录工作

转载 作者:搜寻专家 更新时间:2023-11-01 00:37:26 24 4
gpt4 key购买 nike

我正在尝试检查我的 Node js 应用程序中的 linting 错误,然后启动服务器。

  "scripts": {
"lint": "eslint .",
"pretest": "eslint **/*.js",
"start": "node .",
"posttest": "npm run lint && nsp check"
}

npm run pretest 从不检查整个目录集。我做了一个 npm run lint 。它给了我奇怪的错误,比如

Cannot find module 'eslint-config-medikoo-es5'
Referenced from: /home/rahul/DSP/dsp-api/server/node_modules/es5-ext/package.json
Error: Cannot find module 'eslint-config-medikoo-es5'
Referenced from: /home/rahul/DSP/dsp-api/server/node_modules/es5-ext/package.json
at ModuleResolver.resolve (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/util/module-resolver.js:74:19)
at resolve (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:515:25)
at load (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:532:26)
at configExtends.reduceRight (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:424:36)
at Array.reduceRight (native)
at applyExtends (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:408:28)
at Object.load (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:566:22)
at loadConfig (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config.js:63:33)
at getLocalConfig (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config.js:130:29)
at Config.getConfig (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config.js:260:26)

如果我安装那个依赖项,我就会卡在这个位置

Cannot find module '@ljharb/eslint-config'
Referenced from: /home/rahul/DSP/dsp-api/server/node_modules/express/node_modules/qs/.eslintrc
Error: Cannot find module '@ljharb/eslint-config'
Referenced from: /home/rahul/DSP/dsp-api/server/node_modules/express/node_modules/qs/.eslintrc
at ModuleResolver.resolve (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/util/module-resolver.js:74:19)
at resolve (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:515:25)
at load (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:532:26)
at configExtends.reduceRight (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:424:36)
at Array.reduceRight (native)
at applyExtends (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:408:28)
at Object.load (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config/config-file.js:566:22)
at loadConfig (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config.js:63:33)
at getLocalConfig (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config.js:130:29)
at Config.getConfig (/home/rahul/DSP/dsp-api/node_modules/eslint/lib/config.js:260:26)

请帮忙

最佳答案

看起来你也在检查 node_modules 中的文件,你不应该这样做。

您应该在 these instructions 之后忽略此文件夹.此外,您应该更改 NPM pretest 脚本以匹配 lint 脚本。我建议将其更改为 npm run lint

ESLint supports .eslintignore files to exclude files from the linting process when ESLint operates on a directory. Files given as individual CLI arguments will be exempt from exclusion. The .eslintignore file is a plain text file containing one pattern per line. It can be located in any of the target directory’s ancestors; it will affect files in its containing directory as well as all sub-directories. Here’s a simple example of a .eslintignore file:

node_modules

关于javascript - 如何让 eslint 为 Node js 中的整个目录工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46543994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com