dart_husky 1.2.0 copy "dart_husky: ^1.2.0" to clipboard
dart_husky: ^1.2.0 copied to clipboard

A pure-Dart CLI tool to manage Git hooks (pre-commit, commit-msg, pre-push) in any Dart or Flutter project. Similar to husky and lefthook.

dart_husky

dart_husky #

Git hook manager for Dart & Flutter — no binaries, no fuss.

pub version pub points license dart

Pure Dart. Zero external dependencies. Works with Flutter, FVM, or bare Dart SDK.
Inspired by husky and lefthook.


Why dart_husky? #

Most git hook tools require installing a separate binary (Go, Node.js, etc.). dart_husky is pure Dart — if your team has Dart, they have everything they need.

✦ Pure Dart — no Go, no Node, no extra installs
✦ YAML config — familiar, readable, version-controlled
✦ Built-in conventional commits validation
✦ Sequential or parallel command execution
✦ Staged-only mode — run commands on staged files only
✦ Glob filtering — skip commands when no matching files are staged
✦ Works with dart, flutter, and fvm
✦ Lowercase enforcement — optionally force lowercase commit messages

Installation #

Add to your pubspec.yaml:

dev_dependencies:
  dart_husky: ^1.2.0

Install dependencies and set up hooks:

dart pub get
dart run dart_husky install

That's it. Your hooks are live.


Configuration #

Create dart_husky.yaml in your project root:

dart_husky:
  verbose: true       # print detailed output (default: true)
  staged_only: false  # run on staged files only (default: false)

pre-commit:
  commands:
    format:
      run: dart format --set-exit-if-changed .
    analyze:
      run: dart analyze

commit-msg:
  commands:
    conventional:
      preset: conventional

Supported Hooks #

Hook Triggered when...
pre-commit Before a commit is created
commit-msg After you write a commit message
pre-push Before pushing to remote
post-checkout After switching branches
pre-merge-commit Before a merge commit

Commands #

# Install hooks defined in dart_husky.yaml
dart run dart_husky install

# Remove all installed hooks
dart run dart_husky uninstall

# Manually trigger a hook
dart run dart_husky run pre-commit

# List configured hooks and install status
dart run dart_husky list

Conventional Commits #

Enable built-in conventional commits validation with one line:

commit-msg:
  commands:
    conventional:
      preset: conventional

Valid format:

<type>(<optional scope>): <subject>
Type When to use
feat A new feature
fix A bug fix
chore Maintenance, deps, tooling
docs Documentation only
style Formatting, whitespace
refactor Code change, no feature or fix
test Adding or fixing tests
build Build system changes
ci CI configuration
perf Performance improvement
revert Revert a previous commit

Examples:

git commit -m "feat(auth): add login screen"         ✅
git commit -m "fix: resolve null pointer exception"  ✅
git commit -m "feat!: breaking api change"           ✅
git commit -m "updated stuff"                        ❌

Custom Commit Types #

Append custom types on top of the built-in list:

commit-msg:
  commands:
    conventional:
      preset: conventional
      types:
        append: [wip, release]

Or completely override the built-in types:

commit-msg:
  commands:
    conventional:
      preset: conventional
      types:
        override: [feat, fix, hotfix, release]

Lowercase Enforcement #

Force all commit messages to be lowercase (default: true):

commit-msg:
  commands:
    conventional:
      preset: conventional
      only_small_case: true  # default

To allow mixed case:

commit-msg:
  commands:
    conventional:
      preset: conventional
      only_small_case: false

Applies to any preset, not just conventional commits.

Staged-Only Mode #

Run commands only on staged files instead of the entire project. Faster hooks for large codebases.

Enable globally for all commands:

dart_husky:
  staged_only: true

pre-commit:
  commands:
    format:
      run: dart format --set-exit-if-changed .
    analyze:
      run: dart analyze
    test:
      run: dart test
      staged_only: false  # override — always run full test suite

Command-level staged_only always overrides the global setting. If no staged files are found, the command is skipped automatically.


Glob Filtering #

Skip commands entirely when no staged files match a pattern:

pre-commit:
  commands:
    format:
      run: dart format --set-exit-if-changed .
      glob: '**/*.dart'   # skip if no .dart files are staged
    analyze:
      run: dart analyze
      glob: '**/*.dart'

If you only staged README.md, both format and analyze are skipped — no unnecessary work.


Parallel Execution #

Speed up slow hooks by running commands simultaneously:

pre-commit:
  parallel: true
  commands:
    format:
      run: dart format --set-exit-if-changed .
    analyze:
      run: dart analyze
    test:
      run: dart test

How It Works #

you run: git commit
         └── git checks .git/hooks/pre-commit
                  └── dart run dart_husky run pre-commit
                           └── reads dart_husky.yaml
                                    └── runs each command
                                             ├── all pass → commit created ✅
                                             └── any fail → commit blocked ❌

dart_husky install writes a small shell script into .git/hooks/ for each configured hook. The script detects whether to use dart or fvm dart automatically.


Contributing #

Contributions are welcome! Please make sure your commits follow the conventional commits format — dart_husky will enforce it. 😄


Made with 🎯 by @moulibheemaneti
MIT License

1
likes
160
points
--
downloads

Documentation

API reference

Publisher

verified publishermoulibheemaneti.com

A pure-Dart CLI tool to manage Git hooks (pre-commit, commit-msg, pre-push) in any Dart or Flutter project. Similar to husky and lefthook.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

args, glob, path, yaml

More

Packages that depend on dart_husky