Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pre-commit Hooks for v6 #1755

Closed
Kurt-von-Laven opened this issue Aug 17, 2022 · 0 comments · Fixed by #1756
Closed

Update pre-commit Hooks for v6 #1755

Kurt-von-Laven opened this issue Aug 17, 2022 · 0 comments · Fixed by #1756
Assignees
Labels
enhancement New feature or request

Comments

@Kurt-von-Laven
Copy link
Collaborator

Is your feature request related to a problem? Please describe.
Many great new features have landed in v6, so we should update the pre-commit hooks, which were added in v5, to take advantage of them. This will significantly improve the performance of the hooks.

Describe the solution you'd like
Currently we have a megalinter hook that runs on the files modified relative to DEFAULT_BRANCH (skipping jscpd for the sake of performance) and a megalinter-all hook that runs on all files. We should replace these with a megalinter-incremental hook that runs on the modified files passed by pre-commit but skips linters that run in project mode and a megalinter-full hook that runs on the same files without skipping project mode linters, respectively.

Describe alternatives you've considered
We could keep the hook names the same in the name of backwards compatibility, but (a) they wouldn't do the same thing as the old hooks anyways, and (b) the name megalinter-all would give the deceptive impression that the hook always runs on all files.

Additional context
We can also take this opportunity to leverage the new CLEAR_REPORT_FOLDER, --containername, and --remove-container options, which are so useful that they should be the defaults when running locally via the pre-commit hooks.

@Kurt-von-Laven Kurt-von-Laven added the enhancement New feature or request label Aug 17, 2022
@Kurt-von-Laven Kurt-von-Laven self-assigned this Aug 17, 2022
Kurt-von-Laven added a commit that referenced this issue Aug 17, 2022
Replace the v5 megalinter hook with a v6 megalinter-incremental hook
that only runs on the modified files, skipping all linters that run in
project mode. Replace the v5 megalinter-all hook with a v6
megalinter-full hook that runs only on the modified files when
supported, but also runs linters that run in project mode. This brings
MegaLinter's pre-commit hooks more in line with typical hooks, which run
on the files passed by pre-commit rather than running git diff
themselves.

Leverage new v6 features to automatically clean up the Docker container
and megalinter-reports directory, and give a meaningful name to the
Docker container rather than one randomly generated by Docker. Update
documentation to reflect that the report directory was renamed
megalinter-reports in v6.

Remove FAIL_IF_UPDATED_SOURCES=true since pre-commit hooks already fail
when the hook modifies files, and this setting causes MegaLinter to fail
whenever there are unstaged changes. Stop limiting the hooks to specific
stages. The ability to run MegaLinter on specific files while still
running all project linters is a significant performance improvement
over running all linters on all files, so some users may wish to run the
new megalinter-full hook pre-commit, not just pre-push. Conversely, some
users may find the performance of megalinter-full prohibitive to run
locally and prefer to only run megalinter-incremental pre-push.
nvuillam pushed a commit that referenced this issue Aug 17, 2022
Replace the v5 megalinter hook with a v6 megalinter-incremental hook
that only runs on the modified files, skipping all linters that run in
project mode. Replace the v5 megalinter-all hook with a v6
megalinter-full hook that runs only on the modified files when
supported, but also runs linters that run in project mode. This brings
MegaLinter's pre-commit hooks more in line with typical hooks, which run
on the files passed by pre-commit rather than running git diff
themselves.

Leverage new v6 features to automatically clean up the Docker container
and megalinter-reports directory, and give a meaningful name to the
Docker container rather than one randomly generated by Docker. Update
documentation to reflect that the report directory was renamed
megalinter-reports in v6.

Remove FAIL_IF_UPDATED_SOURCES=true since pre-commit hooks already fail
when the hook modifies files, and this setting causes MegaLinter to fail
whenever there are unstaged changes. Stop limiting the hooks to specific
stages. The ability to run MegaLinter on specific files while still
running all project linters is a significant performance improvement
over running all linters on all files, so some users may wish to run the
new megalinter-full hook pre-commit, not just pre-push. Conversely, some
users may find the performance of megalinter-full prohibitive to run
locally and prefer to only run megalinter-incremental pre-push.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant