Skip to content

Commit

Permalink
refactor: format code and add husky to project (#265)
Browse files Browse the repository at this point in the history
* chore: add husky to project

* refactor: applied format

* chore: add husky tool-runner as a git-hook

* build: add husky to projects for an automated installation and disable husky on ci/cd
  • Loading branch information
maakinoh authored Dec 7, 2024
1 parent a3ede47 commit 4e057df
Show file tree
Hide file tree
Showing 53 changed files with 156 additions and 79 deletions.
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"husky": {
"version": "0.7.1",
"commands": [
"husky"
],
"rollForward": false
}
}
}
2 changes: 2 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
tags:
- 'v[0-9]+.[0-9]+.[0-9]'
- 'v[0-9]+.[0-9]+.[0-9]-**'
env:
HUSKY: 0

jobs:
call_build-and-push-image_nightly:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docker-build-push-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ name: Create and publish Docker images for backend and backoffice
# Note: DOLLAR in the field descriptions should of course be replaced with a dollar sign.
# GitHub parses the description, so we can't write it correctly :)

env:
HUSKY: 0

on:
workflow_call:
inputs:
Expand Down
22 changes: 22 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

## husky task runner examples -------------------
## Note : for local installation use 'dotnet' prefix. e.g. 'dotnet husky'

## run all tasks
#husky run

### run all tasks with group: 'group-name'
#husky run --group group-name

## run task with name: 'task-name'
#husky run --name task-name

## pass hook arguments to task
#husky run --args "$1" "$2"

## or put your custom commands -------------------
#echo 'Husky.Net is awesome!'

