Skip to content

Husky running in the wrong folder #307

@PypWalters

Description

@PypWalters

Describe the bug

For me, Husky ends up running npx lint-staged in ./.husky instead of in wp-content. Which means it is unable to find .lintstagedrc.json and then nothing is scanned.

Parent dir: /Users/<myuser>/Local Sites/<project>/app/public/wp-content
Scaffold path: ./.husky/_

So cd "${PARENT_DIR}/${SCAFFOLD_PATH}/.." resolves to /Users/<myuser>/Local Sites/<project>/app/public/wp-content/./.husky

If I add the following to pre-commit it works as expected.

if [ "$(basename "$PWD")" != "wp-content" ]; then
	cd ..
fi

Steps to Reproduce

  • Create a scaffold project.
  • Create an intentionally bad commit like:
// Test file for pre-commit hook with linting errors
console.log("Testing Husky pre-commit hook");
let unused_variable = "this will cause linting errors";
function   badFormatting( ){
  console.log( "Poor formatting and unused variable" )
}
  • Run git commit -m"test commit"
  • In my case husky runs in the wrong folder and doesn't stop the commit.

Screenshots, screen recording, code snippet

No response

Environment information

  • Device: Macbook Pro M4
  • OS: Sequoia 15.5

WordPress information

This scaffold was adapted to work with VIP's scaffold.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions