2

My project folder is setup with two subfoders, frontend and backend to house codes respectively.

Therefore in the root folder I have:

- backend
    - package.json
    - other backend codes
- frontend
    - package.json
    - other frontend codes
- package.json

In the root's package.json, I have:

  "scripts": {
    "frontend:lint": "cd ./frontend && npm run lint && cd ..",
    "backend:lint": "cd ./backend && npm run lint && cd .."
  },
  "devDependencies": {
    "husky": "4.3.8",
    "lint-staged": "10.5.3"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "frontend/**/*.{ts, tsx, json, html}": [
      "npm run frontend:lint"
    ],
    "backend/**/*.{ts, json}": [
      "npm run backend:lint"
    ]
  }

However if I do git add and the git commit on root level, it keeps saying No staged files match any configured task.

I have looked into both of the sub package.json and they all worked. I am not sure how to configure lint-staged to filter files.

jamesdeath123
  • 4,268
  • 11
  • 52
  • 93

2 Answers2

0

Some explanation of how to target files is given here: https://www.npmjs.com/package/lint-staged#user-content-filtering-files

It may not be applicable in your case as your config gives multiple file types, but just to flag it as a possibility, there is a “Lint-staged tasks do not run if a single filetype is specified with curly braces e.g. *.{js} ” ticket open on the lint-staged repo in which a collaborator comments:

We use micromatch for the globs, and this sounds like an issue in the library.

Perhaps the issue extends further. I also ran into the No staged files match any configured task. message and for me adding the jsx extension to the config fixed it.

Originally I had:

  "lint-staged": {
    "**/*.{js}": [
      "eslint --fix"
    ]
  }

After amending to the following, it worked fine:

  "lint-staged": {
    "**/*.{js,jsx}": [
      "eslint --fix"
    ]
  }
Mina
  • 150
  • 2
  • 12
0

It's working for me, use multi-package monorepo

root
┣ backend
┃ ┣ .lintstagedrc.json
┗ frontend
┃ ┣ .lintstagedrc.json
┃ 

First, install dependencies in root/package.json file, and remove lint-staged config field:

"husky": "8.0.3",
"lint-staged": "13.2.3"

Then, in .husky/pre-commit file: (Note: Reinstall package when modify this file.)

#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged

In backend/.lintstagedrc.json file:

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

In frontend/.lintstagedrc.json file:

{
  "src/**/*.{ts,tsx,js,jsx}": [
    "eslint --fix",
    "prettier --write"
  ]
}
weiliang
  • 663
  • 8
  • 13