Skip to content

Open-Paws/no-animal-violence-pre-commit

Repository files navigation

License: MIT Version Python Last Commit desloppify score

no-animal-violence-pre-commit

A pre-commit hook that scans staged files for language that normalizes harm to animals — idioms, industry euphemisms, and tech jargon — and suggests clearer alternatives. It runs locally before any code leaves the developer's machine, making it the earliest enforcement point in the development workflow. No external dependencies; patterns compile at import time.

Note

This project is part of the Open Paws ecosystem — AI infrastructure for the animal liberation movement. Explore the full platform →

Usage

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/Open-Paws/no-animal-violence-pre-commit
    rev: v0.2.0
    hooks:
      - id: no-animal-violence
        files: \.(py|ts|js|md|yaml|yml)$   # recommended: limit to text files
        exclude: ^tests/fixtures/           # optional: skip known-bad fixtures

Quickstart

  1. Install pre-commit:
    pip install pre-commit
  2. Add the hook config above to .pre-commit-config.yaml in your repository root.
  3. Install the hooks:
    pre-commit install
  4. Run against all existing files (recommended on first install):
    pre-commit run no-animal-violence --all-files
  5. From this point on, the hook runs automatically on every git commit.

Run without installing (one-shot scan):

pre-commit try-repo https://github.com/Open-Paws/no-animal-violence-pre-commit no-animal-violence --all-files

Features

What it checks

The hook scans each staged file line-by-line against 65+ compiled regular expressions (case-insensitive) covering three categories:

  • Animal idioms in code and prosekill two birds with one stone, guinea pig, cattle vs. pets, herding cats, canary in the coal mine, and 30+ others
  • Industry euphemisms for exploitationlivestock → farmed animals, processing plant → slaughterhouse, humane slaughter, spent hens, depopulation, and others
  • Tech jargon with harmful rootsmaster/slave → primary/replica, whitelist/blacklist → allowlist/denylist, cowboy coding, code monkey, dogfooding

On any match the hook prints the file path, line number, matched phrase, and suggested alternative, then exits non-zero to block the commit:

Animal violence language detected:

  src/utils.py:14
    Found:   "kill two birds with one stone"
    Suggest: "accomplish two things at once"

  docs/architecture.md:37
    Found:   "cattle vs. pets"
    Suggest: "ephemeral vs. persistent"

2 instance(s) found. Consider using the suggested alternatives.

Fix the flagged phrases, re-stage, and commit again.

Configuration options

All filtering uses standard pre-commit arguments — no environment variables or config files are required:

Option Example Effect
files `.(py ts
exclude ^tests/fixtures/ Skip paths matching the pattern
stages [pre-commit, manual] Control when the hook runs

All patterns are built in. There is no external config file to maintain.

Running as a standalone script

The scanner can also be invoked directly, outside of pre-commit:

pip install git+https://github.com/Open-Paws/no-animal-violence-pre-commit.git

no-animal-violence-check src/utils.py docs/README.md

Exit code 0 = clean. Exit code 1 = one or more violations found.

Documentation

Ecosystem

This hook is one layer in a multi-tool detection suite. Each tool targets a different enforcement point:

Tool Enforcement point
no-animal-violence-pre-commit ← you are here Local git commit
no-animal-violence-action GitHub Actions CI
reviewdog-no-animal-violence PR inline annotations
eslint-plugin-no-animal-violence JS/TS editor + lint
vale-no-animal-violence Prose / docs
vscode-no-animal-violence VS Code extension
danger-plugin-no-animal-violence Danger.js PR checks

Architecture

Implementation details

The hook is a single Python file (no_animal_violence_check.py) with no runtime dependencies beyond the standard library.

Pattern structure: Each entry in PATTERNS is a (regex_string, alternative_string) tuple. All patterns are compiled once at module load time into COMPILED using re.IGNORECASE.

Execution flow:

  1. pre-commit calls the no-animal-violence-check console script with a list of staged filenames as arguments.
  2. main() iterates over each filename and calls check_file().
  3. check_file() opens the file in UTF-8 mode (with error replacement for binary content), iterates line-by-line, and runs all compiled regexes via finditer.
  4. Findings are collected as (filepath, line_number, matched_text, alternative) tuples.
  5. If any findings exist, they are printed to stdout and the process exits with code 1, blocking the commit.

Pattern source: Patterns are auto-generated from project-compassionate-code and derived from the no-animal-violence canonical dictionary. The pattern list in this repo is currently maintained as a copy (a known DRY limitation tracked for future resolution). Pattern changes must be applied consistently in both repos until automatic sync is implemented.

Python requirement: 3.8+. The hook is registered in .pre-commit-hooks.yaml with language: python and types: [text].

Code Quality

Contributing

Contributions are welcome — especially new patterns. The most useful additions are phrases that appear in real codebases and have clear, professionally neutral alternatives.

  1. Fork the repository and create a feature branch.
  2. Patterns live in the PATTERNS list in no_animal_violence_check.py. Each entry is a (regex, alternative) tuple.
  3. Run the test suite:
    python -m pytest tests/
  4. Verify the hook end-to-end:
    pre-commit try-repo . no-animal-violence --all-files
  5. Open a parallel PR in no-animal-violence if adding a new phrase to the canonical dictionary.
  6. Use movement-standard language in alternatives: "farmed animals" not "livestock", "slaughterhouse" not "processing facility".

License

MIT — see LICENSE. Copyright (c) 2026 Open Paws.

Acknowledgments

Pattern dictionary maintained by the Open Paws community. This hook is auto-generated from project-compassionate-code, which submits animal-friendly PRs to open-source repositories at scale.


Donate · Discord · openpaws.ai · Volunteer


About

Pre-commit hook for detecting animal violence language

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages