如何使eslint工作在Node js中的整个目录

时间:2017-10-03 11:53:59

标签: javascript node.js eslint lint

我正在尝试检查节点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)

请帮忙

2 个答案:

答案 0 :(得分:3)

您似乎也在node_modules中删除文件,这是您不应该做的。

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

  

当ESLint在目录上运行时,ESLint支持.eslintignore个文件从linting过程中排除文件。作为单独的CLI参数提供的文件将免于排除。 .eslintignore文件是纯文本文件,每行包含一个模式。它可以位于任何目标目录的祖先中;它会影响其包含目录中的文件以及所有子目录。以下是.eslintignore文件的简单示例:

node_modules/*

答案 1 :(得分:0)

  

您可以添加 string NetworkPath = XMLWork.XMLGetElement(@"D:\\" + Properties.Settings.Default.currentUser + "\\Digital Statements\\App_Data\\User\\" + Properties.Settings.Default.currentUser + ".wit", "NetworkMasters"); string FileName = Path.GetFileName(file); string LocalPath = Path.GetFullPath(file); string FilePath = NetworkPath; File.Copy(file, Path.Combine(FilePath, FileName)); string NewFileName = LocalPath.TrimEnd('.', 'x', 'm', 'l'); //MessageBox.Show(NewFileName); File.Move(file, NewFileName+".del"); 文件,只需添加以下内容即可   第.eslintignore行。

这将忽略node_modules中的文件。