Skip to content

Commit 8c260ed

Browse files
committed
IMPROVEMENT: add more pre-commit hooks and SetupDeveloperPC.* scripts
This makes it easier for newer developers to start developing code ASAP.
1 parent 45baf1f commit 8c260ed

File tree

4 files changed

+270
-1
lines changed

4 files changed

+270
-1
lines changed

.pre-commit-config.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-executables-have-shebangs
11+
- id: check-shebang-scripts-are-executable
12+
- id: check-illegal-windows-names
13+
- id: check-json
14+
- id: check-toml
15+
- id: check-yaml
16+
217
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.8.0
18+
rev: v0.8.3
419
hooks:
520
- id: ruff
621
args: [ --fix ]

SetupDeveloperPC.bat

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
@echo off
2+
setlocal enabledelayedexpansion
3+
4+
:: Store the original directory
5+
set "ORIGINAL_DIR=%CD%"
6+
7+
:: Change to the directory where the script resides
8+
cd /d %~dp0
9+
10+
set "targetPath=%USERPROFILE%\AppData\Roaming\Python\Python312\Scripts"
11+
set "found=0"
12+
13+
:: Iterate over each entry in PATH
14+
for %%A in ("%PATH:;=" "%") do (
15+
if /i "%%~A"=="!targetPath!" (
16+
set "found=1"
17+
echo The path is already included in the PATH.
18+
goto :checkDone
19+
)
20+
)
21+
22+
if "!found!"=="0" (
23+
rem The target path is not in the PATH, so we will append it
24+
echo Appending "!targetPath!" to the PATH...
25+
setx PATH "%PATH%;!targetPath!"
26+
rem Update the current session PATH variable
27+
set "PATH=%PATH%;!targetPath!"
28+
)
29+
30+
:checkDone
31+
32+
call :ConfigureGit
33+
call :ConfigureVSCode
34+
call :ConfigurePreCommit
35+
36+
echo running pre-commit checks on all Files
37+
pre-commit run -a
38+
39+
:: Change back to the original directory
40+
cd /d %ORIGINAL_DIR%
41+
42+
echo Script completed successfully.
43+
exit /b
44+
45+
:ConfigureGit
46+
echo Configuring Git settings...
47+
git config --local commit.gpgsign true
48+
git config --local diff.tool meld
49+
git config --local diff.astextplain.textconv astextplain
50+
git config --local merge.tool meld
51+
git config --local difftool.prompt false
52+
git config --local mergetool.prompt false
53+
git config --local mergetool.meld.cmd "meld \"$LOCAL\" \"$MERGED\" \"$REMOTE\" --output \"$MERGED\""
54+
git config --local core.autocrlf false
55+
git config --local core.fscache true
56+
git config --local core.symlinks false
57+
git config --local core.editor "code"
58+
git config --local alias.graph1 "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
59+
git config --local alias.graph2 "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all"
60+
git config --local alias.graph "!git graph1"
61+
git config --local alias.co checkout
62+
git config --local alias.st status
63+
git config --local alias.cm "commit -m"
64+
git config --local alias.pom "push origin master"
65+
git config --local alias.aa "add --all"
66+
git config --local alias.df diff
67+
git config --local alias.su "submodule update --init --recursive"
68+
git config --local credential.helper manager
69+
git config --local pull.rebase true
70+
git config --local push.autoSetupRemote
71+
git config --local init.defaultbranch master
72+
git config --local sequence.editor "code --wait"
73+
echo Git configuration applied successfully.
74+
goto :eof
75+
76+
:ConfigurePreCommit
77+
echo Installing pre-commit tools into the Ubuntu running inside WSL2...
78+
wsl --exec bash -c "./wsl_install.bash"
79+
echo Setting pre-commit...
80+
pip3 install pre-commit
81+
pre-commit install
82+
echo Pre-commit done.
83+
goto :eof
84+
85+
:ConfigureVSCode
86+
:: Check for VSCode installation and install extensions
87+
echo Checking for VSCode...
88+
where code >nul
89+
IF %ERRORLEVEL% NEQ 0 (
90+
echo VSCode is not installed. Please install VSCode before running this script.
91+
pause
92+
exit /b
93+
) ELSE (
94+
echo Installing the markdownlint VSCode extension...
95+
cmd /c code --install-extension davidanson.vscode-markdownlint
96+
IF %ERRORLEVEL% NEQ 0 (
97+
echo Failed to install markdownlint extension.
98+
pause
99+
exit /b
100+
)
101+
echo Installing the Markdown Preview Enhanced extension...
102+
cmd /c code --install-extension shd101wyy.markdown-preview-enhanced
103+
IF %ERRORLEVEL% NEQ 0 (
104+
echo Failed to install Markdown Preview Enhanced extension.
105+
pause
106+
exit /b
107+
)
108+
109+
echo Installing GitHub Copilot...
110+
cmd /c code --install-extension GitHub.copilot
111+
IF %ERRORLEVEL% NEQ 0 (
112+
echo Failed to install GitHub Copilot extension.
113+
pause
114+
exit /b
115+
)
116+
117+
echo Installing the Conventional Commits VSCode extension...
118+
cmd /c code --install-extension vivaxy.vscode-conventional-commits
119+
IF %ERRORLEVEL% NEQ 0 (
120+
echo Failed to install Conventional Commits VSCode extension.
121+
pause
122+
exit /b
123+
)
124+
125+
echo Installing the GitLens VSCode extension...
126+
cmd /c code --install-extension eamodio.gitlens
127+
IF %ERRORLEVEL% NEQ 0 (
128+
echo Failed to install GitLens VSCode extension.
129+
pause
130+
exit /b
131+
)
132+
133+
)
134+
goto :eof

