Skip to content

Commit

Permalink
(Re-)Enable dotnet format (#2070)
Browse files Browse the repository at this point in the history
* git add --renormalize .

* Mark migrations as generated code

* Fix mismatch between .gitattributes and .editorconfig

* Fix double-spaces in code

* Correct some indentation

* Fix multiline collection/object inits w/ multiple per line

* Enforce spaces between params and attributes

* Enforce no space in target-typed `new(`

* Enforce space in `if (`/`switch (`

* Enforce braces on conditional

* Enforce `switch` expression brace on next line

* Remove pointless space after final argument

* The linter wants this IDK

* Fix commented `namespace` statement

* Document `dotnet format` and some additional de facto rules
  • Loading branch information
YoshiRulz authored Feb 9, 2025
1 parent 28144c6 commit deee30d
Show file tree
Hide file tree
Showing 41 changed files with 674 additions and 611 deletions.
533 changes: 268 additions & 265 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Auto detect text files and perform LF normalization
* text=auto
* text=auto
# per .editorconfig, C# source files should use \r\n (and VB but who cares)
*.cs text eol=crlf
36 changes: 18 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
*.user
.vs/**
.idea/**
**/bin/**
**/obj/**
**/Release/**
**/Debug/**
**/packages/**
*.g.cs
TASVideos/CommonAssemblyInfo.cs
packages-microsoft-prod.deb
TASVideos/Properties/serviceDependencies.json
TASVideos/Properties/serviceDependencies.local.json
TASVideos.sln.personal.DotSettings
TASVideos.Data/SampleData/SampleData-MsSql.sql
TASVideos.Data/SampleData/SampleData-Postgres.sql
TASVideos/logs/
TASVideos/nohup.out
*.user
.vs/**
.idea/**
**/bin/**
**/obj/**
**/Release/**
**/Debug/**
**/packages/**
*.g.cs
TASVideos/CommonAssemblyInfo.cs
packages-microsoft-prod.deb
TASVideos/Properties/serviceDependencies.json
TASVideos/Properties/serviceDependencies.local.json
TASVideos.sln.personal.DotSettings
TASVideos.Data/SampleData/SampleData-MsSql.sql
TASVideos.Data/SampleData/SampleData-Postgres.sql
TASVideos/logs/
TASVideos/nohup.out
TASVideos/tasvideos.pid
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"editor.insertSpaces": false,
"editor.detectIndentation": false
{
"editor.insertSpaces": false,
"editor.detectIndentation": false
}
68 changes: 34 additions & 34 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TASVideos/TASVideos.csproj"
],
"problemMatcher": "$msCompile"
},
{
"label": "build_forumengine",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TASVideos.ForumEngineTempTest/TASVideos.ForumEngineTempTest.csproj"
],
"problemMatcher": "$msCompile"
},
{
"label": "build_wikiengine",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TASVideos.WikiEngineTest/TASVideos.WikiEngineTest.csproj"
],
"problemMatcher": "$msCompile"
}
]
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TASVideos/TASVideos.csproj"
],
"problemMatcher": "$msCompile"
},
{
"label": "build_forumengine",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TASVideos.ForumEngineTempTest/TASVideos.ForumEngineTempTest.csproj"
],
"problemMatcher": "$msCompile"
},
{
"label": "build_wikiengine",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/TASVideos.WikiEngineTest/TASVideos.WikiEngineTest.csproj"
],
"problemMatcher": "$msCompile"
}
]
}
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ They are also run in CI.

The codebase uses the [Allman style](https://en.wikipedia.org/wiki/Indentation_style#Allman_style), placing braces on their own line. It uses tabs for indentation including in HTML in CSHTML where it acts as a single space when parsed by web browsers. Otherwise, code style should generally follow conventions for .NET 5 and C#.

Most of our code style rules are configured in EditorConfig, so you can use `dotnet format` or any other Roslyn-powered linter to apply them. These rules aren't automated at the moment:
- Do not mark lambdas as `static`.
- Do not use `required` with `init` props.

## Site Design

The site has a [design document](DESIGN-SPEC.md) which details the structure, philosophy, and design goals of the frontend segments of the codebase which is great study for aspiring frontend contributors.
12 changes: 6 additions & 6 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Custom Packages" value="custompackages" />
</packageSources>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="Custom Packages" value="custompackages" />
</packageSources>
</configuration>
2 changes: 1 addition & 1 deletion TASVideos.Api/Endpoints/GamesEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ await db.Games
.SingleOrDefaultAsync(g => g.Id == id)))
.ProducesFromId<GamesResponse>("game");

group.MapGet("", async ([AsParameters]GamesRequest request, HttpContext context, ApplicationDbContext db) =>
group.MapGet("", async ([AsParameters] GamesRequest request, HttpContext context, ApplicationDbContext db) =>
{
var validationError = ApiResults.Validate(request, context);
if (validationError is not null)
Expand Down
2 changes: 1 addition & 1 deletion TASVideos.Api/Endpoints/PublicationsEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ await db.Publications
.SingleOrDefaultAsync(p => p.Id == id)))
.ProducesFromId<PublicationsResponse>("publication");

group.MapGet("", async ([AsParameters]PublicationsRequest request, HttpContext context, ApplicationDbContext db) =>
group.MapGet("", async ([AsParameters] PublicationsRequest request, HttpContext context, ApplicationDbContext db) =>
{
var validationError = ApiResults.Validate(request, context);
if (validationError is not null)
Expand Down
2 changes: 1 addition & 1 deletion TASVideos.Api/Endpoints/SubmissionsEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ await db.Submissions
.SingleOrDefaultAsync(p => p.Id == id)))
.ProducesFromId<SubmissionsResponse>("submission");

group.MapGet("", async ([AsParameters]SubmissionsRequest request, HttpContext context, ApplicationDbContext db) =>
group.MapGet("", async ([AsParameters] SubmissionsRequest request, HttpContext context, ApplicationDbContext db) =>
{
var validationError = ApiResults.Validate(request, context);
if (validationError is not null)
Expand Down
2 changes: 1 addition & 1 deletion TASVideos.Api/Endpoints/TagsEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ await tagService.GetById(id)))
.ProducesFromId<TagsResponse>("tag")
.WithName("GetByTagId");

group.MapGet("", async ([AsParameters]ApiRequest request, HttpContext context, ITagService tagService) =>
group.MapGet("", async ([AsParameters] ApiRequest request, HttpContext context, ITagService tagService) =>
{
var validationError = ApiResults.Validate(request, context);
if (validationError is not null)
Expand Down
17 changes: 15 additions & 2 deletions TASVideos.Common/HtmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,21 @@ public readonly string Serialize()
private static readonly Regex AllowedAttributeNames = AllowedAttributeNamesRegex();
private static readonly HashSet<string> VoidTags = new(
[
"area", "base", "br", "col", "embed", "hr", "img", "input",
"keygen", "link", "meta", "param", "source", "track", "wbr"
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"keygen",
"link",
"meta",
"param",
"source",
"track",
"wbr"
],
StringComparer.OrdinalIgnoreCase
);
Expand Down
6 changes: 3 additions & 3 deletions TASVideos.Core/Services/TASVideoAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public async Task<int> PostSubmissionTopic(int submissionId, string title)
Question = SiteGlobalConstants.PollQuestion,
PollOptions =
[
new () { Text = SiteGlobalConstants.PollOptionNo, Ordinal = 0 },
new () { Text = SiteGlobalConstants.PollOptionYes, Ordinal = 1 },
new () { Text = SiteGlobalConstants.PollOptionsMeh, Ordinal = 2 }
new() { Text = SiteGlobalConstants.PollOptionNo, Ordinal = 0 },
new() { Text = SiteGlobalConstants.PollOptionYes, Ordinal = 1 },
new() { Text = SiteGlobalConstants.PollOptionsMeh, Ordinal = 2 }
]
};

Expand Down
22 changes: 11 additions & 11 deletions TASVideos.Core/Services/TASVideosGrue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ internal class TASVideosGrue(ApplicationDbContext db, IForumService forumService
{
private static readonly string[] RandomMessages =
[
"... minty!",
"... blech, salty!",
"... blech, bitter!",
"... juicy!",
"... crunchy!",
"... sweet!",
"... want more!",
"... *burp*!",
"... om, nom, nom... nom nom",
"... 'twas dry"
];
"... minty!",
"... blech, salty!",
"... blech, bitter!",
"... juicy!",
"... crunchy!",
"... sweet!",
"... want more!",
"... *burp*!",
"... om, nom, nom... nom nom",
"... 'twas dry"
];

public async Task RejectAndMove(int submissionId)
{
Expand Down
2 changes: 1 addition & 1 deletion TASVideos.Core/Settings/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class AppSettings

public Connections ConnectionStrings { get; set; } = new();

public SubmissionRateLimit SubmissionRate { get; set; } = new ();
public SubmissionRateLimit SubmissionRate { get; set; } = new();

public IrcConnection Irc { get; set; } = new();
public DiscordConnection Discord { get; set; } = new();
Expand Down
4 changes: 2 additions & 2 deletions TASVideos.Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected override void OnModelCreating(ModelBuilder builder)
entity
.HasGeneratedTsVectorColumn(
p => p.SearchVector,
"english", // Text search config
"english", // Text search config
p => new { p.PageName, p.Markup })
.HasIndex(p => p.SearchVector)
.HasMethod("GIN");
Expand Down Expand Up @@ -437,7 +437,7 @@ protected override void OnModelCreating(ModelBuilder builder)
entity
.HasGeneratedTsVectorColumn(
p => p.SearchVector,
"english", // Text search config
"english", // Text search config
p => p.Text)
.HasIndex(p => p.SearchVector)
.HasMethod("GIN");
Expand Down
1 change: 1 addition & 0 deletions TASVideos.Data/TASVideos.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Update="Migrations/**/*.cs" AutoGen="true" />
<None Remove="SampleData\SampleData-Postgres.sql" />
</ItemGroup>

Expand Down
3 changes: 2 additions & 1 deletion TASVideos.Parsers/Parsers/Bk2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public async Task<IParseResult> Parse(Stream file, long length)
romHash = header.GetValueFor("MD5");
}

