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

Add pre-commit hooks #5

Merged
merged 3 commits into from
Apr 15, 2024
Merged

Add pre-commit hooks #5

merged 3 commits into from
Apr 15, 2024

Conversation

DaniilKl
Copy link
Contributor

@DaniilKl DaniilKl commented Apr 12, 2024

Add pre-commit hooks to simplify reviewing and code maintaining. The hooks have been automatically configured using 3mdeb/hooks repository and its pre-commit-init.py script.

Signed-off-by: Daniil Klimuk <[email protected]>
@DaniilKl DaniilKl requested a review from macpijan April 12, 2024 13:02
@DaniilKl DaniilKl self-assigned this Apr 12, 2024
@DaniilKl
Copy link
Contributor Author

Verification logs:

check for added large files..............................................Passed
check for merge conflicts................................................Passed
check for broken symlinks............................(no files to check)Skipped
detect private key.......................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
mixed line ending........................................................Passed
codespell................................................................Passed
yamllint.................................................................Failed
- hook id: yamllint
- exit code: 1

.pre-commit-config.yaml
  51:8      error    too many spaces after hyphen  (hyphens)
  51:5      error    wrong indentation: expected 6 but found 4  (indentation)

markdownlint.........................................(no files to check)Skipped
markdownlint-fix.....................................(no files to check)Skipped
ShellCheck v0.9.0....................................(no files to check)Skipped

So, it works and even detected some spells.

@DaniilKl DaniilKl linked an issue Apr 12, 2024 that may be closed by this pull request
@macpijan
Copy link
Contributor

ShellCheck v0.9.0....................................(no files to check)Skipped

We have some shell files, and I would expect many failures there. Not that we have to fix them right now, but why these are not checked?

markdownlint.........................................(no files to check)Skipped

We have README.md , at least?

@DaniilKl DaniilKl marked this pull request as draft April 12, 2024 14:28
Reason: ignore "variable appears unsued" beacause scripts in this
directory are being sourced by other scripts in the repo, and,
therefore, so not use self declared variables.

Solutions I have also tried:
- adding "# shellcheck source=../include/dts-functions.sh" and "# shellcheck
  source=../include/dts-environment.sh" to all scripts under path
  ./scripts/;
- adding "# shellcheck source=SCRIPTDIR/../include/dts-functions.sh" and "#
  shellcheck source=SCRIPTDIR/../include/dts-environment.sh" to all scripts
  under path ./scripts/;
- adding "source-path=./include" and "source-path=SCRIPTDIR/../include" to
  ".shellcheckrc" as well as via command line arguments and comments in shell
  scriptfiles;
- mixing above solutions in different ways;

All above solutions did not work.

References:
https://www.shellcheck.net/wiki/Directive
https://www.shellcheck.net/wiki/SC2034
https://www.shellcheck.net/wiki/SC1090
https://pre-commit.com/#config-args

Signed-off-by: Daniil Klimuk <[email protected]>
@DaniilKl
Copy link
Contributor Author

@macpijan, my bad, thanks for noticing. After fixes added in 433483c and 478de5a:

λ pre-commit run -a
check for added large files..............................................Passed
check for merge conflicts................................................Passed
check for broken symlinks............................(no files to check)Skipped
detect private key.......................................................Passed
fix end of files.........................................................Passed
trim trailing whitespace.................................................Passed
mixed line ending........................................................Passed
codespell................................................................Passed
yamllint.................................................................Passed
markdownlint.............................................................Passed
markdownlint-fix.........................................................Passed
ShellCheck v0.9.0........................................................Passed

@DaniilKl DaniilKl marked this pull request as ready for review April 15, 2024 08:41
scripts/dasharo-deploy Outdated Show resolved Hide resolved
@macpijan
Copy link
Contributor

@DaniilKl I said there is no need to fix all of the shellcheck errors here, but I am very glad you did.

For list of pre-commit warnings checkout:
https://www.shellcheck.net/wiki/

Signed-off-by: Daniil Klimuk <[email protected]>
@macpijan macpijan merged commit aa2f0a9 into main Apr 15, 2024
@macpijan macpijan deleted the add-pre-commit branch April 15, 2024 13:32
@tlaurion
Copy link

@DaniilKl a little description would not hurt, even after merging

@macpijan
Copy link
Contributor

@tlaurion description of what exactly?

@tlaurion
Copy link

tlaurion commented Apr 15, 2024

@tlaurion description of what exactly?

This PR description : tools enabled why and how.

You can discard, but PR description can be searched globally. I took personal notes of this because Pre-commit hooks are amazing for linting, typos and syntax validation prior of commit, which limits the number of unneeded commits fixing things ad-hoc under unneeded additional commits.

Anyway, thanks for this. This is good example for the rest of the ecosystem and I'll try to replicate in my own projects.

@macpijan
Copy link
Contributor

macpijan commented Apr 15, 2024

@tlaurion Oh, got it.

We have a templates and script for putting up a set of tools and configs in a new repo: https://github.com/3mdeb/hooks/blob/main/pre-commit-init/pre-commit-init.py#L60

Feel free to try to use it and submit issues if not clear.

We have selected specific tools and rules we like for specific types of files, and we aim to adopt the same rules across the board.

So we could in fact add in the MR description @DaniilKl that this was added using this script.

@DaniilKl
Copy link
Contributor Author

@tlaurion, good idea. @macpijan, done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement pre-commit in DTS repo
3 participants