Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ jobs:
run: |
# workaround for https://github.com/actions/runner/issues/2033
git config --global --add safe.directory '*'
- name: fantomless
run: |
dotnet tool install fantomless-tool --version 4.7.997-prerelease
dotnet fantomless --recurse .
git diff --exit-code || (echo "Formatting did not match (see above diff), please run fantomless-tool" >&2 && exit 1)

- name: Install commitlint&prettier's required dependencies
run: |
Expand All @@ -262,15 +257,17 @@ jobs:
- name: Install prettier
run: npm install --verbose

- name: Run "prettier" to check the style of our TypeScript and YML code
- name: Run formatting tools to check the style of our F#&TypeScript&YML code
run: |
sudo npm run format

# Since we changed file modes in the previous step we need the following command to
# make git ignore mode changes in files and doesn't include them in the git diff command.
git config core.fileMode false
# Since after installing commitlint dependencies package.json file changes, we need to
# run the following command to ignore package.json file
git restore package.json

git diff --exit-code || (echo "Formatting did not match (see above diff), please run 'npm run format'" >&2 && exit 1)

- name: Validate current commit (last commit) with commitlint
Expand Down
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

format:
npm run format
dnx --yes fantomless-tool --recurse .
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"husky": "^9.0.0"
},
"scripts": {
"format": "(npx --no-install prettier --version || (echo '\nPlease install `prettier` via `npm install` first; if this problem persists, try `npm rebuild && npm install`' >&2 && exit 1)) && npx --no-install prettier --quote-props=consistent --write './**/*.{yml,ts}'",
"format:check": "(npx --no-install prettier --version || (echo '\nPlease install `prettier` via `npm install` first; if this problem persists, try `npm rebuild && npm install`' >&2 && exit 1)) && npx --no-install prettier --quote-props=consistent --check './**/*.{yml,ts}'",
"format": "bash ./scripts/format.sh --write",
"format:check": "bash ./scripts/format.sh --check",
"test": "vitest --globals=true",
"prepare": "husky"
}
Expand Down
27 changes: 27 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash
set -euo pipefail

if [ "$#" -ne 1 ]; then
echo "Usage: $0 --check|--write" >&2
exit 1
fi

if [ "$1" != "--check" ] && [ "$1" != "--write" ]; then
echo "Usage: $0 --check|--write" >&2
exit 1
fi

which dotnet || (echo '\nPlease install .NET SDK v10.x or newer' >&2 && exit 1)

which npx || (echo '\nPlease install `npx`, maybe installing NPM?' >&2 && exit 1)

npx --no-install prettier --version || (echo '\nPlease install `prettier` via `npm install` first; if this problem persists, try `npm rebuild` or `git clean -fdx` before `npm install`' >&2 && exit 1)

npx --no-install prettier "$@" --quote-props=consistent './**/*.{yml,ts}'

FANTOMLESS_CALL="dotnet dnx --yes --version 4.7.997-prerelease fantomless-tool --recurse ."
if [ "$1" = "--check" ]; then
$FANTOMLESS_CALL --check
else
$FANTOMLESS_CALL
fi
13 changes: 1 addition & 12 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@
set -euo pipefail

echo "Running pre-commit format checks..."

echo "Running prettier format check..."
if ! npm run format:check > /dev/null 2>&1; then
echo ""
echo "❌ Prettier check failed. Please run 'make format' to fix formatting issues, then stage the changes and try committing again."
npm run format:check
exit 1
fi

echo "Running fantomless format check..."
if ! dnx fantomless-tool --check --recurse . > /dev/null 2>&1; then
echo ""
echo "❌ Fantomless check failed. Please run 'make format' to fix formatting issues, then stage the changes and try committing again."
dnx --yes fantomless-tool --check --recurse .
echo "❌ Formatting check failed. Please run 'make format' to fix formatting issues, then stage the changes and try committing again."
exit 1
fi

Expand Down
Loading