1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 05:15:37 +08:00

Merge pull request #18065 from huoyaoyuan/code-style

Enforce code style analysis shipped with .NET SDK
This commit is contained in:
Dean Herbert 2022-05-07 14:58:19 +09:00 committed by GitHub
commit dd63657dfb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 243 additions and 111 deletions

View File

@ -2,12 +2,6 @@
"version": 1,
"isRoot": true,
"tools": {
"dotnet-format": {
"version": "3.1.37601",
"commands": [
"dotnet-format"
]
},
"jetbrains.resharper.globaltools": {
"version": "2022.1.0-eap10",
"commands": [

View File

@ -1,6 +1,14 @@
# EditorConfig is awesome: http://editorconfig.org
root = true
[*.{csproj,props,targets}]
charset = utf-8-bom
end_of_line = crlf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
[*.cs]
end_of_line = crlf
insert_final_newline = true
@ -8,8 +16,19 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true
#license header
file_header_template = Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.\nSee the LICENCE file in the repository root for full licence text.
#Roslyn naming styles
#PascalCase for public and protected members
dotnet_naming_style.pascalcase.capitalization = pascal_case
dotnet_naming_symbols.public_members.applicable_accessibilities = public,internal,protected,protected_internal,private_protected
dotnet_naming_symbols.public_members.applicable_kinds = property,method,field,event
dotnet_naming_rule.public_members_pascalcase.severity = error
dotnet_naming_rule.public_members_pascalcase.symbols = public_members
dotnet_naming_rule.public_members_pascalcase.style = pascalcase
#camelCase for private members
dotnet_naming_style.camelcase.capitalization = camel_case
@ -172,24 +191,11 @@ csharp_style_prefer_index_operator = false:silent
csharp_style_prefer_range_operator = false:silent
csharp_style_prefer_switch_expression = false:none
#Supressing roslyn built-in analyzers
# Suppress: EC112
#Private method is unused
dotnet_diagnostic.IDE0051.severity = silent
#Private member is unused
dotnet_diagnostic.IDE0052.severity = silent
#Rules for disposable
dotnet_diagnostic.IDE0067.severity = none
dotnet_diagnostic.IDE0068.severity = none
dotnet_diagnostic.IDE0069.severity = none
#Disable operator overloads requiring alternate named methods
dotnet_diagnostic.CA2225.severity = none
# Banned APIs
dotnet_diagnostic.RS0030.severity = error
[*.{yaml,yml}]
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
dotnet_diagnostic.OLOC001.words_in_name = 5
dotnet_diagnostic.OLOC001.license_header = // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.\n// See the LICENCE file in the repository root for full licence text.

View File

@ -33,6 +33,9 @@ jobs:
path: ${{ github.workspace }}/inspectcode
key: inspectcode-${{ hashFiles('.config/dotnet-tools.json') }}-${{ hashFiles('.github/workflows/ci.yml' ) }}
- name: Dotnet code style
run: dotnet build -c Debug -warnaserror osu.Desktop.slnf -p:EnforceCodeStyleInBuild=true
- name: CodeFileSanity
run: |
# TODO: Add ignore filters and GitHub Workflow Command Reporting in CFS. That way we don't have to do this workaround.
@ -46,10 +49,6 @@ jobs:
done <<< $(dotnet codefilesanity)
exit $exit_code
# Temporarily disabled due to test failures, but it won't work anyway until the tool is upgraded.
# - name: .NET Format (Dry Run)
# run: dotnet format --dry-run --check
- name: InspectCode
run: dotnet jb inspectcode $(pwd)/osu.Desktop.slnf --no-build --output="inspectcodereport.xml" --caches-home="inspectcode" --verbosity=WARN
@ -147,4 +146,4 @@ jobs:
# cannot accept .sln(f) files as arguments.
# Build just the main game for now.
- name: Build
run: msbuild osu.iOS/osu.iOS.csproj /restore /p:Configuration=Debug
run: msbuild osu.iOS/osu.iOS.csproj /restore /p:Configuration=Debug

55
.globalconfig Normal file
View File

@ -0,0 +1,55 @@
is_global = true
# .NET Code Style
# IDE styles reference: https://docs.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/
# IDE0001: Simplify names
dotnet_diagnostic.IDE0001.severity = warning
# IDE0002: Simplify member access
dotnet_diagnostic.IDE0002.severity = warning
# IDE0003: Remove qualification
dotnet_diagnostic.IDE0003.severity = warning
# IDE0004: Remove unnecessary cast
dotnet_diagnostic.IDE0004.severity = warning
# IDE0005: Remove unnecessary imports
dotnet_diagnostic.IDE0005.severity = warning
# IDE0034: Simplify default literal
dotnet_diagnostic.IDE0034.severity = warning
# IDE0036: Sort modifiers
dotnet_diagnostic.IDE0036.severity = warning
# IDE0040: Add accessibility modifier
dotnet_diagnostic.IDE0040.severity = warning
# IDE0049: Use keyword for type name
dotnet_diagnostic.IDE0040.severity = warning
# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = warning
# IDE0051: Private method is unused
dotnet_diagnostic.IDE0051.severity = silent
# IDE0052: Private member is unused
dotnet_diagnostic.IDE0052.severity = silent
# IDE0073: File header
dotnet_diagnostic.IDE0073.severity = warning
# IDE0130: Namespace mismatch with folder
dotnet_diagnostic.IDE0130.severity = warning
# IDE1006: Naming style
dotnet_diagnostic.IDE1006.severity = warning
#Disable operator overloads requiring alternate named methods
dotnet_diagnostic.CA2225.severity = none
# Banned APIs
dotnet_diagnostic.RS0030.severity = error

View File

@ -1,4 +1,4 @@
<!-- Contains required properties for osu!framework projects. -->
<!-- Contains required properties for osu!framework projects. -->
<Project>
<PropertyGroup Label="C#">
<LangVersion>8.0</LangVersion>

View File

@ -1,4 +1,4 @@
<Project>
<Project>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<OutputPath>bin\$(Configuration)</OutputPath>

View File

@ -29,13 +29,14 @@ namespace osu.Game.Rulesets.Catch.Tests.Editor
protected CatchSelectionBlueprintTestScene()
{
EditorBeatmap = new EditorBeatmap(new CatchBeatmap
var catchBeatmap = new CatchBeatmap
{
BeatmapInfo =
{
Ruleset = new CatchRuleset().RulesetInfo,
}
}) { Difficulty = { CircleSize = 0 } };
};
EditorBeatmap = new EditorBeatmap(catchBeatmap) { Difficulty = { CircleSize = 0 } };
EditorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint
{
BeatLength = 100

View File

@ -142,13 +142,12 @@ namespace osu.Game.Tests.Visual.Collections
AddStep("add dropdown", () =>
{
Add(new CollectionFilterDropdown
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X,
Width = 0.4f,
}
);
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
RelativeSizeAxes = Axes.X,
Width = 0.4f,
});
});
AddStep("add two collections with same name", () => manager.Collections.AddRange(new[]
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Infrastructure;
using osu.Game.Database;
using osu.Game.Input.Bindings;

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,6 +1,7 @@
using System;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
using System.IO;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using System;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using System;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -1,4 +1,7 @@
using Microsoft.EntityFrameworkCore.Migrations;
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using Microsoft.EntityFrameworkCore.Migrations;
namespace osu.Game.Migrations
{

View File

@ -119,7 +119,7 @@ namespace osu.Game.Overlays.BeatmapSet.Scores
maxComboColumn.Text = value.MaxCombo.ToLocalisableString(@"0\x");
ppColumn.Alpha = value.BeatmapInfo.Status.GrantsPerformancePoints() ? 1 : 0;
ppColumn.Text = value.PP?.ToLocalisableString(@"N0") ?? default(LocalisableString);
ppColumn.Text = value.PP?.ToLocalisableString(@"N0") ?? default;
statisticsColumns.ChildrenEnumerable = value.GetStatisticsForDisplay().Select(createStatisticsColumn);
modsColumn.Mods = value.Mods;

View File

@ -62,7 +62,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
private void updateProgress(APIUser user)
{
levelProgressBar.Length = user?.Statistics?.Level.Progress / 100f ?? 0;
levelProgressText.Text = user?.Statistics?.Level.Progress.ToLocalisableString("0'%'") ?? default(LocalisableString);
levelProgressText.Text = user?.Statistics?.Level.Progress.ToLocalisableString("0'%'") ?? default;
}
}
}

View File

@ -126,7 +126,7 @@ namespace osu.Game.Overlays.Rankings
startDateColumn.Value = dateToString(response.Spotlight.StartDate);
endDateColumn.Value = dateToString(response.Spotlight.EndDate);
mapCountColumn.Value = response.BeatmapSets.Count.ToLocalisableString(@"N0");
participantsColumn.Value = response.Spotlight.Participants?.ToLocalisableString(@"N0") ?? default(LocalisableString);
participantsColumn.Value = response.Spotlight.Participants?.ToLocalisableString(@"N0") ?? default;
}
private LocalisableString dateToString(DateTimeOffset date) => date.ToLocalisableString(@"yyyy-MM-dd");

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Users;
@ -25,7 +24,7 @@ namespace osu.Game.Overlays.Rankings.Tables
protected override Drawable[] CreateUniqueContent(UserStatistics item) => new Drawable[]
{
new RowText { Text = item.PP?.ToLocalisableString(@"N0") ?? default(LocalisableString), }
new RowText { Text = item.PP?.ToLocalisableString(@"N0") ?? default, }
};
}
}

