2

I recently created an Angular 13 project and added ESLint configuration to my app. I have a few libraries so I added ESLinting to those projects as well. I set up husky and lint-staged to run ng lint fix and prettier fix on the staged files. When I commit, however, I the prompt freezes for a good deal of time then completes. Here is my configuration.

{
 "scripts": {
    "lint:fix": "ng lint -- --fix && npm run prettier:fix",
    "prettier:check": "npm run prettier -- -l",
    "prettier:cli": "npm run prettier -- -c",
    "prettier:fix": "npm run prettier:cli -- --write"
 }
 "dependencies: {
    ...
    "husky": "^4.3.8",
    "lint-staged": "^11.2.6",
    ...
 }
 "husky": {
    "hooks": {
      "commit-msg": "commitlint -e $HUSKY_GIT_PARAMS",
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*.{ts,js,json,css,md,ejs,html}": [
      "npm run lint:fix"
    ]
  }
}

As a test I ran my npm run lint:fix command and it lints the app and every library. It takes approximately the same amount of time when I commit so I assume committing is running lint on every file.

How do I run my npm run lint:fix script on only staged files?

afriedman111
  • 1,925
  • 4
  • 25
  • 42

0 Answers0