Skip to content

Commit

Permalink
[src] Add optional StyleCop validation. (#22208)
Browse files Browse the repository at this point in the history
This makes it easy to reformat code using StyleCop!

I'll start enabling rules in separate PRs.
  • Loading branch information
rolfbjarne authored Feb 20, 2025
1 parent 50be5f0 commit 2b415aa
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
<NoWarn>$(NoWarn.Replace('CA1416','').Replace('CA1422',''))</NoWarn>
</PropertyGroup>
</Target>
<PropertyGroup Condition="'$(EnableStyleCop)' == 'true'">
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)/stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup Condition="'$(EnableStyleCop)' == 'true'">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,14 @@ analyze:
echo "Analyzed $$csproj successfully."; \
done

# This target builds the generated project files with StyleCop enabled.
stylecop-csproj: $(CSPROJECTS) $(foreach platform,$(DOTNET_PLATFORMS),$($(shell echo $(platform) | tr '[:lower:]' '[:upper:]')_DOTNET_PLATFORM_ASSEMBLY_DEPENDENCIES))
$(Q) set -e; \
for csproj in $(CSPROJECTS); do \
echo "Building $$csproj with StyleCop enabled..."; \
$(DOTNET) build $$csproj $(DOTNET_BUILD_VERBOSITY) /p:EnableStyleCop=true; \
echo "Built $$csproj with StyleCop successfully."; \
done

csproj:: $(CSPROJECTS)
ALL_TARGETS += $(CSPROJECTS)
Expand Down
Loading

6 comments on commit 2b415aa

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

@vs-mobiletools-engineering-service2

This comment was marked as outdated.

Please sign in to comment.