Have all checks run:
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_unused_variable
- id: ansible_role_find_empty_files
- id: ansible_role_find_empty_directories
- id: ansible_role_fix_readability
- id: ansible_role_find_undefined_handlers
- id: ansible_role_find_unquoted_values
- id: ansible_role_find_horizontal_when
You can also select single checks, read further for more details.
This pre-commit hook can help you find defined variables (in defaults/main.yml
or vars/main.yml
) that are not used in the role.
Expand (or create) your .pre-commit-config.yml
with this section:
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_unused_variable
This hook can find empty defaults/main.yml
, handlers/main.yml
and vars/main.yml
files.
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_empty_files
Extra parameter available:
-l <number>
: number of minimum lines to declare that a file is empty (by default: 2)
This hook can find empty directories.
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_empty_directory
Extra parameter available:
-d <number>
: number of sub folder (maxdepth) to check (by default: 1)
This hook can improve readability.
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_fix_readability
This hook can find undefined handlers.
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_undefined_handlers
Know bug:
- doesn't detect notification in "listener".
- doesn't work if notify have quote an not name of the handler task (or the opposite).
This hook can find unquoted values.
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_unquoted_values
This hook can find when statements that can be spread vertically.
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_horizontal_when
It is possible to change the folder where the check is made. To do that, add extra parameters:
repos:
- repo: https://github.com/robertdebock/pre-commit
rev: v1.5.3
hooks:
- id: ansible_role_find_horizontal_when
args: [-f roles/*]