Discuss.FOLIO.org is no longer used. This is a static snapshot of the website as of February 14, 2023.

Should the coding guidelines be enforced using pre-commit hooks

jensheinrich
27 Dec '21

There is a set of coding guidelines, but the repositories as far as I could see, do not yet include pre-commit hooks.
This would be a very easy and useful addition as the pre-commit hooks shown here can enforce the use of the .editorconfig settings and linters and formatters.
There is also an hook to remove trailing whitespace like defined in the guidelines.

The automation of these removes the need for developers to remember to do so and leaves more ressources for relevant work.
Setting up linters and formatters also enables a strict enforcement of the coding guidelines on the CI level.

I also created a Task for Jira already, if this is deemed a good idea by you:

*Purpose/Overview:* Add a system to enforce the [Coding Guidelines|https://dev.folio.org/guidelines/contributing/#coding-style]

*Requirements/Scope:*
 # Declare styling conventions for all tools
 # Choose linter/formatters for each language
 # Add an `.editorconfig` file and language specific linter settings to all repositories
 # Enforce conventions in [pre-commit hooks|https://pre-commit.com/]

*Approach:*
 * Add global style settings (whitespace etc) via editorconfig
 ** Enforce removal of trailing whitespace using [trailing-whitespace hook|https://github.com/pre-commit/pre-commit-hooks]
 ** Enforce matching editorconfig settings using an [editorconfig-precommit-hook|https://github.com/editorconfig-checker/editorconfig-checker.python]
 * Add default styles for languages where there has not been chosen a special style
 ** eg. the one suggested by [ansible-lint|https://ansible-lint.readthedocs.io/en/latest/rules.html] for the [folio-ansible|https://github.com/folio-org/folio-ansible] repository

 * Add checks for formatters to CI

*Acceptance criteria:*
 * All repositories have defined linter and settings
 * CI fails on incorrectly formatted code
julianladisch
11 Apr '22

FOLIO uses other ways to enforce the rules.

FOLIO Developers | Guides | Code analysis and linting facilities explains the code analysis and linting facilities run by Jenkins.

Some back-end modules run checkstyle during their maven compile phase: okapi/pom.xml at v4.13.2 · folio-org/okapi · GitHub

Some front-end modules use GitHub Actions to run yarn lint when a pull request is opened or a commit is merged: ui-checkout/build-npm.yml at v8.0.1 · folio-org/ui-checkout · GitHub

To “Declare styling conventions for all tools” and “Choose linter/formatters for each language” the #development Slack channel might be a better place because developers usually communicate via Slack rather than discuss.folio.org.