sudo-suhas / lint-staged-multi-pkg

Example repo to demonstrate use of `lint-staged` with multi-pkg projects
MIT License
188 stars 19 forks source link

"Install lint-staged at the package root" solution requires extra works? #32

Closed OshotOkill closed 4 years ago

OshotOkill commented 4 years ago

I checked out the description and installed husky, lint-staged, prettier, stylelint in project root, and configured hooks in .lintstagedrc.yml, however they didn't work.

My dir structure:

|-- .git
|-- .gitignore
|-- .lintstagedrc.yml
|-- .prettierrc
|-- node_modules
|-- package.json
|-- yarn.lock
|
|-- my-project-1
|
`-- my-project- 2
    |-- package.json
    |-- src
    |   |-- a
    |   |     |-- index.ts
    |   |     `-- index.less
    |   `-- b
    |          `-- index.ts
    `-- yarn.lock

.lintstagedrc.yml

linters:
  my-project-2/**/*.{ts,tsx,json}:
    - prettier --config ./.prettierrc --write
  my-project-2/**/*.{css,less}:
    - stylelint --fix

I tried to add husky configs in package.json and it still didn't solve the problem:

{
   "husky": {
      "hooks": {
        "pre-commit": "lint-staged"
      }
   },
   ...
}

I wonder if I missed something, or we should only install these dependencies and configure .lintstagedrc in project root without some extra works?

OshotOkill commented 4 years ago

Ok, I figure out what's going on, it seems that husky didn't install hooks in .git/hooks at all. I reinstalled it again and set husky configurations in package.json, it works properly.

Shall we add descriptions about adding husky configurations in package.json since someone new like me may be confused at first ? Besides, lint-staged removed advanced configuration since 9.0, we need to update .lintstaged.yml

from :

linters:
  my-project-2/**/*.{ts,tsx,json}:
    - prettier --config ./.prettierrc --write
  my-project-2/**/*.{css,less}:
    - stylelint --fix

to:

my-project-2/**/*.{ts,tsx,json}:
  - prettier --config ./.prettierrc --write
my-project-2/**/*.{css,less}:
  - stylelint --fix