Stylcop: Adding a stylecop analyser and trying to configure it

This commit is contained in:
Zoe Roux 2021-09-02 22:44:00 +02:00
parent 38472a7431
commit 8ff2fe3965
20 changed files with 972 additions and 929 deletions

17
Directory.Build.props Normal file
View File

@ -0,0 +1,17 @@
<Project>
<PropertyGroup>
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
<IsOSX Condition="$([MSBuild]::IsOSPlatform('OSX'))">true</IsOSX>
<IsLinux Condition="$([MSBuild]::IsOSPlatform('Linux'))">true</IsLinux>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.354" />
<None Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json" Visible="false" />
<None Include="$(MSBuildThisFileDirectory).editorconfig" Link="stylecop.json" Visible="false" />
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)Kyoo.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
</Project>

View File

@ -16,9 +16,9 @@
void Restart();
/// <summary>
/// Get the data directory
/// Get the data directory.
/// </summary>
/// <returns>Retrieve the data directory where runtime data should be stored</returns>
/// <returns>Retrieve the data directory where runtime data should be stored.</returns>
string GetDataDirectory();
/// <summary>

View File

@ -14,10 +14,10 @@ namespace Kyoo.Abstractions.Controllers
public interface IConfigurationManager
{
/// <summary>
/// Add an editable configuration to the editable configuration list
/// Add an editable configuration to the editable configuration list.
/// </summary>
/// <param name="path">The root path of the editable configuration. It should not be a nested type.</param>
/// <typeparam name="T">The type of the configuration</typeparam>
/// <typeparam name="T">The type of the configuration.</typeparam>
void AddTyped<T>(string path);
/// <summary>
@ -40,28 +40,29 @@ namespace Kyoo.Abstractions.Controllers
/// <summary>
/// Get the value of a setting using it's path.
/// </summary>
/// <param name="path">The path of the resource (can be separated by ':' or '__')</param>
/// <param name="path">The path of the resource (can be separated by ':' or '__').</param>
/// <exception cref="ItemNotFoundException">No setting found at the given path.</exception>
/// <returns>The value of the settings (if it's a strongly typed one, the given type is instantiated</returns>
/// <returns>The value of the settings (if it's a strongly typed one, the given type is instantiated.</returns>
object GetValue(string path);
/// <summary>
/// Get the value of a setting using it's path.
/// If your don't need a strongly typed value, see <see cref="GetValue"/>.
/// </summary>
/// <param name="path">The path of the resource (can be separated by ':' or '__')</param>
/// <param name="path">The path of the resource (can be separated by ':' or '__').</param>
/// <typeparam name="T">A type to strongly type your option.</typeparam>
/// <exception cref="InvalidCastException">If your type is not the same as the registered type</exception>
/// <exception cref="InvalidCastException">If your type is not the same as the registered type.</exception>
/// <exception cref="ItemNotFoundException">No setting found at the given path.</exception>
/// <returns>The value of the settings (if it's a strongly typed one, the given type is instantiated</returns>
/// <returns>The value of the settings (if it's a strongly typed one, the given type is instantiated.</returns>
T GetValue<T>(string path);
/// <summary>
/// Edit the value of a setting using it's path. Save it to the json file.
/// </summary>
/// <param name="path">The path of the resource (can be separated by ':' or '__')</param>
/// <param name="value">The new value of the resource</param>
/// <param name="path">The path of the resource (can be separated by ':' or '__').</param>
/// <param name="value">The new value of the resource.</param>
/// <exception cref="ItemNotFoundException">No setting found at the given path.</exception>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
Task EditValue(string path, object value);
}
}

View File

