Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
Add coding guidelines enforcement (#85)
Browse files Browse the repository at this point in the history
* Add initial coding guidelines and fix where necessary

* Enforce code styling and update code where necessary

* Remove duplicate .editorconfig entries

* Add code analysis setup to CI

* Add missing checkout step

* Update incorrect action version tag

* Remove incompatible analysis step

* Push code style offense to validate CI pipeline

* Remove code style violation

* Add global.json
  • Loading branch information
Typiqally committed May 26, 2023
1 parent 8fbe7fd commit a746ef6
Show file tree
Hide file tree
Showing 57 changed files with 1,150 additions and 614 deletions.
526 changes: 526 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Setup .NET
uses: actions/setup-dotnet@v1.7.2
with:
Expand All @@ -25,7 +25,7 @@ jobs:

- name: Build
run: dotnet build --no-restore

test:
name: Test
needs: [ setup, build ]
Expand Down
12 changes: 11 additions & 1 deletion Epsilon.Abstractions/Epsilon.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisLevel>latest-All</AnalysisLevel>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Epsilon.Canvas.Abstractions\Epsilon.Canvas.Abstractions.csproj" />
<ProjectReference Include="..\Epsilon.Canvas.Abstractions\Epsilon.Canvas.Abstractions.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview1.23165.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion Epsilon.Abstractions/Export/ICanvasModuleExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ namespace Epsilon.Abstractions.Export;

public interface ICanvasModuleExporter : IExporter<ExportData>
{

}
2 changes: 2 additions & 0 deletions Epsilon.Abstractions/Export/IExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
public interface IExporter<in T>
{
public IEnumerable<string> Formats { get; }

public string FileExtension { get; }

Task<Stream> Export(T data, string format);
}
5 changes: 4 additions & 1 deletion Epsilon.Abstractions/Http/HttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

public abstract class HttpService
{
protected HttpService(HttpClient client) => Client = client;
protected HttpService(HttpClient client)
{
Client = client;
}

protected HttpClient Client { get; }
}
15 changes: 8 additions & 7 deletions Epsilon.Abstractions/Model/CourseAssignment.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Epsilon.Abstractions.Model
namespace Epsilon.Abstractions.Model;

public class CourseAssignment
{
public class CourseAssignment
{
public string Name { get; set; } = String.Empty;
public string Score { get; set; } = String.Empty;
public string Url { get; set; } = String.Empty;
}
public string Name { get; set; } = string.Empty;

public string Score { get; set; } = string.Empty;

public Uri? Url { get; set; }
}
8 changes: 0 additions & 8 deletions Epsilon.Abstractions/Model/CourseModule.cs

This file was deleted.

8 changes: 8 additions & 0 deletions Epsilon.Abstractions/Model/CourseModulePackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Epsilon.Abstractions.Model;

public class CourseModulePackage
{
public string Name { get; set; } = string.Empty;

public IEnumerable<CourseOutcome> Outcomes { get; set; } = Enumerable.Empty<CourseOutcome>();
}
15 changes: 8 additions & 7 deletions Epsilon.Abstractions/Model/CourseOutcome.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
namespace Epsilon.Abstractions.Model
namespace Epsilon.Abstractions.Model;

public class CourseOutcome
{
public class CourseOutcome
{
public string Name { get; set; } = String.Empty;
public IEnumerable<CourseAssignment> Assignments { get; set; } = Enumerable.Empty<CourseAssignment>();
public string Description { get; set; } = String.Empty;
}
public string Name { get; set; } = string.Empty;

public IEnumerable<CourseAssignment> Assignments { get; set; } = Enumerable.Empty<CourseAssignment>();

public string Description { get; set; } = string.Empty;
}
44 changes: 29 additions & 15 deletions Epsilon.Abstractions/Model/CoursePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,33 @@ namespace Epsilon.Abstractions.Model;

public class CoursePage
{
public string Title { get; set; }
public string CreatedAt { get; set; }
public string Url { get; set; }
public string EditingRoles { get; set; }
public string PageId { get; set; }
public string LastEditedBy { get; set; }
public string Published { get; set; }
public string HideFromStudents { get; set; }
public string FrontPage { get; set; }
public string HtmlUrl { get; set; }
public string TodoDate { get; set; }
public string PublishedAt { get; set; }
public string UpdatedAt { get; set; }
public string LockedForUser { get; set; }
public string Body { get; set; }
public string? Title { get; set; }

public string? CreatedAt { get; set; }

public Uri? Url { get; set; }

public string? EditingRoles { get; set; }

public string? PageId { get; set; }

public string? LastEditedBy { get; set; }

public string? Published { get; set; }

public string? HideFromStudents { get; set; }

public string? FrontPage { get; set; }

public Uri? HtmlUrl { get; set; }

public string? TodoDate { get; set; }

public string? PublishedAt { get; set; }

public string? UpdatedAt { get; set; }

public string? LockedForUser { get; set; }

public string? Body { get; set; }
}
12 changes: 6 additions & 6 deletions Epsilon.Abstractions/Model/ExportData.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
namespace Epsilon.Abstractions.Model
namespace Epsilon.Abstractions.Model;

public class ExportData
{
public class ExportData
{
public string PersonaHtml { get; set; } = string.Empty;
public IEnumerable<CourseModule> CourseModules { get; set; } = Enumerable.Empty<CourseModule>();
}
public string PersonaHtml { get; set; } = string.Empty;

public IEnumerable<CourseModulePackage> CourseModules { get; set; } = Enumerable.Empty<CourseModulePackage>();
}
10 changes: 10 additions & 0 deletions Epsilon.Canvas.Abstractions/Epsilon.Canvas.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisLevel>latest-All</AnalysisLevel>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0-preview1.23165.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Epsilon.Canvas.Abstractions.Model;

public record Module(
public record CourseModule(
[property: JsonPropertyName("id")] int Id,
[property: JsonPropertyName("name")] string Name,
[property: JsonPropertyName("items_count")] int Count,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Epsilon.Canvas.Abstractions.Model;

public record ModuleOutcomeResultCollection(Module Module, OutcomeResultCollection Collection);
public record ModuleOutcomeResultCollection(CourseModule CourseModule, OutcomeResultCollection Collection);
7 changes: 4 additions & 3 deletions Epsilon.Canvas.Abstractions/Model/Outcome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ public record Outcome(
{
public string ShortDescription()
{
string description = RemoveHtml();
//Function gives only the short English description back of the outcome.
var description = RemoveHtml();

// Function gives only the short English description back of the outcome.
var startPos = description.IndexOf(" EN ", StringComparison.Ordinal) + " EN ".Length;
var endPos = description.IndexOf(" NL ", StringComparison.Ordinal);

return description.Substring(startPos, endPos - startPos);
return description[startPos..endPos];
}

private string RemoveHtml()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Globalization;
using System.Text.Json.Serialization;

namespace Epsilon.Canvas.Abstractions.Model;

Expand All @@ -8,8 +9,8 @@ public record OutcomeResultCollectionLink(
)
{
public IDictionary<string, Outcome> OutcomesDictionary => Outcomes.DistinctBy(static o => o.Id)
.ToDictionary(static o => o.Id.ToString(), static o => o);
.ToDictionary(static o => o.Id.ToString(CultureInfo.InvariantCulture), static o => o);

public IDictionary<string, Alignment> AlignmentsDictionary => Alignments.DistinctBy(static a => a.Id)
.ToDictionary(static a => a.Id, static a => a);
}
3 changes: 2 additions & 1 deletion Epsilon.Canvas.Abstractions/Model/OutcomeResultLink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public record OutcomeResultLink(
[property: JsonPropertyName("user")] string? User,
[property: JsonPropertyName("learning_outcome")] string? Outcome,
[property: JsonPropertyName("alignment")] string? Alignment,
[property: JsonPropertyName("assignment")] string? Assignment);
[property: JsonPropertyName("assignment")] string? Assignment
);
4 changes: 2 additions & 2 deletions Epsilon.Canvas.Abstractions/Model/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace Epsilon.Canvas.Abstractions.Model;
public record Page(
[property: JsonPropertyName("title")] string? Title,
[property: JsonPropertyName("created_at")] string? CreatedAt,
[property: JsonPropertyName("url")] string? Url,
[property: JsonPropertyName("url")] Uri? Url,
[property: JsonPropertyName("editing_roles")] string? EditingRoles,
[property: JsonPropertyName("page_id")] int? PageId,
[property: JsonPropertyName("published")] bool? Published,
[property: JsonPropertyName("hide_from_students")] bool? HideFromStudents,
[property: JsonPropertyName("front_page")] bool? FrontPage,
[property: JsonPropertyName("html_url")] string? HTMLUrl,
[property: JsonPropertyName("html_url")] Uri? HtmlUrl,
[property: JsonPropertyName("todo_date")] DateTime? TodoDate,
[property: JsonPropertyName("publish_at")] DateTime? PublishAt,
[property: JsonPropertyName("updated_at")] DateTime? UpdatedAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace Epsilon.Canvas.Abstractions.Service;
public interface IAssignmentHttpService
{
Task<IEnumerable<Assignment>?> GetAll(int courseId, IEnumerable<string> include);

Task<Assignment?> GetById(int courseId, int id);
}
2 changes: 1 addition & 1 deletion Epsilon.Canvas.Abstractions/Service/IFileHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ namespace Epsilon.Canvas.Abstractions.Service;

public interface IFileHttpService
{
Task<IEnumerable<byte>?> GetFileByteArray(string url);
Task<IEnumerable<byte>?> GetFileByteArray(Uri url);
}
6 changes: 4 additions & 2 deletions Epsilon.Canvas.Abstractions/Service/IModuleHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ namespace Epsilon.Canvas.Abstractions.Service;

public interface IModuleHttpService
{
Task<IEnumerable<Module>?> GetAll(int courseId, IEnumerable<string> include);
Task<Module?> GetById(int courseId, int id);
Task<IEnumerable<CourseModule>?> GetAll(int courseId, IEnumerable<string> include);

Task<CourseModule?> GetById(int courseId, int id);

Task<IEnumerable<ModuleItem>?> GetAllItems(int courseId, int moduleId, int limit = 100);
}
1 change: 1 addition & 0 deletions Epsilon.Canvas.Abstractions/Service/IOutcomeHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ namespace Epsilon.Canvas.Abstractions.Service;
public interface IOutcomeHttpService
{
Task<Outcome?> Find(int id);

Task<OutcomeResultCollection?> GetResults(int courseId, IEnumerable<string> include);
}
2 changes: 1 addition & 1 deletion Epsilon.Canvas.Abstractions/Service/IPageHttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Epsilon.Canvas.Abstractions.Service;

public interface IPageHttpService
{
Task<string> GetPageByName(int courseId, string pageName);
Task<string?> GetPageByName(int courseId, string pageName);

Task<IEnumerable<Page>?> GetAll(int courseId, IEnumerable<string> include);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public interface IPaginatorHttpService
{
public Task<IEnumerable<T>> GetAllPages<T>(HttpMethod method, string uri);
public Task<IEnumerable<T>> GetAllPages<T>(HttpMethod method, Uri uri);
}
Loading

0 comments on commit a746ef6

Please sign in to comment.