Skip to content
This repository has been archived by the owner on Oct 13, 2024. It is now read-only.

style: add Sonar and StyleCop Analyzers #177

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[*.cs]
csharp_style_var_for_built_in_types=true:silent
csharp_style_var_when_type_is_apparent=true:silent
csharp_style_var_elsewhere=true:silent

## SonarAnalyzers.CSharp

# Remove this commented out code.
dotnet_diagnostic.S125.severity = None

# Complete the task associated to this 'TODO' comment.
dotnet_diagnostic.S1135.severity = None

# Remove this empty class, write its code or make it an "interface".
dotnet_diagnostic.S2094.severity = None

# Fix this implementation of 'IDisposable' to conform to the dispose pattern.
dotnet_diagnostic.S3881.severity = None


## StyleCop.Analyzers

# XML comment analysis is disabled due to project configuration
dotnet_diagnostic.SA0001.severity = None

# Prefix local calls with this
dotnet_diagnostic.SA1101.severity = None

# Opening brace should be followed by a space
dotnet_diagnostic.SA1012.severity = None

# Closing brace should be preceded by a space
dotnet_diagnostic.SA1013.severity = None

# Using directive should appear within a namespace declaration
dotnet_diagnostic.SA1200.severity = None

# Field '_blah' should not begin with an underscore
dotnet_diagnostic.SA1309.severity = None

# Use trailing comma in multi-line initializers
dotnet_diagnostic.SA1413.severity = None

# Single-line comments should not be followed by blank line
dotnet_diagnostic.SA1512.severity = None

# The file header is missing or not located at the top of the file
dotnet_diagnostic.SA1633.severity = None
16 changes: 16 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project>
<ItemGroup>
<PackageReference
Include="SonarAnalyzer.CSharp"
Version="9.15.0.81779"
PrivateAssets="all"
Condition="$(MSBuildProjectExtension) == '.csproj'"
/>
<PackageReference
Include="StyleCop.Analyzers"
Version="1.2.0-beta.507"
PrivateAssets="all"
Condition="$(MSBuildProjectExtension) == '.csproj'"
/>
</ItemGroup>
</Project>
14 changes: 14 additions & 0 deletions Jellyfin.Plugin.Themerr.Tests/FixtureCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider;
using Movie = MediaBrowser.Controller.Entities.Movies.Movie;

namespace Jellyfin.Plugin.Themerr.Tests;

/// <summary>
/// This class is used to create a collection of tests.
/// </summary>
[CollectionDefinition("Fixture Collection")]
public class FixtureCollection : ICollectionFixture<FixtureJellyfinServer>
{
// This class doesn't need to have any code, or even be long-lived.
// All it needs is to just exist, and be annotated with CollectionDefinition.
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@

namespace Jellyfin.Plugin.Themerr.Tests;

[CollectionDefinition("Bootstrapped Collection")]
public class BootstrappedCollection : ICollectionFixture<BootstrapJellyfinServer>
{
// This class doesn't need to have any code, or even be long-lived.
// All it needs is to just exist, and be annotated with CollectionDefinition.
}

/// <summary>
/// This class is used to bootstrap a Jellyfin server with mock movies
/// This class is used as a fixture for the Jellyfin server with mock movies
/// </summary>
public class BootstrapJellyfinServer
public class FixtureJellyfinServer
{
/// <summary>
/// Mock movies to use for testing
/// </summary>
/// <returns></returns>
/// <returns>List containing mock <see cref="Movie"/> objects.</returns>
public static List<Movie> MockMovies()
{
return new List<Movie>
Expand Down Expand Up @@ -66,7 +59,6 @@ public static List<Movie> MockMovies()
};
}


/// <summary>
/// Create mock movies from stub video
/// </summary>
Expand All @@ -75,40 +67,37 @@ public static List<Movie> MockMovies()
private void CreateMockMovies()
{
var mockMovies = MockMovies();

// get the stub video path based on the directory of this file
var stubVideoPath = Path.Combine(
Directory.GetCurrentDirectory(),
"data",
"video_stub.mp4"
);

"video_stub.mp4");

Assert.True(File.Exists(stubVideoPath), "Could not find ./data/video_stub.mp4");

foreach (var movie in mockMovies)
{
// copy the ./data/video_stub.mp4 to the movie folder "movie.Name (movie.ProductionYear)"
var movieFolder = Path.Combine(
"themerr_jellyfin_tests",
$"{movie.Name} ({movie.ProductionYear})"
);

$"{movie.Name} ({movie.ProductionYear})");

// create the movie folder
Directory.CreateDirectory(movieFolder);

// copy the video_stub.mp4 to the movie folder, renaming it based on movie name
var movieVideoPath = Path.Combine(
movieFolder,
$"{movie.Name} ({movie.ProductionYear}).mp4"
);

$"{movie.Name} ({movie.ProductionYear}).mp4");

// if file does not exist
if (!File.Exists(movieVideoPath))
{
// copy the stub video to the movie folder
File.Copy(stubVideoPath, movieVideoPath);
}

Assert.True(File.Exists(movieVideoPath), $"Could not find {movieVideoPath}");
}
}
Expand Down
Loading