@ -8,7 +8,8 @@ using Microsoft.AspNetCore.Mvc;
namespace Kyoo.Abstractions.Controllers
{
/// <summary>
/// A service to abstract the file system to allow custom file systems (like distant file systems or external providers)
/// A service to abstract the file system to allow custom file systems
/// (like distant file systems or external providers).
/// </summary>
public interface IFileSystem
{
@ -16,7 +17,7 @@ namespace Kyoo.Abstractions.Controllers
/// <summary>
/// Used for http queries returning a file. This should be used to return local files
/// or proxy them from a distant server
/// or proxy them from a distant server.
/// </summary>
/// <remarks>
/// If no file exists at the given path or if the path is null, a NotFoundResult is returned

View File

@ -1,5 +1,5 @@
using Kyoo.Abstractions.Models;
using System.Threading.Tasks;
using Kyoo.Abstractions.Models;
namespace Kyoo.Abstractions.Controllers
{

View File

@ -15,7 +15,7 @@ namespace Kyoo.Abstractions.Models.Exceptions
/// </summary>
public IdentificationFailedException()
: base("An identification failed.")
{}
{ }
/// <summary>
/// Create a new <see cref="IdentificationFailedException"/> with a custom message.
@ -23,7 +23,7 @@ namespace Kyoo.Abstractions.Models.Exceptions
/// <param name="message">The message to use.</param>
public IdentificationFailedException(string message)
: base(message)
{}
{ }
/// <summary>
/// The serialization constructor

View File

@ -12,7 +12,7 @@ namespace Kyoo.Abstractions.Models.Exceptions
/// <summary>
/// Create a default <see cref="ItemNotFoundException"/> with no message.
/// </summary>
public ItemNotFoundException() {}
public ItemNotFoundException() { }
/// <summary>
/// Create a new <see cref="ItemNotFoundException"/> with a message

View File

@ -10,12 +10,6 @@
<LangVersion>default</LangVersion>
</PropertyGroup>
<PropertyGroup>
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
<IsOSX Condition="$([MSBuild]::IsOSPlatform('OSX'))">true</IsOSX>
<IsLinux Condition="$([MSBuild]::IsOSPlatform('Linux'))">true</IsLinux>
</PropertyGroup>
<PropertyGroup>
<TranscoderBinary Condition="$(IsWindows) == true">transcoder.dll</TranscoderBinary>
<TranscoderBinary Condition="$(IsOSX) == true">libtranscoder.dylib</TranscoderBinary>

View File

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Kyoo.Abstractions.Controllers;
using Kyoo.Abstractions.Models;
using Kyoo.Abstractions.Models.Permissions;
using Kyoo.Core.Models.Options;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace Kyoo.Core.Api

View File

@ -1,8 +1,4 @@
<Project>
<PropertyGroup>
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
</PropertyGroup>
<Import Project="Kyoo.Host.WindowsTrait.target" Condition="$(IsWindows) == true" />
<Import Project="Kyoo.Host.WindowsTrait.linux.target" Condition="$(IsWindows) != true" />

View File

@ -5,8 +5,8 @@ using TMDbLib.Objects.General;
using TMDbLib.Objects.People;
using TMDbLib.Objects.Search;
using Images = Kyoo.Abstractions.Models.Images;
using TvCast = TMDbLib.Objects.TvShows.Cast;
using MovieCast = TMDbLib.Objects.Movies.Cast;
using TvCast = TMDbLib.Objects.TvShows.Cast;
namespace Kyoo.TheMovieDb
{

View File

@ -49,7 +49,7 @@ namespace Kyoo.TheMovieDb
.Select(x => x.ToPeople(provider))
.Concat(tv.Credits.Crew.Select(x => x.ToPeople(provider)))
.ToArray(),
ExternalIDs = new []
ExternalIDs = new[]
{
new MetadataID
{
@ -84,7 +84,7 @@ namespace Kyoo.TheMovieDb
? $"https://image.tmdb.org/t/p/original{tv.BackdropPath}"
: null,
},
ExternalIDs = new []
ExternalIDs = new[]
{
new MetadataID
{

View File

@ -22,7 +22,7 @@ namespace Kyoo.TheMovieDb
{
Slug = Utility.ToSlug(company.Name),
Name = company.Name,
ExternalIDs = new []
ExternalIDs = new[]
{
new MetadataID
{

View File

@ -14,6 +14,26 @@ namespace Kyoo.TheMovieDb
/// </summary>
public class PluginTmdb : IPlugin
{
/// <summary>
/// The configuration used to check if the api key is present or not.
/// </summary>
private readonly IConfiguration _configuration;
/// <summary>
/// Create a new <see cref="PluginTmdb"/>.
/// </summary>
/// <param name="configuration">The configuration used to check if the api key is present or not.</param>
/// <param name="logger">The logger used to warn when the api key is not present.</param>
public PluginTmdb(IConfiguration configuration, ILogger<PluginTmdb> logger)
{
_configuration = configuration;
if (!Enabled)
{
logger.LogWarning("No API key configured for TheMovieDB provider. " +
"To enable TheMovieDB, specify one in the setting the-moviedb:APIKEY ");
}
}
/// <inheritdoc />
public string Slug => "the-moviedb";
@ -32,24 +52,6 @@ namespace Kyoo.TheMovieDb
{ TheMovieDbOptions.Path, typeof(TheMovieDbOptions) }
};
/// <summary>
/// The configuration used to check if the api key is present or not.
/// </summary>
private readonly IConfiguration _configuration;
/// <summary>
/// Create a new <see cref="PluginTmdb"/>.
/// </summary>
/// <param name="configuration">The configuration used to check if the api key is present or not.</param>
/// <param name="logger">The logger used to warn when the api key is not present.</param>
public PluginTmdb(IConfiguration configuration, ILogger<PluginTmdb> logger)
{
_configuration = configuration;
if (!Enabled)
logger.LogWarning("No API key configured for TheMovieDB provider. " +
"To enable TheMovieDB, specify one in the setting the-moviedb:APIKEY ");
}
/// <inheritdoc />
public void Configure(ContainerBuilder builder)
{

26
Kyoo.ruleset Normal file
View File

@ -0,0 +1,26 @@
<RuleSet Name="Kyoo" ToolsVersion="10.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.CSharp.MaintainabilityRules">
<Rule Id="SA1413" Action="None" /> <!-- UseTrailingCommasInMultiLineInitializers -->
<Rule Id="SA1414" Action="None" /> <!-- UseTrailingCommasInMultiLineInitializers -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.CSharp.NamingRules">
<Rule Id="SA1309" Action="None" /> <!-- FieldNamesMustNotBeginWithUnderscore -->
<Rule Id="SX1309" Action="Warning" /> <!-- FieldNamesMustBeginWithUnderscore -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.CSharp.ReadabilityRules">
<Rule Id="SA1101" Action="None" /> <!-- PrefixLocalCallsWithThis -->
<Rule Id="SX1101" Action="Warning" /> <!-- DoNotPrefixLocalMembersWithThis -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.CSharp.SpacingRules">
<Rule Id="SA1502" Action="None"/> <!-- DocumentationLinesMustBeginWithSingleSpace -->
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.CSharp.DocumentationRules">
<Rule Id="SA1642" Action="None" /> <!-- ConstructorSummaryDocumentationMustBeginWithStandardText -->
<Rule Id="SA1643" Action="None" /> <!-- DestructorSummaryDocumentationMustBeginWithStandardText -->
<Rule Id="SA1623" Action="None" /> <!-- PropertySummaryDocumentationMustMatchAccessors -->
<Rule Id="SA1633" Action="None" /> <!-- FileMustHaveHeader TODO remove this, this is only temporary -->
</Rules>
</RuleSet>

6
stylecop.json Normal file
View File

@ -0,0 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
}
}