简体   繁体   English

如何从 node.js 项目的根文件夹正确 eslint

[英]How to properly eslint from root folder for node.js project

I have a project structure that looks like:我的项目结构如下所示:

root/
    controllers/
    database/
    app.js
    server.js
    .eslintrc.json
    package.json
    etc...

I want to run eslint from command line to lint all.js files in root and subdirectories, but trying to use global patterns at this level is giving different errors: If I try: eslint./**/*.js , I start getting errors from node_modules , references from config files inside the modules..., which I assume means eslint is for some reason not ignoring the modules folder as it should by default.我想从命令行运行 eslint 以检查根目录和子目录中的 all.js 文件,但是尝试在此级别使用全局模式会出现不同的错误:如果我尝试: eslint./**/*.js .js,我开始得到来自node_modules的错误,来自模块内部配置文件的引用...,我认为这意味着 eslint 出于某种原因没有像默认情况下那样忽略模块文件夹。

The only way to get it working is by individually listing the files in the root and subdirectories, like:让它工作的唯一方法是分别列出根目录和子目录中的文件,例如:

yarn run eslint controllers/** server.js app.js database/**

Doing this works, but is not a very clean solution.这样做可行,但不是一个非常干净的解决方案。 Is this behavior expected?这种行为是预期的吗? Must I necessarily put everything inside a src folder as usually done?我必须像往常一样将所有内容都放在src文件夹中吗?

Not sure how to eslint properly from root folder but in order to check all files at once, one option I could see is to put all the project files and folders (other than eslint.json, package*.json etc) in a new folder "src".不确定如何从根文件夹正确 eslint,但为了一次检查所有文件,我可以看到的一个选项是将所有项目文件和文件夹(除了 eslint.json、package*.json 等)放在一个新文件夹中“来源”。

Post which project structure would be:-发布哪个项目结构将是:-

root/
    src/
        controllers/
        database/
        app.js
        server.js
    .eslintrc.json
    package.json
    etc...

Then doing npx eslint src然后做npx eslint src

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM