最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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"
    ]
  },
发布评论

评论列表(0)

  1. 暂无评论