# @jshawl/pre-commit

> Pre-commit guards

Latest version **0.1.2** (published 2020-05-25) · GPL-3.0-only license · 0 weekly downloads

## Install

```sh
npm install @jshawl/pre-commit
pnpm add @jshawl/pre-commit
yarn add @jshawl/pre-commit
bun add @jshawl/pre-commit
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2020-05-25 |
| First published | 2020-05-25 |
| Weekly downloads | 0 |
| License | GPL-3.0-only |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 39.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Jesse Shawl |
| Maintainers | jshawl |
| Keywords | git, pre-commit hook |

## Links

- npm: https://www.npmjs.com/package/@jshawl/pre-commit
- Repository: https://git.sr.ht/~jshawl/pre-commit
- npm.io page: https://npm.io/package/@jshawl/pre-commit

## Dependencies (2)

- [ora](https://npm.io/package/ora.md) ^4.0.4
- [@jshawl/pre-commit](https://npm.io/package/@jshawl/pre-commit.md) 0.0.4

## Recent versions

- 0.1.2 (latest) — 2020-05-25
- 0.1.1 — 2020-05-25
- 0.1.0 — 2020-05-25
- 0.0.10 — 2020-05-25
- 0.0.9 — 2020-05-25
- 0.0.8 — 2020-05-25
- 0.0.7 — 2020-05-25
- 0.0.6 — 2020-05-25
- 0.0.5 — 2020-05-25
- 0.0.4 — 2020-05-25
- 0.0.3 — 2020-05-25
- 0.0.2 — 2020-05-25
- 0.0.1 — 2020-05-25

## README

# Pre-Commit Hook

This npm package generates a git `pre-commit` hook that runs a set of customizable bash commands.

## Philosophy

### No package.json changes

Local commits are a very personal activity. Your own commit guards don't _need_ to be shared with other contributors to your repository.

### Not npm specific

This package's runtime is nodejs but you can add arbitrary bash commands as commit guards:

`.pre-commit-scripts`: 

```
npm run format:check
npm run format # format anyway to pass the next check
npm run lint
! git diff --staged | grep console.log # prevent accidentally sharing debug statements
```

### Index safe by default

No changes are ever applied to the staging area programmatically.

The general workflow is:

1. Try to commit
2. See commit guard errors
3. Fix errors
4. Stage changes
5. Try to commit (and succeed this time)

## Install

```
npm install @jshawl/pre-commit
```

A post-install script will copy a `pre-commit` executable to `.git/hooks/pre-commit`.

## Usage

```
git commit --allow-empty -m "testing pre-commit hook"
```

A few npm scripts will run. If any of them fail, git will not
commit. You can skip the pre-commit hook by adding the `--no-verify` to a `git commit` command.

## Configuration

It's possible to override the default commands.

Create a `.pre-commit-scripts` file like this one:

```
npm run format:check
npm run format
npm run lint
npm run build
```

in your repository's root directory, and list whichever commands you want to `exit 0` before allowing a commit.

Optionally, consider ignoring this file so other contributors to the repository don't have to follow your own commit rules:

```
echo .pre-commit-scripts >> .git/info/exclude
```

## Uninstall

```
npm uninstall @jshawl/pre-commit
```

or just remove the pre-commit hook:

```
rm .git/hooks/pre-commit
```

---
_Source: https://npm.io/package/@jshawl/pre-commit · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
