Pre-commit Hooks
The Bash Tools Framework provides pre-commit hooks to ensure code quality and consistency before changes are committed
to your repository. These hooks are defined in the .pre-commit-hooks.yaml file and can be easily integrated into your
development workflow using the pre-commit tool.
1. Available Hooks
1.1. fixShebangExecutionBit
This hook finds all files containing a shebang and marks them as executable if they are not already.
1.2. frameworkLint
This hook checks if your files use the correct syntax for using the bash-tools-framework.
1.3. awkLint
This hook lints awk files using awk.
1.4. shellcheckLint
This hook lints bash files using shellcheck. It automatically installs the latest version of shellcheck if it’s not already available.
1.5. runUnitTests
Internal hook used in the framework to run unit tests using bats in a Docker isolated environment. It ensures that your code is tested in a consistent environment before being committed.
1.6. plantuml
This hook generates Plantuml diagrams from .puml files. It uses the bin/plantuml script, which can be configured to
run in CI mode, generate images in the same directory as the source files, and specify output formats. It uses the
latest plantuml docker image and uses it to generate diagrams. It also detects added files in CI mode to only generate
diagrams for new files.
1.7. mermaid
This hook generates Mermaid diagrams from .mmd files. It uses the bin/mermaid script, which can be configured to run
in CI mode, generate images in the same directory as the source files, and specify output formats. It uses the latest
mermaid binary using npx and uses it to generate diagrams. It also detects added files in CI mode to only generate
diagrams for new files.
1.8. megalinterCheckVersion
This hook checks if a new version of megalinter is available. It uses the bin/megalinter script with the
--check-megalinter-version option to check for updates.
1.9. megalinter
This hook runs megalinter for comprehensive code quality checks. It uses the bin/megalinter script, which can be
configured to specify the megalinter image, configuration file, and whether to automatically fix issues.
1.10. hugoUpdateLastmod
This hook updates the lastmod and version fields in Hugo frontmatter based on git modification dates or the current
date.
2. Usage
To use these hooks, simply add the desired hooks to your .pre-commit-config.yaml file. For example:
default_install_hook_types: [pre-commit, pre-push]
default_stages: [pre-commit, manual]
minimum_pre_commit_version: 3.5.0
repos:
- repo: https://github.com/fchastanet/bash-tools-framework
rev: 6.2.6
hooks:
- id: fixShebangExecutionBit
- id: awkLint
- id: shellcheckLint
- id: plantuml
args: [--same-dir, -f, png, -f, svg, --limit-size, '1200']
- id: hugoUpdateLastmod