0

I am trying to lint my ionic project and abort the commit if lint fails. Running npm run lint in the console shows the error. I have installed precommit and lately husky ("husky": "^0.15.0-rc.6") with the below code inside package.json

"husky": {
    "hooks": {
      "pre-commit": "npm run lint"
    }
}

I have read a number of tutorials and the closest I got is linting but still commits if there are errors. Have also reverted the git hooks. How can I share the modified hooks with a team and run lint on every commit? At the moment git does commit event though npm run lint returns errors. I have remote the precommit hooks so the husky installation can successfully set up new ones.

Xerri
  • 4,916
  • 6
  • 45
  • 54
  • If you return a severity of error from TS Lint, then you can get the npm scripts to fail. See the configuration information: https://palantir.github.io/tslint/usage/configuration/ – Steven Scott Feb 08 '18 at 02:03
  • I added severity and defaultSeverity. By default it’s already errors so it should already fail – Xerri Feb 08 '18 at 04:29
  • Maybe check the TSLint versions then? I have my lint configuration set to not fail on the build on errors. Maybe the configuration in Ionic's configuration files is the same, and they have the switch to not fail the build process? – Steven Scott Feb 09 '18 at 16:16
  • It’s set to ^5.8.0 in package.json do it should have the latest – Xerri Feb 09 '18 at 16:50
  • Set it as ^5.9.1 to have the latest and it did not work – Xerri Feb 09 '18 at 20:23
  • Currently returning error mean you are returning exit code 2 but it seems I need something that returns exit code 1 to stop the commit. – Xerri Feb 09 '18 at 20:34
  • That is strange as usually anything other than 0 will stop the process. Maybe change the severities then to 1 to get your commit to stop. Maybe this is an issue with the commit tool and not the lint? – Steven Scott Feb 09 '18 at 20:49
  • I'm using GitHub Desktop on Mac. How can I change the severity? – Xerri Feb 09 '18 at 20:52
  • Sorry, severities in the TSLint to match what your hook requires (1) to stop the commit. – Steven Scott Feb 09 '18 at 22:40
  • With rc7 there is not exit. `export GIT_PARAMS="$*" node_modules/run-node/run-node ./node_modules/husky/lib/runner/bin `basename "$0"`. This is the code. Had to revert back to the rc6 code to exit the commit. According to the do an error severity return 2. Is there a severity that returns 1? – Xerri Feb 10 '18 at 06:32

1 Answers1

0

Check out the comments in this GitHub issue. Adding --bailOnLintError true to lint script did the trick.

Xerri
  • 4,916
  • 6
  • 45
  • 54