Skip to content

Commit cd400a2

Browse files
authored
[tools] Misc improvements to the autoformat script. (#23713)
1 parent a244845 commit cd400a2

File tree

2 files changed

+65
-47
lines changed

2 files changed

+65
-47
lines changed

src/rgen/Microsoft.Macios.Generator/IO/TabbedWriter.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public TabbedWriter<T> WriteLine (ref DefaultInterpolatedStringHandler handler)
178178
Writer.WriteLine (handler.ToStringAndClear ());
179179
return this;
180180
}
181-
181+
182182
/// <summary>
183183
/// Append a new raw literal by prepending the correct indentation.
184184
/// </summary>
@@ -188,24 +188,22 @@ public TabbedWriter<T> WriteRaw (string rawString)
188188
{
189189
// we will split the raw string in lines and then append them so that the
190190
// tabbing is correct
191-
var lines = rawString.AsSpan().Split('\n');
192-
var enumerator = lines.GetEnumerator();
193-
bool hasNext = enumerator.MoveNext();
194-
while (hasNext)
195-
{
191+
var lines = rawString.AsSpan ().Split ('\n');
192+
var enumerator = lines.GetEnumerator ();
193+
bool hasNext = enumerator.MoveNext ();
194+
while (hasNext) {
196195
var range = enumerator.Current;
197-
var line = rawString.AsSpan(range);
198-
hasNext = enumerator.MoveNext();
199-
if (!hasNext)
200-
{
196+
var line = rawString.AsSpan (range);
197+
hasNext = enumerator.MoveNext ();
198+
if (!hasNext) {
201199
Write (line);
202200
break;
203201
}
204202
WriteLine (line);
205203
}
206204
return this;
207205
}
208-
206+
209207
#else
210208
/// <summary>
211209
/// Append a new raw literal by prepending the correct indentation.

tools/autoformat.sh

Lines changed: 56 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -ex
1+
#!/bin/bash -e
22

33
# Go to the top level directory
44
cd "$(git rev-parse --show-toplevel)"
@@ -23,6 +23,7 @@ IFS=$'\n'
2323
SED=(sed -i)
2424
fi
2525

26+
echo 'Changing "== null" and "!= null" to "is null" and "is not null"...'
2627
for file in $(git ls-files -- '*.cs' ':(exclude)tests/monotouch-test/Foundation/UrlTest.cs' ':(exclude)tests/monotouch-test/AVFoundation/AVAudioFormatTest.cs'); do
2728
if [[ -L "$file" ]]; then
2829
echo "Skipping $file because it's a symlink"
@@ -33,44 +34,63 @@ IFS=$'\n'
3334
done
3435
)
3536

36-
# Go one directory up, to avoid any global.json in xamarin-macios
37+
# Go one directory up, to avoid any global.json in dotnet/macios
3738
cd ..
3839

40+
if test -z "${DOTNET:-}"; then
41+
DOTNET=dotnet
42+
fi
43+
44+
function af_whitespace ()
45+
{
46+
echo "Processing $1..."
47+
$DOTNET format whitespace "$1"
48+
}
49+
3950
# Start formatting!
40-
dotnet format whitespace "$SRC_DIR/tests/cecil-tests/cecil-tests.csproj"
41-
dotnet format whitespace "$SRC_DIR/tests/dotnet/UnitTests/DotNetUnitTests.csproj"
42-
dotnet format whitespace "$SRC_DIR/msbuild/Messaging/Xamarin.Messaging.Build/Xamarin.Messaging.Build.csproj"
43-
dotnet format whitespace "$SRC_DIR/msbuild/Xamarin.Localization.MSBuild/Xamarin.Localization.MSBuild.csproj"
44-
dotnet format whitespace "$SRC_DIR/msbuild/Xamarin.MacDev.Tasks/Xamarin.MacDev.Tasks.csproj"
45-
dotnet format whitespace "$SRC_DIR/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Tasks.Windows.csproj"
46-
dotnet format whitespace "$SRC_DIR/src/bgen/bgen.csproj"
47-
dotnet format whitespace "$SRC_DIR/tools/dotnet-linker/dotnet-linker.csproj"
48-
dotnet format whitespace "$SRC_DIR/tools/mmp/mmp.csproj"
49-
dotnet format whitespace "$SRC_DIR/tools/mtouch/mtouch.csproj"
50-
dotnet format whitespace "$SRC_DIR/tests/xharness/xharness.sln"
51-
dotnet format whitespace "$SRC_DIR/tests/introspection/dotnet/iOS/introspection.csproj"
52-
dotnet format whitespace "$SRC_DIR/tests/introspection/dotnet/MacCatalyst/introspection.csproj"
53-
dotnet format whitespace "$SRC_DIR/tests/introspection/dotnet/macOS/introspection.csproj"
54-
dotnet format whitespace "$SRC_DIR/tests/introspection/dotnet/tvOS/introspection.csproj"
55-
dotnet format whitespace "$SRC_DIR/tests/monotouch-test/dotnet/iOS/monotouch-test.csproj"
56-
dotnet format whitespace "$SRC_DIR/tests/monotouch-test/dotnet/MacCatalyst/monotouch-test.csproj"
57-
dotnet format whitespace "$SRC_DIR/tests/monotouch-test/dotnet/macOS/monotouch-test.csproj"
58-
dotnet format whitespace "$SRC_DIR/tests/monotouch-test/dotnet/tvOS/monotouch-test.csproj"
59-
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-sharpie/xtro-sharpie.csproj"
60-
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/u2ignore/u2ignore.csproj"
61-
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/u2todo/u2todo.csproj"
62-
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-report/xtro-report.csproj"
63-
dotnet format whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-sanity/xtro-sanity.csproj"
64-
dotnet format whitespace "$SRC_DIR/tools/api-tools/mono-api-html/mono-api-html.csproj"
65-
dotnet format whitespace "$SRC_DIR/tools/api-tools/mono-api-info/mono-api-info.csproj"
66-
dotnet format whitespace "$SRC_DIR/tests/common/MonoTouch.Dialog/MonoTouch.Dialog.iOS.csproj"
67-
dotnet format whitespace "$SRC_DIR/tests/common/MonoTouch.Dialog/MonoTouch.Dialog.MacCatalyst.csproj"
68-
dotnet format whitespace "$SRC_DIR/tests/common/MonoTouch.Dialog/MonoTouch.Dialog.tvOS.csproj"
69-
dotnet format whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.iOS.csproj"
70-
dotnet format whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.MacCatalyst.csproj"
71-
dotnet format whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.macOS.csproj"
72-
dotnet format whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.tvOS.csproj"
73-
dotnet format whitespace --folder "$SRC_DIR"
51+
af_whitespace "$SRC_DIR/tests/cecil-tests/cecil-tests.csproj"
52+
af_whitespace "$SRC_DIR/tests/dotnet/UnitTests/DotNetUnitTests.csproj"
53+
af_whitespace "$SRC_DIR/msbuild/Messaging/Xamarin.Messaging.Build/Xamarin.Messaging.Build.csproj"
54+
af_whitespace "$SRC_DIR/msbuild/Xamarin.Localization.MSBuild/Xamarin.Localization.MSBuild.csproj"
55+
af_whitespace "$SRC_DIR/msbuild/Xamarin.MacDev.Tasks/Xamarin.MacDev.Tasks.csproj"
56+
af_whitespace "$SRC_DIR/msbuild/Xamarin.iOS.Tasks.Windows/Xamarin.iOS.Tasks.Windows.csproj"
57+
af_whitespace "$SRC_DIR/src/bgen/bgen.csproj"
58+
af_whitespace "$SRC_DIR/src/rgen/Microsoft.Macios.Binding.Common/Microsoft.Macios.Binding.Common.csproj"
59+
af_whitespace "$SRC_DIR/src/rgen/Microsoft.Macios.Bindings.Analyzer.Sample/Microsoft.Macios.Bindings.Analyzer.Sample.csproj"
60+
af_whitespace "$SRC_DIR/src/rgen/Microsoft.Macios.Bindings.Analyzer/Microsoft.Macios.Bindings.Analyzer.csproj"
61+
af_whitespace "$SRC_DIR/src/rgen/Microsoft.Macios.Bindings.CodeFixers/Microsoft.Macios.Bindings.CodeFixers.csproj"
62+
af_whitespace "$SRC_DIR/src/rgen/Microsoft.Macios.Generator.Sample/Microsoft.Macios.Generator.Sample.csproj"
63+
af_whitespace "$SRC_DIR/src/rgen/Microsoft.Macios.Generator/Microsoft.Macios.Generator.csproj"
64+
af_whitespace "$SRC_DIR/src/rgen/Microsoft.Macios.Transformer/Microsoft.Macios.Transformer.csproj"
65+
af_whitespace "$SRC_DIR/tools/dotnet-linker/dotnet-linker.csproj"
66+
af_whitespace "$SRC_DIR/tools/mmp/mmp.csproj"
67+
af_whitespace "$SRC_DIR/tools/mtouch/mtouch.csproj"
68+
af_whitespace "$SRC_DIR/tests/xharness/xharness.sln"
69+
af_whitespace "$SRC_DIR/tests/introspection/dotnet/iOS/introspection.csproj"
70+
af_whitespace "$SRC_DIR/tests/introspection/dotnet/MacCatalyst/introspection.csproj"
71+
af_whitespace "$SRC_DIR/tests/introspection/dotnet/macOS/introspection.csproj"
72+
af_whitespace "$SRC_DIR/tests/introspection/dotnet/tvOS/introspection.csproj"
73+
af_whitespace "$SRC_DIR/tests/monotouch-test/dotnet/iOS/monotouch-test.csproj"
74+
af_whitespace "$SRC_DIR/tests/monotouch-test/dotnet/MacCatalyst/monotouch-test.csproj"
75+
af_whitespace "$SRC_DIR/tests/monotouch-test/dotnet/macOS/monotouch-test.csproj"
76+
af_whitespace "$SRC_DIR/tests/monotouch-test/dotnet/tvOS/monotouch-test.csproj"
77+
af_whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-sharpie/xtro-sharpie.csproj"
78+
af_whitespace "$SRC_DIR/tests/xtro-sharpie/u2ignore/u2ignore.csproj"
79+
af_whitespace "$SRC_DIR/tests/xtro-sharpie/u2todo/u2todo.csproj"
80+
af_whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-report/xtro-report.csproj"
81+
af_whitespace "$SRC_DIR/tests/xtro-sharpie/xtro-sanity/xtro-sanity.csproj"
82+
af_whitespace "$SRC_DIR/tools/api-tools/mono-api-html/mono-api-html.csproj"
83+
af_whitespace "$SRC_DIR/tools/api-tools/mono-api-info/mono-api-info.csproj"
84+
af_whitespace "$SRC_DIR/tests/common/MonoTouch.Dialog/MonoTouch.Dialog.iOS.csproj"
85+
af_whitespace "$SRC_DIR/tests/common/MonoTouch.Dialog/MonoTouch.Dialog.MacCatalyst.csproj"
86+
af_whitespace "$SRC_DIR/tests/common/MonoTouch.Dialog/MonoTouch.Dialog.tvOS.csproj"
87+
af_whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.iOS.csproj"
88+
af_whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.MacCatalyst.csproj"
89+
af_whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.macOS.csproj"
90+
af_whitespace "$SRC_DIR/tests/common/Touch.Unit/Touch.Client/dotnet/Touch.Client.tvOS.csproj"
91+
92+
echo "Processing $SRC_DIR..."
93+
$DOTNET format whitespace --folder "$SRC_DIR"
7494

7595
for file in "$SRC_DIR"/dotnet/Templates/Microsoft.*.Templates/*/*/.template.config/localize/*.json "$SRC_DIR"/dotnet/Templates/Microsoft.*.Templates/*/.template.config/localize/*.json; do
7696
tr -d $'\r' < "$file" > "$file".tmp

0 commit comments

Comments
 (0)