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

lint staged config with react-express monorepo failing #36

Closed rohit-ambre closed 4 years ago

rohit-ambre commented 4 years ago

Hi, I have project with react and express but it is not wrapped using lerna. project structure:

project
├── client/
│   ├── src/
│   ├── package.json
│   ├── index.js
│   └── utils.js
├── cli.js
├── src/
├── index.js
├── config.js
└── package.json

So outside folder contains all express related files and client folder has create-react-react(typescript) project. I have separate eslint config for both. express eslint is in root and react's eslint is in client folder.

my scripts in base package.json:

"lint": "eslint .",
"lint:fix": "eslint . --fix",
"client:lint": "cd client && npm run lint",
"client:lint:fix": "cd client && npm run lint:fix",

my husky and lint-staged config:

"lint-staged": {
    "./**/*": [
      "npm run lint:fix"
    ],
    "./client/**/*.{js,jsx,ts,tsx}": [
      "npm run client:lint:fix"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },

what I need is,

  1. if file is from base express directory then it should run first task on it for linting and then add
  2. and if file is from client folder then it should use client lint command to fix

so in my configuration, it is working fine for express files but sometimes it is failing in client related files. it says,

Prevented an empty git commit!

Because even if my react files have changes and linting errors it is not committing those files after running the lint fixes.

Can anyone please help me with the correct lint-staged config

while committing to this branch it is giving errors in .eslintignore etc file which are ignored like following, so I pushed it with --no-verify flag Screenshot 2020-07-20 at 10 16 56 PM

Thank you

sudo-suhas commented 4 years ago

Please create an issue in the lint-staged repo. I will not be able to help you with this.

sudo-suhas commented 4 years ago

Would recommend going through the readme