View File

@ -100,7 +100,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void updateTooltipText()
{
TooltipText = cumulativeRotation.Value?.ToLocalisableString("0.0°") ?? default(LocalisableString);
TooltipText = cumulativeRotation.Value?.ToLocalisableString("0.0°") ?? default;
}
}
}

View File

@ -87,44 +87,46 @@ namespace osu.Game.Screens.OnlinePlay.Components
},
};
// case MatchType.TagCoop:
// return new SpriteIcon
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// Size = new Vector2(size),
// Icon = FontAwesome.Solid.Sync,
// Colour = colours.Blue,
//
// Shadow = false
// };
#pragma warning disable IDE0055 // Indentation of commented code
// case MatchType.TagCoop:
// return new SpriteIcon
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// Size = new Vector2(size),
// Icon = FontAwesome.Solid.Sync,
// Colour = colours.Blue,
//
// Shadow = false
// };
// case MatchType.TagTeamCoop:
// return new FillFlowContainer
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// AutoSizeAxes = Axes.Both,
// Direction = FillDirection.Horizontal,
// Spacing = new Vector2(2f),
// Children = new[]
// {
// new SpriteIcon
// {
// Icon = FontAwesome.Solid.Sync,
// Size = new Vector2(size * 0.75f),
// Colour = colours.Blue,
// Shadow = false,
// },
// new SpriteIcon
// {
// Icon = FontAwesome.Solid.Sync,
// Size = new Vector2(size * 0.75f),
// Colour = colours.Pink,
// Shadow = false,
// },
// },
// };
// case MatchType.TagTeamCoop:
// return new FillFlowContainer
// {
// Anchor = Anchor.Centre,
// Origin = Anchor.Centre,
// AutoSizeAxes = Axes.Both,
// Direction = FillDirection.Horizontal,
// Spacing = new Vector2(2f),
// Children = new[]
// {
// new SpriteIcon
// {
// Icon = FontAwesome.Solid.Sync,
// Size = new Vector2(size * 0.75f),
// Colour = colours.Blue,
// Shadow = false,
// },
// new SpriteIcon
// {
// Icon = FontAwesome.Solid.Sync,
// Size = new Vector2(size * 0.75f),
// Colour = colours.Pink,
// Shadow = false,
// },
// },
// };
#pragma warning restore IDE0055
}
}

View File

@ -1,4 +1,4 @@
<Project>
<Project>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<ProjectTypeGuids>{FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

View File

@ -56,6 +56,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{10DF8F12-50FD-45D8-8A38-17BA764BF54D}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.globalconfig = .globalconfig
Directory.Build.props = Directory.Build.props
osu.Android.props = osu.Android.props
osu.iOS.props = osu.iOS.props