Reputation: 447
I'm following the first example (copy/paste) of custom config file (lint-staged.config.js) for lint-staged packaged from its github README without success. I get error Command failed with exit code 1.
always.
I have tried three things, for each case I had my lint-staged.config.js
in the root directory.
error Command failed with exit code 1.
"lint-staged": {
"packages/**/*.{ts,tsx}": [
"yarn lint-staged --config ./lint-staged.config.js"
]
},
error Command failed with exit code 1.
npx lint-staged --config ../lint-staged.config.js
error Command failed with exit code 1.
yarn lint-staged --config lint-staged.config.js
Im just looking for run a custom config file.
The problem is that the execution fails, the error message its related to the command but the command itself its correct as lint-staged [options]
(yarn/npx lint-staged -h) then to provide a custom config file it would as lint-staged [--config [path]]
but it fails (I even provide all kind of quotes for path).
Upvotes: 5
Views: 5088
Reputation: 447
The issue is that when the module doesn't provide an explicit positive answer to the validation it will always return error Command failed with exit code 1
meaning that the validation has fail.
To properly work as expected it should, in my case:
Then, the next following strings could be a message or messages like 'error some A' and 'error some B' and 'error some C' and so on...
For example: ['0', 'error some A', 'error some B', 'error some C']
const path = require("path");
module.exports = (absolutePaths) => {
const cwd = process.cwd();
const relativePaths = absolutePaths.map((file) => path.relative(cwd, file));
console.log("query", relativePaths)
return ['0', 'error some A', 'error some B', 'error some C']
};
This runs ok, but as Andrey Mikhaylov said in this post to run something like
"lint-staged": {
"packages/**/*.{ts,tsx}": [
"yarn lint-staged --config ./lint-staged.config.js"
]
},
If the lint returns an error, It will blow away the staged files causing a regression that will drop the commit completely, which means that all the work will be lost.
I fix this not intended/desired behaviour running the same command yarn lint-staged --config ./lint-staged.config.js
but from husky at the pre-commit file as
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn lint-staged --config ./lint-staged.config.js`
Upvotes: 1