Skip to content

Commit 44c021c

Browse files
fix: Format files (MAPCO-8614) (#13)
* Format files * Add new line at the end of file * Use solution styles instead of Built in rider * Set warp long lines to false * pass only the solution * Remove retduntent pass * Make sure the .sln is in git * Add sln * Add csproj * path to root * specify csproj * change to sln * include yahalom.csproj * find and clean up the code files * change to actual solution * Revert yaml * Removed trailing * Finds all .csproj files * use dotnet format * specify yahalom * Modify yaml * Revert "Modify yaml" This reverts commit 9e9f71c. * Add editorconfig * Revert "Add editorconfig" This reverts commit 0622404. * modify yaml * Change to home directory to avoid project file conflicts * modify yyaml * modify yaml * modify yaml * use CSharpier * update csharpierignore * Revert "update csharpierignore" This reverts commit 24d2960. * Revert "use CSharpier" This reverts commit e6e00de. * modify yaml * fix yaml * fix yaml again * Change to a temp directory to avoid project file conflicts * test formatting * revert test * modify yaml to use DotSettings * EDIT YAML * MODIFY YAML * Revert "MODIFY YAML" This reverts commit 75fa01f. * Add editor config * Revert "Add editor config" This reverts commit a7b9acb. * add new line at the end of file * new line at end of file * Revert "add new line at the end of file" This reverts commit 6a76d2c. * run jb cleanupcode locally * Add editor config file * remove commented lines * Enforce type isntead of var * preserve single line * Change hard warp settings * fix style * test one line property * revert test
1 parent 95dc74a commit 44c021c

29 files changed

+5642
-141
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
csharp_style_var_for_built_in_types = false:suggestion
10+
csharp_style_var_when_type_is_apparent = false:suggestion
11+
csharp_style_var_elsewhere = false:suggestion
12+
dotnet_diagnostic.IDE0008.severity = error
13+
dotnet_diagnostic.IDE0007.severity = silent
14+
15+
csharp_preserve_single_line_statements = false
16+
csharp_preserve_single_line_blocks = false
17+
max_line_length = 999

.github/workflows/format.yaml

Lines changed: 63 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,91 @@
1-
name: Format
1+
name: format_check
22

33
on:
44
workflow_call:
55

66
jobs:
77
format_check:
8-
name: Verify Rider formatting
98
runs-on: ubuntu-latest
9+
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
1315

1416
- name: Setup .NET
1517
uses: actions/setup-dotnet@v4
1618
with:
17-
dotnet-version: '8.0.x'
19+
dotnet-version: 8.0.x
1820

1921
- name: Install JetBrains ReSharper Global Tools (jb)
22+
shell: bash
2023
run: |
24+
set -euo pipefail
25+
cd /tmp
2126
dotnet tool install --global JetBrains.ReSharper.GlobalTools
2227
echo "$HOME/.dotnet/tools" >> "$GITHUB_PATH"
2328
24-
- name: Run Rider cleanup (dry-check via diff)
29+
- name: Discover all solutions
30+
id: discover
31+
shell: bash
2532
run: |
26-
jb cleanupcode \
27-
--profile="Built-in: Reformat Code" \
28-
--no-build \
29-
--verbosity=WARN \
30-
--include="**/*.cs" \
31-
--exclude="**/bin/**" \
32-
--exclude="**/obj/**" \
33-
--exclude="**/.idea/**" \
34-
.
33+
set -euo pipefail
34+
git ls-files '*.sln' > solutions.txt || true
35+
echo "Found solution files:"
36+
cat solutions.txt || true
37+
count=$(wc -l < solutions.txt | tr -d ' ')
38+
echo "solution_count=$count" >> "$GITHUB_OUTPUT"
3539
36-
- name: Detect formatting changes (code files only)
37-
id: diff
40+
- name: Check formatting
41+
if: steps.discover.outputs.solution_count != '0'
42+
shell: bash
3843
run: |
39-
LIST_FILE="$RUNNER_TEMP/files_needing_format.txt"
40-
CHANGED="$(git status --porcelain --untracked-files=no -- '*.cs' '*.csproj' '*.sln' | awk '{print $2}' | sort -u)"
41-
if [[ -n "$CHANGED" ]]; then
42-
echo "changed=true" >> "$GITHUB_OUTPUT"
43-
echo "$CHANGED" | tee "$LIST_FILE"
44-
echo "list_file=$LIST_FILE" >> "$GITHUB_OUTPUT"
45-
else
46-
echo "changed=false" >> "$GITHUB_OUTPUT"
47-
echo "list_file=" >> "$GITHUB_OUTPUT"
48-
fi
44+
set -euo pipefail
45+
while IFS= read -r sln; do
46+
[ -z "$sln" ] && continue
47+
echo "==> Restoring $sln"
48+
dotnet restore "$sln"
4949
50-
- name: Summarize unformatted files
51-
if: steps.diff.outputs.changed == 'true'
52-
run: |
53-
{
54-
echo "### ❌ Formatting check failed"
55-
echo
56-
echo "The following code files are not formatted properly:"
57-
echo
58-
echo '```'
59-
cat "${{ steps.diff.outputs.list_file }}"
60-
echo '```'
61-
echo
62-
echo "➡️ Run Rider **Code Cleanup** (Built-in: *Reformat Code*) locally and commit."
63-
} >> "$GITHUB_STEP_SUMMARY"
50+
echo "==> Running jb cleanupcode"
51+
jb cleanupcode "$sln" \
52+
--profile="Built-in: Reformat Code" \
53+
--no-build \
54+
--verbosity=WARN \
55+
--include="Assets/**/*.cs" \
56+
--exclude="**/bin/**" \
57+
--exclude="**/obj/**" \
58+
--exclude="**/.idea/**" \
59+
--exclude="**/Library/**" \
60+
--exclude="**/Logs/**" \
61+
--exclude="**/Temp/**"
62+
done < solutions.txt
6463
65-
- name: Annotate files in Checks UI
66-
if: steps.diff.outputs.changed == 'true'
64+
- name: Diff & annotate unformatted files (fail if any)
65+
if: steps.discover.outputs.solution_count != '0'
66+
shell: bash
6767
run: |
68-
while IFS= read -r f; do
69-
echo "::error file=$f,title=Not formatted::Run Rider Code Cleanup (Built-in: Reformat Code) and commit."
70-
done < "${{ steps.diff.outputs.list_file }}"
68+
set -euo pipefail
69+
DIFF_FILE=cleanup.diff
70+
git --no-pager diff --unified=0 -- 'Assets/**/*.cs' > "$DIFF_FILE" || true
7171
72-
- name: Revert any changes (always clean workspace)
73-
if: always()
74-
run: |
75-
git restore --staged .
76-
git checkout -- .
77-
git clean -fd
72+
if [ -s "$DIFF_FILE" ]; then
73+
echo "Unformatted changes detected in Assets/:"
74+
awk '
75+
BEGIN { file="" }
76+
/^\+\+\+ b\// { sub(/^\+\+\+ b\//, "", $0); file=$0; next }
77+
/^@@ / {
78+
match($0, /\+([0-9]+)(,([0-9]+))?/, m)
79+
start = m[1]
80+
printf("::error file=%s,line=%d,title=Formatting differs::Run Rider Code Cleanup (or jb cleanupcode) locally and commit.\n", file, start)
81+
}
82+
' "$DIFF_FILE"
83+
echo "::error title=Formatting check failed::Some files under Assets/ differ from the configured formatting."
84+
exit 1
85+
else
86+
echo "Formatting is clean in Assets/."
87+
fi
7888
79-
- name: Fail job if formatting needed
80-
if: steps.diff.outputs.changed == 'true'
81-
run: exit 1
89+
- name: No solutions found (informative)
90+
if: steps.discover.outputs.solution_count == '0'
91+
run: echo "No .sln files found; skipping formatting check."

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
# Autogenerated VS/MD/Consulo solution and project files
4646
ExportedObj/
4747
.consulo/
48-
*.csproj
4948
*.unityproj
50-
*.sln
5149
*.suo
5250
*.tmp
5351
*.user

.idea/.idea.yahalom/.idea/codeStyles/Project.xml

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.yahalom/.idea/workspace.xml

Lines changed: 105 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)