javascript - Running `lint-staged` takes a lot of time even for a single changed file - Stack Overflow

Running npm run pre-mit takes a lot of time even if only one file has been changed.package.json script

Running npm run pre-mit takes a lot of time even if only one file has been changed.

package.json script: "pre-mit": "lint-staged",

and lint-staged mands:

  "lint-staged": {
    "src/**/*.{ts,js,json}": [
      "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
    ],
    "src/**/*.{js,ts,json}": [
      "prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
    ]
  },

It feels like eslint runs in the entire project How can I make it run only in the changed files?

Running npm run pre-mit takes a lot of time even if only one file has been changed.

package.json script: "pre-mit": "lint-staged",

and lint-staged mands:

  "lint-staged": {
    "src/**/*.{ts,js,json}": [
      "eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
    ],
    "src/**/*.{js,ts,json}": [
      "prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
    ]
  },

It feels like eslint runs in the entire project How can I make it run only in the changed files?

Share Improve this question asked Jun 9, 2022 at 12:39 rb27rb27 1713 silver badges10 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

You're asking eslint (and prettier) to run over the whole codebase by providing a glob. If you skip out the glob then each will run only on the file matched by lint-staged.

  "lint-staged": {
    "src/**/*.{ts,js,json}": [
      "eslint --fix"
    ],
    "src/**/*.{js,ts,json}": [
      "prettier --write"
    ]
  },

You can make this even better by bining the operations. Since they all run on the exact same set of files putting them in an array runs the operations sequentially and prevents conflicts between the two operations.

  "lint-staged": {
    "src/**/*.{ts,js,json}": [
      "eslint --fix", "prettier --write"
    ],
    "test/**/*.{js,ts,json}": [
      "prettier --write"
    ]
  },

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745064615a4609179.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信