Skip to content

Commit

Permalink
Add Verify Code Formatting to CI Pipeline (#101)
Browse files Browse the repository at this point in the history
* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* `dotnet format`

* Update `.editorconfig` to match `CommunityToolkit.Maui`

* `dotnet format`

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* `dotnet format`
  • Loading branch information
TheCodeTraveler authored Aug 5, 2022
1 parent d9c49e2 commit 10916e1
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 66 deletions.
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,8 @@ dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_symbols.static_fields.applicable_accessibilities = internal, private, protected, protected_internal, private_protected

dotnet_naming_style.static_field_style.capitalization = camel_case
dotnet_naming_style.static_field_style.required_prefix =
dotnet_naming_style.static_field_style.required_prefix =

# Modifier preferences
csharp_prefer_static_local_function = true:suggestion
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:error
36 changes: 32 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ variables:
NugetPackageVersion: '$(CurrentSemanticVersion)'
NET_VERSION: '6.0.x'
RunPoliCheck: false
PathToSolution: 'src/CommunityToolkit.Maui.Markup.sln'
PathToLibrarySolution: 'src/CommunityToolkit.Maui.Markup.sln'
PathToSamplesSolution: 'samples/CommunityToolkit.Maui.Markup.Sample.sln'
PathToCommunityToolkitCsproj: 'src/CommunityToolkit.Maui.Markup/CommunityToolkit.Maui.Markup.csproj'
PathToCommunityToolkitSampleCsproj: 'samples/CommunityToolkit.Maui.Markup.Sample/CommunityToolkit.Maui.Markup.Sample.csproj'
PathToCommunityToolkitUnitTestCsproj: 'src/CommunityToolkit.Maui.Markup.UnitTests/CommunityToolkit.Maui.Markup.UnitTests.csproj'
Expand Down Expand Up @@ -118,10 +119,10 @@ jobs:

# check vulnerabilities
- powershell: |
dotnet list $(PathToSolution) package --vulnerable --include-transitive | findstr /S /c:"has the following vulnerable packages";
dotnet list $(PathToLibrarySolution) package --vulnerable --include-transitive | findstr /S /c:"has the following vulnerable packages";
if ($LastExitCode -ne 1)
{
dotnet list $(PathToSolution) package --vulnerable --include-transitive;
dotnet list $(PathToLibrarySolution) package --vulnerable --include-transitive;
exit 1;
}
Expand Down Expand Up @@ -157,6 +158,33 @@ jobs:
artifactName: nuget
pathToPublish: '$(Build.ArtifactStagingDirectory)'

- job: verify_formatting_windows
displayName: Verify Code Formatting on Windows
pool:
vmImage: windows-latest
steps:
- task: UseDotNet@2
displayName: 'Install Latest .NET SDK'
inputs:
packageType: 'sdk'
version: '$(NET_VERSION)'

- powershell: dotnet workload install maui
displayName: Install Latest .NET MAUI Workload

- task: Bash@3
displayName: 'Verify Formatting'
env:
PathToSamplesSolution: $(PathToSamplesSolution)
inputs:
targetType: 'inline'
script: |
dotnet format $PathToSamplesSolution --verify-no-changes --exclude-diagnostics CA1416
status=$?
[ $status -eq 0 ] && echo "No errors found"
[ $status -ne 0 ] && echo "Formatting errors found. In the Windows Command Line, please run \`dotnet format $PathToSamplesSolution\`, then commit + push the newly formatted code"
exit $status
- job: build_macos
displayName: Build macOS Library
pool:
Expand Down Expand Up @@ -209,4 +237,4 @@ jobs:
- task: CmdLine@2
displayName: 'Pack CommunityToolkit NuGets'
inputs:
script: 'dotnet pack -c Release $(PathToCommunityToolkitCsproj) -p:PackageVersion=$(NugetPackageVersion) --output $(Build.ArtifactStagingDirectory)/nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg'
script: 'dotnet pack -c Release $(PathToCommunityToolkitCsproj) -p:PackageVersion=$(NugetPackageVersion) --output $(Build.ArtifactStagingDirectory)/nuget -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg'
2 changes: 1 addition & 1 deletion samples/CommunityToolkit.Maui.Markup.Sample/AppShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CommunityToolkit.Maui.Markup.Sample;

class AppShell : Shell
{
readonly static IReadOnlyDictionary<Type, string> pageRouteMappingDictionary = new Dictionary<Type, string>(new[]
static readonly IReadOnlyDictionary<Type, string> pageRouteMappingDictionary = new Dictionary<Type, string>(new[]
{
CreateRoutePageMapping<NewsPage, NewsViewModel>(),
CreateRoutePageMapping<SettingsPage, SettingsViewModel>(),
Expand Down
24 changes: 12 additions & 12 deletions samples/CommunityToolkit.Maui.Markup.Sample/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ public static MauiApp CreateMauiApp()
var builder = MauiApp.CreateBuilder()
.UseMauiApp<App>()
.UseMauiCommunityToolkit()
.UseMauiCommunityToolkitMarkup();

// Fonts
builder.ConfigureFonts(fonts => fonts.AddFont("FontAwesome.otf", "FontAwesome"));

// App Shell
builder.Services.AddTransient<AppShell>();

// Services
.UseMauiCommunityToolkitMarkup();

// Fonts
builder.ConfigureFonts(fonts => fonts.AddFont("FontAwesome.otf", "FontAwesome"));

// App Shell
builder.Services.AddTransient<AppShell>();

// Services
builder.Services.AddSingleton<App>();
builder.Services.AddSingleton(Browser.Default);
builder.Services.AddSingleton<SettingsService>();
builder.Services.AddSingleton(Preferences.Default);
builder.Services.AddSingleton<HackerNewsAPIService>();
builder.Services.AddSingleton(RestService.For<IHackerNewsApi>("https://hacker-news.firebaseio.com/v0"));

// Pages + View Models
builder.Services.AddSingleton(RestService.For<IHackerNewsApi>("https://hacker-news.firebaseio.com/v0"));

// Pages + View Models
builder.Services.AddTransient<NewsPage, NewsViewModel>();
builder.Services.AddTransient<SettingsPage, SettingsViewModel>();
builder.Services.AddTransient<NewsDetailPage, NewsDetailViewModel>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace CommunityToolkit.Maui.Markup.UnitTests.Mocks;
// Inspired by https://github.com/dotnet/maui/blob/main/src/Core/tests/UnitTests/TestClasses/DispatcherStub.cs
sealed class MockDispatcherProvider : IDispatcherProvider, IDisposable
{
readonly static DispatcherMock dispatcherMock = new();
static readonly DispatcherMock dispatcherMock = new();

readonly ThreadLocal<IDispatcher> dispatcherInstance = new(() => dispatcherMock);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using Microsoft.Maui.Controls.Internals;

namespace CommunityToolkit.Maui.Markup;

namespace CommunityToolkit.Maui.Markup;

/// <summary>
/// Extension Methods for IDynamicResourceHandler
/// </summary>
public static class DynamicResourceHandlerExtensions
{
{
/// <summary>
/// Set Dynamic Resource
/// </summary>
Expand All @@ -21,8 +21,8 @@ public static TDynamicResourceHandler DynamicResource<TDynamicResourceHandler>(t
dynamicResourceHandler.SetDynamicResource(property, key);

return dynamicResourceHandler;
}

}

/// <summary>
/// Set Dynamic Resource
/// </summary>
Expand Down
14 changes: 7 additions & 7 deletions src/CommunityToolkit.Maui.Markup/ImageExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace CommunityToolkit.Maui.Markup;

namespace CommunityToolkit.Maui.Markup;

/// <summary>
/// Extension methods for IImage
/// </summary>
public static class ImageExtensions
{
{
/// <summary>
/// Sets the <see cref="IImageSourcePart.Source" /> Property/>
/// </summary>
Expand All @@ -16,8 +16,8 @@ public static TBindable Source<TBindable>(this TBindable bindable, ImageSource?
{
bindable.SetValue(ImageElement.SourceProperty, imageSource);
return bindable;
}

}

/// <summary>
/// Sets the <see cref="Microsoft.Maui.IImage.Aspect" /> Property/>
/// </summary>
Expand All @@ -29,8 +29,8 @@ public static TBindable Aspect<TBindable>(this TBindable bindable, Aspect aspect
{
bindable.SetValue(ImageElement.AspectProperty, aspect);
return bindable;
}

}

/// <summary>
/// Sets the <see cref="Microsoft.Maui.IImage.IsOpaque" /> Property/>
/// </summary>
Expand Down
50 changes: 25 additions & 25 deletions src/CommunityToolkit.Maui.Markup/ItemsViewExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System.Collections;
using System.Windows.Input;

namespace CommunityToolkit.Maui.Markup;

namespace CommunityToolkit.Maui.Markup;

/// <summary>
/// Fluent extension methods for <see cref="ItemsView"/>
/// </summary>
public static class ItemsViewExtensions
{
{
/// <summary>
/// Assigns the <see cref="ItemsView.EmptyView"/> property
/// </summary>
Expand All @@ -19,8 +19,8 @@ public static TItemsView EmptyView<TItemsView>(this TItemsView itemsView, object
{
itemsView.EmptyView = view;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.EmptyViewTemplate"/> property
/// </summary>
Expand All @@ -32,8 +32,8 @@ public static TItemsView EmptyViewTemplate<TItemsView>(this TItemsView itemsView
{
itemsView.EmptyViewTemplate = view;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.ItemsSource"/> property
/// </summary>
Expand All @@ -45,8 +45,8 @@ public static TItemsView ItemsSource<TItemsView>(this TItemsView itemsView, IEnu
{
itemsView.ItemsSource = itemsSource;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.HorizontalScrollBarVisibility"/> property
/// </summary>
Expand All @@ -58,8 +58,8 @@ public static TItemsView HorizontalScrollBarVisibility<TItemsView>(this TItemsVi
{
itemsView.HorizontalScrollBarVisibility = visibility;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.VerticalScrollBarVisibility"/> property
/// </summary>
Expand All @@ -71,8 +71,8 @@ public static TItemsView VerticalScrollBarVisibility<TItemsView>(this TItemsView
{
itemsView.VerticalScrollBarVisibility = visibility;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.VerticalScrollBarVisibility"/> and <see cref="ItemsView.HorizontalScrollBarVisibility"/> properties
/// </summary>
Expand All @@ -83,8 +83,8 @@ public static TItemsView VerticalScrollBarVisibility<TItemsView>(this TItemsView
public static TItemsView ScrollBarVisibility<TItemsView>(this TItemsView itemsView, ScrollBarVisibility visibility) where TItemsView : ItemsView
{
return itemsView.HorizontalScrollBarVisibility(visibility).VerticalScrollBarVisibility(visibility);
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.RemainingItemsThreshold"/> property
/// </summary>
Expand All @@ -96,8 +96,8 @@ public static TItemsView RemainingItemsThreshold<TItemsView>(this TItemsView ite
{
itemsView.RemainingItemsThreshold = threshold;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.RemainingItemsThresholdReachedCommand"/> ans <see cref="ItemsView.RemainingItemsThresholdReachedCommandParameter"/>properties
/// </summary>
Expand All @@ -109,8 +109,8 @@ public static TItemsView RemainingItemsThreshold<TItemsView>(this TItemsView ite
public static TItemsView RemainingItemsThresholdReachedCommand<TItemsView>(this TItemsView itemsView, ICommand command, object? parameter) where TItemsView : ItemsView
{
return itemsView.RemainingItemsThresholdReachedCommand(command).RemainingItemsThresholdReachedCommandParameter(parameter);
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.RemainingItemsThresholdReachedCommand"/> property
/// </summary>
Expand All @@ -122,8 +122,8 @@ public static TItemsView RemainingItemsThresholdReachedCommand<TItemsView>(this
{
itemsView.RemainingItemsThresholdReachedCommand = command;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.RemainingItemsThresholdReachedCommandParameter"/> property
/// </summary>
Expand All @@ -135,8 +135,8 @@ public static TItemsView RemainingItemsThresholdReachedCommandParameter<TItemsVi
{
itemsView.RemainingItemsThresholdReachedCommandParameter = parameter;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.ItemTemplate"/> property
/// </summary>
Expand All @@ -148,8 +148,8 @@ public static TItemsView ItemTemplate<TItemsView>(this TItemsView itemsView, Dat
{
itemsView.ItemTemplate = template;
return itemsView;
}

}

/// <summary>
/// Assigns the <see cref="ItemsView.ItemsUpdatingScrollMode"/> property
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/CommunityToolkit.Maui.Markup/LabelExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace CommunityToolkit.Maui.Markup;

namespace CommunityToolkit.Maui.Markup;

/// <summary>
/// Extension Methods for Label
/// </summary>
public static class LabelExtensions
{
{
/// <summary>
/// Sets Formatted Text
/// </summary>
Expand Down
14 changes: 7 additions & 7 deletions src/CommunityToolkit.Maui.Markup/PlaceholderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace CommunityToolkit.Maui.Markup;

namespace CommunityToolkit.Maui.Markup;

/// <summary>
/// Extension Methods for <see cref="IPlaceholder"/>
/// </summary>
public static class PlaceholderExtensions
{
{
/// <summary>
/// Sets the <see cref="IPlaceholder.PlaceholderColor"/> Property
/// </summary>
Expand All @@ -16,8 +16,8 @@ public static TBindable PlaceholderColor<TBindable>(this TBindable bindable, Col
{
bindable.SetValue(PlaceholderElement.PlaceholderColorProperty, textColor);
return bindable;
}

}

/// <summary>
/// Sets the <see cref="IPlaceholder.Placeholder" /> Property/>
/// </summary>
Expand All @@ -29,8 +29,8 @@ public static TBindable Placeholder<TBindable>(this TBindable bindable, string?
{
bindable.SetValue(PlaceholderElement.PlaceholderProperty, text);
return bindable;
}

}

/// <summary>
/// Sets the <see cref="IPlaceholder.Placeholder" /> and <see cref="IPlaceholder.PlaceholderColor" /> Properties/>
/// </summary>
Expand Down

0 comments on commit 10916e1

Please sign in to comment.