-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The pre-commit framework allows users to run MegaLinter locally as a Git pre-commit hook. While it does have built-in support for Node.js hooks, it doesn't support monorepos, because the package.json must be in the root directory. While it does have built-in support for Docker hooks, the user experience of overriding arguments to mega-linter-runner is nicer than that for the Docker image. Hence, hand-roll system hooks instead, and leverage npx to execute (and, if necessary, download) mega-linter-runner.
- Loading branch information
1 parent
d43b202
commit 2bfcdaa
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
- id: megalinter | ||
name: Run MegaLinter on files modified relative to DEFAULT_BRANCH | ||
entry: npx -- | ||
language: system | ||
pass_filenames: false | ||
args: | ||
- mega-linter-runner | ||
- --fix | ||
- --env | ||
- "'APPLY_FIXES=all'" | ||
- --env | ||
- "'FAIL_IF_UPDATED_SOURCES=true'" | ||
- --env | ||
- "'LOG_LEVEL=warning'" | ||
- --env | ||
- "'VALIDATE_ALL_CODEBASE=false'" | ||
- --env | ||
- "'DISABLE_LINTERS=COPYPASTE_JSCPD'" | ||
stages: | ||
- commit | ||
description: > | ||
See https://megalinter.github.io/latest/mega-linter-runner/#usage and | ||
https://megalinter.github.io/latest/configuration/ if you wish to override | ||
the default arguments. mega-linter-runner is specified as an argument so | ||
that you may override the version (e.g., [email protected]). Depends | ||
on npx, which ships with npm 7+, and Docker. Unlike most pre-commit hooks, | ||
MegaLinter itself computes the files to run on. Runs very slowly when the | ||
pertinent Docker image isn't already cached (c.f., | ||
https://github.com/marketplace/actions/docker-cache/). If you encounter | ||
permission errors, try running Docker in rootless mode (c.f., | ||
https://github.com/marketplace/actions/rootless-docker/). Linter results are | ||
logged to the report directory, so you should make sure to list it in your | ||
.gitignore and wipe it between runs. Skip jscpd since duplicate detection | ||
fundamentally requires scanning the entire repository and hence can't be | ||
performed incrementally. | ||
- id: megalinter-all | ||
name: Run MegaLinter on all files | ||
entry: npx -- | ||
language: system | ||
pass_filenames: false | ||
args: | ||
- mega-linter-runner | ||
- --fix | ||
- --env | ||
- "'APPLY_FIXES=all'" | ||
- --env | ||
- "'FAIL_IF_UPDATED_SOURCES=true'" | ||
- --env | ||
- "'LOG_LEVEL=warning'" | ||
- --env | ||
- "'VALIDATE_ALL_CODEBASE=true'" | ||
stages: | ||
- push | ||
description: > | ||
See https://megalinter.github.io/latest/mega-linter-runner/#usage and | ||
https://megalinter.github.io/latest/configuration/ if you wish to override | ||
the default arguments. mega-linter-runner is specified as an argument so | ||
that you may override the version (e.g., [email protected]). Depends | ||
on npx, which ships with npm 7+, and Docker. Runs very slowly when the | ||
pertinent Docker image isn't already cached (c.f., | ||
https://github.com/marketplace/actions/docker-cache/). If you encounter | ||
permission errors, try running Docker in rootless mode (c.f., | ||
https://github.com/marketplace/actions/rootless-docker/). Linter results are | ||
logged to the report directory, so you should make sure to list it in your | ||
.gitignore and wipe it between runs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters