I am using lint-staged to lint JS and SCSS files in our project, but I also have multiple ESLint configs depending on the context. One that runs as part of a build process that is less strict and allows things like console.logs. Then a more strict config that gets run on pre-commit hooks.
As it stands right now I can call lint-staged for the pre-commit hooks but have to lint all files on my build process.
I'm wondering if there is a way to have something like:
"lint-staged": {
"src/main/webpack/**/*.js": "eslint --fix",
"src/main/webpack/**/*.scss": "stylelint --fix"
},
"lint-staged-build": {
"src/main/webpack/**/*.js": "eslint --fix -c .eslintconfig-build.json",
"src/main/webpack/**/*.scss": "stylelint --fix"
}
OR
"lint-staged": {
"pre-commit": {
"src/main/webpack/**/*.js": "eslint --fix",
"src/main/webpack/**/*.scss": "stylelint --fix"
},
"build": {
"src/main/webpack/**/*.js": "eslint --fix -c .eslintconfig-build.json",
"src/main/webpack/**/*.scss": "stylelint --fix"
}
You could try using the JS config format and export a different configuration based on an ENV variable, for example:
const precommit = {
"src/main/webpack/**/*.js": "eslint --fix",
"src/main/webpack/**/*.scss": "stylelint --fix"
}
const build = {
"src/main/webpack/**/*.js": "eslint --fix -c .eslintconfig-build.json",
"src/main/webpack/**/*.scss": "stylelint --fix"
}
const useBuild = process.env.NODE_ENV === 'production'
module.exports = useBuild ? build : precommit
Alternatively, pass a different config: lint-staged -c lint-staged.build.json
This just made me realize that this might allow me doing something cool now!
Exactly what I was looking for :)
Why the current execution is so limited? Actually with pretty-quick we can accomplish this... 👋
@5ay3h the simple config format is to make lint-staged easier to integrate for most people, while — as you can see — the JS format allows advanced usage.
What is limited in your opinion?
@iiroj a more straight-forward approach to run lint-staged with different commands.
For example: lint-staged --command "prettier -c", lint-staged --command "prettier --write", etc.
https://github.com/azz/pretty-quick enables this functionality, but its obviously limited to prettier execution 😞
@5ay3h would the --command flag assume that it would match all files?
It would get complicated pretty quick (pun intended) when you'd have flags like lint-staged --glob "*.js" --command "prettier -c" --glob "*.json" --command "jsonlint --fix"
And I don't think having an array of command/glob is a good idea. My suggestion is to being able to run lint-staged independently (with only single command and glob)
Sorry but I don't think we want go this route. The provided solution solves the problem and to me addition CLI flags isn't worth the complexity considering same can be achieved with a different syntax ATM. I'll close this since I consider it's resolved. Feel free to re-open if I'm mistaken.
Most helpful comment
Alternatively, pass a different config:
lint-staged -c lint-staged.build.json