0

I added Husky to my Angular project which does not reside in the root folder. (Not my decision.) It is in the "frontend" subfolder. And the husky/git pre-commit hook is in frontend/.husky/pre-commit.

It looks like this:

#!/bin/sh

changed_files=$(git diff --cached --diff-filter=d --name-only | grep .ts$ | grep ^frontend | sed "s%^frontend/%%g")
if [ -n "$changed_files" ]; then
  . "$(dirname "$0")/_/husky.sh"
  cd frontend && npx ng lint --files $changed_files
fi

But for some reason it fails saying that the ts file cannot be found:

An unhandled exception occurred: Project 'C:/proj/frontend/src/app/my.component.spec.ts' does not exist.
See "C:\Users\XXX\AppData\Local\Temp\ng-u1G22D\angular-errors.log" for further details.
husky - pre-commit hook exited with code 127 (error)

But this doesn't make any sense. The file exists.

What am I missing? How to I fix this?

edit It works when I call the linter per file:

  cd frontend || exit 1
  for f in $changed_files
  do
    npx ng lint --files "$f"
  done
Apollo
  • 1,296
  • 2
  • 11
  • 24
  • 1
    That *sounds* like a bug in the linter code: perhaps it does its own internal "change directory" operation and loses track of where it should be working, or something? (Although then I would expect it to complain about a path name that doesn't exist, not one that does.) – torek Oct 28 '21 at 07:42
  • Damn.... Okay, we plan to migrate to ESLint anyway so I think I'll leave it like that and try it again with ESLint -- and perhaps lint-staged as well. Thank you @torek – Apollo Oct 28 '21 at 08:14

0 Answers0