dotnet husky run --group pre-commit
12 changes: 12 additions & 0 deletions .husky/task-runner.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "https://alirezanet.github.io/Husky.Net/schema.json",
"tasks": [
{
"name": "dotnet-format",
"group": "pre-commit",
"command": "dotnet",
"args": ["format","--no-restore", "--include", "${staged}"],
"include": ["**/*.cs"]
}
]
}
11 changes: 5 additions & 6 deletions src/Eurofurence.App.Backoffice/Eurofurence.App.Backoffice.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="0.37.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.11" />
Expand All @@ -15,15 +13,16 @@
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="MudBlazor" Version="7.8.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Eurofurence.App.Domain.Model\Eurofurence.App.Domain.Model.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../.." />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<ArtistAlleySystemStatus> GetArtistAllaySystemStatus()
{
var options = new JsonSerializerOptions();
options.Converters.Add(new JsonStringEnumConverter());
return await http.GetFromJsonAsync<ArtistAlleySystemStatus>("ArtistsAlley/SystemStatus",options);
return await http.GetFromJsonAsync<ArtistAlleySystemStatus>("ArtistsAlley/SystemStatus", options);
}
}
}
2 changes: 1 addition & 1 deletion src/Eurofurence.App.Backoffice/Services/IUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public interface IUserService
/// <param name="changeRequest"></param>
/// <returns></returns>
public Task PutUserArtistAlleyStatusAsync(string userID, ArtistAlleyUserPenaltyChangeRequest changeRequest);

}
}
4 changes: 2 additions & 2 deletions src/Eurofurence.App.Common/DataDiffUtils/PatchDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public PatchDefinition<TSource, TTarget> Map<TField>(
if (sourceValue is ICollection &&
sourceValue.GetType().IsGenericType)
return CollectionsEqual((ICollection)sourceValue, (ICollection)targetValue);

return (bool)sourceValue?.Equals(targetValue);
},
ApplySourceValueToTarget =
Expand Down Expand Up @@ -129,7 +129,7 @@ public List<PatchOperation<TTarget>> Patch(IEnumerable<TSource> sources, IEnumer
{
TTarget target;

var result = new PatchOperation<TTarget> {Action = ActionEnum.NotModified};
var result = new PatchOperation<TTarget> { Action = ActionEnum.NotModified };

var existingTarget = _targetItemLocator(sourceItem, unprocessedTargets);
if (existingTarget != null)
Expand Down
4 changes: 4 additions & 0 deletions src/Eurofurence.App.Common/Eurofurence.App.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../.." />
</Target>
</Project>
8 changes: 4 additions & 4 deletions src/Eurofurence.App.Common/Results/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ public class Result : IResult
public bool IsSuccessful { get; set; }
public string ErrorMessage { get; set; }
public string ErrorCode { get; set; }

public static explicit operator bool(Result r) => r.IsSuccessful;

public static Result Ok => new Result {IsSuccessful = true};
public static Result Ok => new Result { IsSuccessful = true };
public static Result Error(string errorCode, string errorMessage = "")
=> new Result {IsSuccessful = false, ErrorCode = errorCode, ErrorMessage = errorMessage};
=> new Result { IsSuccessful = false, ErrorCode = errorCode, ErrorMessage = errorMessage };
}

public class Result<T> : Result, IResult<T>
{
public T Value { get; set; }
public static explicit operator T(Result<T> r) => r.Value;

public new static Result<T> Ok(T value) => new Result<T> {IsSuccessful = true, Value = value};
public new static Result<T> Ok(T value) => new Result<T> { IsSuccessful = true, Value = value };
public new static Result<T> Error(string errorCode, string errorMessage = "")
=> new Result<T> { IsSuccessful = false, ErrorCode = errorCode, ErrorMessage = errorMessage };
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eurofurence.App.Common/Validation/BadgeChecksum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static bool IsValid(string id)
public static bool TryParse(string id, out int regNo)
{
var numberPart = id.Substring(0, id.Length - 1);
var checksumLetter = id[id.Length-1];
var checksumLetter = id[id.Length - 1];

if (CHECKSUM_LETTER_MAP.IndexOf(checksumLetter) == -1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class StateChangeRecord : EntityBase
[Required]
[Column("ChangedBy")]
public string ChangedBy { get; set; }

/// <summary>
/// The new penalty which was set
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PrivateMessageRecord : EntityBase
{
[DataMember]
public string RecipientRegSysId { get; set; }

[DataMember]
public string RecipientIdentityId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<ItemGroup>
<ProjectReference Include="..\Eurofurence.App.Common\Eurofurence.App.Common.csproj" />
</ItemGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../.." />
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/Eurofurence.App.Domain.Model/Events/EventRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class EventRecord : EntityBase

[DataMember]
public string[] Tags { get; set; }

[JsonIgnore]
public virtual EventConferenceTrackRecord ConferenceTrack { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/Eurofurence.App.Domain.Model/Fragments/LinkFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override bool Equals(object obj)
if (obj == null || GetType() != obj.GetType())
return false;

var f = (LinkFragment) obj;
var f = (LinkFragment)obj;

return
f.FragmentType == FragmentType
Expand All @@ -62,7 +62,7 @@ public override int GetHashCode()
{
unchecked
{
var hashCode = (int) FragmentType;
var hashCode = (int)FragmentType;
hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (Target != null ? Target.GetHashCode() : 0);
return hashCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class FursuitBadgeRecord : EntityBase

[DataMember]
[Required]
public string OwnerUid { get; set; }
public string OwnerUid { get; set; }

[DataMember]
[Required]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ImageWithRelationsResponse : ImageRecord
[DataMember]
public List<Guid> TableRegistrationIds { get; set; } = new();

[DataMember]
[DataMember]
public List<Guid> MapIds { get; set; } = new();

[DataMember]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class KnowledgeEntryRecord : EntityBase
[JsonIgnore]
public KnowledgeGroupRecord KnowledgeGroup { get; set; }

[DataMember]
[DataMember]
public virtual List<LinkFragment> Links { get; set; } = new();

[JsonIgnore]
Expand Down
2 changes: 1 addition & 1 deletion src/Eurofurence.App.Domain.Model/Maps/MapEntryRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MapEntryRecord
[DataMember]
public int TapRadius { get; set; }

[DataMember]
[DataMember]
public List<LinkFragment> Links { get; set; } = new();

[JsonIgnore]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public AppDbContext(DbContextOptions<AppDbContext> options)
public virtual DbSet<DeviceIdentityRecord> DeviceIdentities { get; set; }
public virtual DbSet<RegistrationIdentityRecord> RegistrationIdentities { get; set; }

public virtual DbSet<ArtistAlleyUserPenaltyRecord> ArtistAlleyUserPenalties{ get; set; }
public virtual DbSet<ArtistAlleyUserPenaltyRecord> ArtistAlleyUserPenalties { get; set; }

public virtual DbSet<ArtistAlleyUserPenaltyRecord.StateChangeRecord> ArtistAlleyUserPenaltyChanges { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
<ItemGroup>
<ProjectReference Include="..\Eurofurence.App.Domain.Model\Eurofurence.App.Domain.Model.csproj" />
</ItemGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../.." />
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Task<Guid> SendPrivateMessageAsync(
SendPrivateMessageByRegSysRequest request,
string senderUid = "System",
CancellationToken cancellationToken = default);

Task<Guid> SendPrivateMessageAsync(
SendPrivateMessageByIdentityRequest request,
string senderUid = "System",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public interface ICollectingGameService
Task<IResult> RegisterTokenForFursuitBadgeForOwnerAsync(string ownerUid, Guid fursuitBadgeId, string tokenValue);
Task<IResult<CollectTokenResponse>> CollectTokenForPlayerAsync(string identityId, string tokenValue, string username);

Task<IResult<PlayerScoreboardEntry[]>> GetPlayerScoreboardEntriesAsync(int top);
Task<IResult<PlayerScoreboardEntry[]>> GetPlayerScoreboardEntriesAsync(int top);
Task<IResult<FursuitScoreboardEntry[]>> GetFursuitScoreboardEntriesAsync(int top);

Task<IResult> CreateTokenFromValueAsync(string tokenValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
public class PlayerScoreboardEntry : ScoreboardEntry
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class LostAndFoundResponse

[JsonPropertyName("title")]
public string Title { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static string[] GetRegSysIds(this ClaimsPrincipal principal)
{
return principal.FindAll("RegSysId").Select(x => x.Value).ToArray();
}

public static string GetName(this ClaimsPrincipal principal)
{
return principal.FindFirst("name")?.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Eurofurence.App.Server.Services.Abstractions.Telegram
{
public interface IUserManager
{
Task<TEnum> GetAclForUserAsync<TEnum>(string username) where TEnum: struct;
Task<TEnum> GetAclForUserAsync<TEnum>(string username) where TEnum : struct;

Task SetAclForUserAsync<TEnum>(string username, TEnum acl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task<ImportResult> ImportAgentClosingResultLogAsync(TextReader logR
try
{
await _semaphore.WaitAsync();

var csv = new CsvReader(logReader, CultureInfo.InvariantCulture);

csv.Context.RegisterClassMap<AgentClosingResultImportRowClassMap>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async Task RegisterTableAsync(ClaimsPrincipal user, TableRegistrationRequ

foreach (var registration in activeRegistrations)
{
if (registration.ImageId is {} imageId) await _imageService.DeleteOneAsync(imageId);
if (registration.ImageId is { } imageId) await _imageService.DeleteOneAsync(imageId);
await DeleteOneAsync(registration.Id);
}

Expand Down Expand Up @@ -191,7 +191,7 @@ private async Task BroadcastAsync(TableRegistrationRecord record)
{
message.AppendLine($"Website: {record.WebsiteUrl.RemoveMarkdown()}");
}

if (record.ImageId.HasValue)
{
await _telegramMessageSender.SendImageToChatAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public void EnqueueMessage(IPrivateMessageQueueService.QueuedNotificationParamet
}
}

public int GetQueueSize() {
public int GetQueueSize()
{
lock (_notificationQueue)
return _notificationQueue.Count;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Target Name="Husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High" />
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High" WorkingDirectory="../.." />
</Target>
</Project>
Loading

0 comments on commit 4e057df

Please sign in to comment.