Set up pre-commit-validation

The fastest way to validate code changes for linting issues, conventional commits messages and potential secrets in the code is by using the OneCX generator. Some projects have their own generator based on the OneCX generator. It should be clarified before starting if this is the case for the project the app is generated for.

To run the generator, execute the following command:

nx generate <namespaceOfTheGenerator>/nx-plugin:pre-commit-validation
  • <namespaceOfTheGenerator>: For the OneCX generator, use @onecx. For a project specific generator, ask for the namespace of the generators.

Next, the CLI will ask if you want to enable validation checks with three questions: Lint-check, Conventional Commits message check and scanning for blacklisted words in the code. For each check, you can choose "yes" or "no".

If "yes" is selected, the CLI installs the necessary dependencies if not already present - husky (used for all checks), lint-staged for linting, commitlint for Conventional Commits check and detect-secrets for blacklist-scanning.

The blacklist file used for the blacklist scanning should be in the users home directory (~/blacklist.txt).

The required configuration files for the enabled validation checks will be generated and the enabled checks are automatically performed before the changes can be committed.