SetupDeveloperPC.sh

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
3+
# Store the original directory
4+
ORIGINAL_DIR=$(pwd)
5+
6+
# Change to the directory where the script resides
7+
cd "$(dirname "$0")" || exit
8+
9+
ConfigureGit() {
10+
echo "Configuring Git settings..."
11+
git config --local commit.gpgsign true
12+
git config --local diff.tool meld
13+
git config --local diff.astextplain.textconv astextplain
14+
git config --local merge.tool meld
15+
git config --local difftool.prompt false
16+
git config --local mergetool.prompt false
17+
git config --local mergetool.meld.cmd "meld \"\$LOCAL\" \"\$MERGED\" \"\$REMOTE\" --output \"\$MERGED\""
18+
git config --local core.autocrlf false
19+
git config --local core.fscache true
20+
git config --local core.symlinks false
21+
git config --local core.editor "code"
22+
git config --local alias.graph1 "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
23+
git config --local alias.graph2 "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all"
24+
git config --local alias.graph "!git graph1"
25+
git config --local alias.co checkout
26+
git config --local alias.st status
27+
git config --local alias.cm "commit -m"
28+
git config --local alias.pom "push origin master"
29+
git config --local alias.aa "add --all"
30+
git config --local alias.df diff
31+
git config --local alias.su "submodule update --init --recursive"
32+
git config --local credential.helper manager
33+
git config --local pull.rebase true
34+
git config --local push.autoSetupRemote
35+
git config --local init.defaultbranch master
36+
git config --local sequence.editor "code --wait"
37+
echo Git configuration applied successfully.
38+
}
39+
40+
ConfigurePreCommit() {
41+
echo Setting pre-commit...
42+
echo "Checking for pip..."
43+
if ! command -v pip &> /dev/null; then
44+
echo "pip is not installed. Please install pip before running this script."
45+
exit 1
46+
fi
47+
pip install pre-commit
48+
pre-commit install
49+
echo Pre-commit done.
50+
}
51+
52+
ConfigureVSCode() {
53+
# Check for VSCode installation
54+
echo "Checking for VSCode..."
55+
if ! command -v code &> /dev/null; then
56+
echo "VSCode is not installed. Please install VSCode before running this script."
57+
exit 1
58+
else
59+
echo "Installing the markdownlint VSCode extension..."
60+
if ! code --install-extension davidanson.vscode-markdownlint; then
61+
echo "Failed to install markdownlint extension."
62+
exit 1
63+
fi
64+
65+
echo "Installing the Markdown Preview Enhanced extension..."
66+
if ! code --install-extension shd101wyy.markdown-preview-enhanced; then
67+
echo "Failed to install Markdown Preview Enhanced extension."
68+
exit 1
69+
fi
70+
71+
echo "Installing GitHub Copilot..."
72+
if ! code --install-extension GitHub.copilot; then
73+
echo "Failed to install GitHub Copilot extension."
74+
exit 1
75+
fi
76+
77+
echo "Installing the Conventional Commits VSCode extension..."
78+
if ! code --install-extension vivaxy.vscode-conventional-commits; then
79+
echo "Failed to install Conventional Commits VSCode extension."
80+
exit 1
81+
fi
82+
83+
echo "Installing the GitLens VSCode extension..."
84+
if ! code --install-extension eamodio.gitlens; then
85+
echo "Failed to install GitLens VSCode extension."
86+
exit 1
87+
fi
88+
89+
fi
90+
}
91+
92+
# Call configuration functions
93+
ConfigureGit
94+
ConfigureVSCode
95+
ConfigurePreCommit
96+
97+
# Run pre-commit
98+
echo "running pre-commit checks on all Files"
99+
pre-commit run -a
100+
101+
# Change back to the original directory
102+
cd "$ORIGINAL_DIR" || exit
103+
104+
echo "Script completed successfully."
105+
exit 0

wsl_install.bash

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
# This script should run in a ubuntu 22.04 or newer running inside WSL2 on a Windows PC
4+
# It configures the WSL2 virtual machine to run the linters required in the project
5+
#
6+
# This script is automatically called from the SetupDeveloperPC.bat and should not be called directly
7+
8+
sudo apt-get update
9+
10+
sudo apt install unzip shellcheck
11+
12+
npm install --global [email protected]
13+
14+
shellcheck --version
15+
npm list -g markdown-link-check

0 commit comments

Comments
 (0)