HashType? hashType = romHash.Length switch {
HashType? hashType = romHash.Length switch
{
2 * SHA1.HashSizeInBytes => HashType.Sha1,
2 * MD5.HashSizeInBytes => HashType.Md5,
8/* 2 * Crc32.HashLengthInBytes w/ System.IO.Hashing */ => HashType.Crc32,
Expand Down
68 changes: 34 additions & 34 deletions TASVideos.Parsers/Parsers/Ctm.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
namespace TASVideos.MovieParsers.Parsers;

[FileExtension("ctm")]
internal class Ctm : Parser, IParser
{
private const decimal FrameRate = 268111856.0M / 4481136.0M; // https://github.com/citra-emu/citra/blob/a2f34ea82b5a31a7e842d0099921b85b8bce403f/src/core/hw/gpu.h#L27
private const int InputRate = 234; // Rate at which inputs are polled per second

public async Task<IParseResult> Parse(Stream file, long length)
{
var result = new SuccessResult(FileExtension)
{
Region = RegionType.Ntsc,
SystemCode = SystemCodes.N3ds
};

using var br = new BinaryReader(file);
var header = new string(br.ReadChars(4));
if (header != "CTM\x1b")
{
return InvalidFormat();
}

br.ReadUInt64(); // Title ID
br.ReadBytes(20); // Git hash of Citra revision
br.ReadUInt64(); // Init time of system clock
br.ReadUInt64(); // Movie ID
br.ReadChars(32); // Author
result.RerecordCount = br.ReadInt32();
result.Frames = (int)Math.Ceiling((decimal)br.ReadUInt64() / InputRate * FrameRate);

return await Task.FromResult(result);
}
}
namespace TASVideos.MovieParsers.Parsers;

[FileExtension("ctm")]
internal class Ctm : Parser, IParser
{
private const decimal FrameRate = 268111856.0M / 4481136.0M; // https://github.com/citra-emu/citra/blob/a2f34ea82b5a31a7e842d0099921b85b8bce403f/src/core/hw/gpu.h#L27
private const int InputRate = 234; // Rate at which inputs are polled per second

public async Task<IParseResult> Parse(Stream file, long length)
{
var result = new SuccessResult(FileExtension)
{
Region = RegionType.Ntsc,
SystemCode = SystemCodes.N3ds
};

using var br = new BinaryReader(file);
var header = new string(br.ReadChars(4));
if (header != "CTM\x1b")
{
return InvalidFormat();
}

br.ReadUInt64(); // Title ID
br.ReadBytes(20); // Git hash of Citra revision
br.ReadUInt64(); // Init time of system clock
br.ReadUInt64(); // Movie ID
br.ReadChars(32); // Author
result.RerecordCount = br.ReadInt32();
result.Frames = (int)Math.Ceiling((decimal)br.ReadUInt64() / InputRate * FrameRate);

return await Task.FromResult(result);
}
}
4 changes: 2 additions & 2 deletions TASVideos.Parsers/Parsers/Omr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public async Task<IParseResult> Parse(Stream file, long length)

string system;

if(Convert.ToInt16(version) >= 4)
if (Convert.ToInt16(version) >= 4)
{
var confVersion = replay.XPathEvaluateList("//snapshots/item/config").FirstAttributeValue("version");

if(Convert.ToInt16(confVersion) >= 6)
if (Convert.ToInt16(confVersion) >= 6)
{
system = replay.XPathEvaluateList("//snapshots/item/config/config/msxconfig/info")
.FirstDescendant("type").Value.ToLower();
Expand Down
Loading

0 comments on commit deee30d

Please sign in to comment.