简体   繁体   中英

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.

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?

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

Post which project structure would be:-

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

Then doing npx eslint src

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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