简体   繁体   中英

Apply ESLint rules only to some files by pattern in IDEA

My NodeJS project has the following structure:

project
|
|- client
|  |
|  |- .eslintrc.yml
|  | ...
|
|- server
...

Both client and server folders contain JS code.

For code linting I use eslint with the following config:

extends: ../node_modules/eslint-config-airbnb/.eslintrc
rules:
  import/no-commonjs:
    - error
env:
  browser: true

I use Intellij IDEA's integration with ESLint for the real-time linting. The problem is that IDEA checks all the files in the project, while I want it to only check files from the client folder.

You have 2 options here:

  1. add server/* to .eslintignore

or

  1. set up ESLint inspection to work for the desired scope only:

    • in Settings | Appearance & Behavior | Scopes , create a new scope with server excluded (or just client included recursively)
    • in Settings | Editor | Inspections | JavaScript | Code quality tools , choose this scope for ESLint inspection (in screenshot below, sub is a name of custom scope):

在此处输入图片说明

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