I've Backend & Frontend project configured on the same repository, let's say I've Backend with ESLint & Frontend with TSLint
Can I have somehow run both lint-staged configurations when I commit changes on both projects?
I can't see why not. I assume they are on different sub-paths and 🚫💩 lint-staged works with globs. See the documentation
Let me share both project package.json config:
Frontend
"scripts": {
"lint": "npm run lint:js",
"lint:eslint": "eslint --ignore-pattern 'internals/scripts'",
"lint:js": "npm run lint:eslint -- .",
"lint:staged": "lint-staged",
},
...
,
"lint-staged": {
"gitDir": "../",
"linters": {
"Frontend/**/*.js": "eslint"
}
}
Backend
"scripts": {
"lint": "npm run lint:js",
"lint:eslint": "eslint",
"lint:js": "npm run lint:eslint -- .",
"lint:staged": "lint-staged",
},
...
,
"lint-staged": {
"gitDir": "../",
"linters": {
"Backend/**/*.js": "eslint"
}
}
@okonet
If I commit change on Frontend & Backend...
It triggers Frontend precommit but doesn't trigger Backend precommit. There's only 1 git hook ofc
Actually since 1st (Frontend) lint-staged precommit is successful, the 2nd one (Backend) doesn't trigger because 1st eslint precommit passed.
Any idea how can I fix this?
No. I don't know anything about your setup. Sounds like it's config issue
Okay after looking at the config, I think the problem is that you have 2 package.json files with separate lint-staged configs but you only have 1 pre-commit hook.
I'd suggest:
.lintstagedrc file in the root of your project and point 🚫💩 lint-staged to it using --config argument. See https://github.com/davidtheclark/cosmiconfig{
"{Frontend,Backend}/**/*.js": "eslint"
}
This might still make lint-staged confused about file paths so you have to experiment a bit with gitDir option proabably. The setup you have is rather exotic :)
Can I close this one?
Testing it; sorry for taking it long. Give me some hours please
@okonet
Point your pre-commit hook (sorry I could not see it how you add it in your configs) to run lint-staged only once for both configs
I used husky for managing hooks; how can I make sure it only executes once?
@okonet
I've errors cuz one project uses eslint-plugin-redux-saga and the other doesn't how to read modules from it's right project folder? Or what am I missing?
Output
[14:54:22] Running tasks for Frontend/**/*.js [failed]
[14:54:22] → 🚫 eslint found some errors. Please fix them and try committing again.
Oops! Something went wrong! :(
ESLint couldn't find the plugin "eslint-plugin-redux-saga". This can happen for a couple different reasons:
1. If ESLint is installed globally, then make sure eslint-plugin-redux-saga is also installed globally. A globally-installed ESLint cannot find a locally-i
nstalled plugin.
2. If ESLint is installed locally, then it's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
npm i eslint-plugin-redux-saga@latest --save-dev
If you still can't figure out the problem, please stop by https://gitter.im/eslint/eslint to chat with the team.
25h25h
husky > pre-commit hook failed (add --no-verify to bypass)
What I've seen is that hook runs both package precommit scripts. Any idea how to avoid this?
Also lint-staged run linter for all files and not only staged files.
Did you try my suggestions?
Also lint-staged run linter for all files and not only staged files.
If there is a regression, please file a separate issue with a repo to reproduce.
@SuEric I think this may be helpful for you - okonet/lint-staged#how-to-use-lint-staged-in-a-multi-package-monorepo
Documentation has been added which addresses the question raised here, closing the issue.