codermonk
codermonk

Reputation: 132

how to get the staged files in custom lint-staged scripts and how to debug the custom script file?

I have lint-staged + husky configured in my app and I need to run a custom lint-staged script on precommit. Here is my package.json

//package.json
"lint-staged": {
  "app/**/*.js": "node ./lint-staged-scripts/customScript"
}

In the customScript.js, how will I be able to access the staged files ?

I tried running node --inspect-brk ./lint-staged-scripts/customScript, could not get staged files in args.

But on running npx lint-staged -d, i could see the files getting listed in the fileList.

How to access staged files and debug custom lint-staged scripts?

TIA and i'm new to writing lint-staged scripts !

Upvotes: 1

Views: 2588

Answers (1)

codermonk
codermonk

Reputation: 132

I still could not figure how to debug it. But looks like we get the staged files as arguments to the customScript file.

process.argv.slice(2) // will give the list of staged files

It is mentioned in the docs as well https://github.com/okonet/lint-staged#configuration

This config will execute your-cmd with the list of currently staged files passed as arguments. So, considering you did git add file1.ext file2.ext, lint-staged will run the following command: your-cmd file1.ext file2.ext

Upvotes: 1

Related Questions