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(); void Restart();
/// <summary> /// <summary>
/// Get the data directory /// Get the data directory.
/// </summary> /// </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(); string GetDataDirectory();
/// <summary> /// <summary>

View File

@ -14,10 +14,10 @@ namespace Kyoo.Abstractions.Controllers
public interface IConfigurationManager public interface IConfigurationManager
{ {
/// <summary> /// <summary>
/// Add an editable configuration to the editable configuration list /// Add an editable configuration to the editable configuration list.
/// </summary> /// </summary>
/// <param name="path">The root path of the editable configuration. It should not be a nested type.</param> /// <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); void AddTyped<T>(string path);
/// <summary> /// <summary>
@ -40,28 +40,29 @@ namespace Kyoo.Abstractions.Controllers
/// <summary> /// <summary>
/// Get the value of a setting using it's path. /// Get the value of a setting using it's path.
/// </summary> /// </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> /// <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); object GetValue(string path);
/// <summary> /// <summary>
/// Get the value of a setting using it's path. /// Get the value of a setting using it's path.
/// If your don't need a strongly typed value, see <see cref="GetValue"/>. /// If your don't need a strongly typed value, see <see cref="GetValue"/>.
/// </summary> /// </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> /// <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> /// <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); T GetValue<T>(string path);
/// <summary> /// <summary>
/// Edit the value of a setting using it's path. Save it to the json file. /// Edit the value of a setting using it's path. Save it to the json file.
/// </summary> /// </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>
/// <param name="value">The new value of the resource</param> /// <param name="value">The new value of the resource.</param>
/// <exception cref="ItemNotFoundException">No setting found at the given path.</exception> /// <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); Task EditValue(string path, object value);
} }
} }

View File

@ -8,7 +8,8 @@ using Microsoft.AspNetCore.Mvc;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers
{ {
/// <summary> /// <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> /// </summary>
public interface IFileSystem public interface IFileSystem
{ {
@ -16,7 +17,7 @@ namespace Kyoo.Abstractions.Controllers
/// <summary> /// <summary>
/// Used for http queries returning a file. This should be used to return local files /// 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> /// </summary>
/// <remarks> /// <remarks>
/// If no file exists at the given path or if the path is null, a NotFoundResult is returned /// 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 System.Threading.Tasks;
using Kyoo.Abstractions.Models;
namespace Kyoo.Abstractions.Controllers namespace Kyoo.Abstractions.Controllers
{ {

View File

@ -10,12 +10,6 @@
<LangVersion>default</LangVersion> <LangVersion>default</LangVersion>
</PropertyGroup> </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> <PropertyGroup>
<TranscoderBinary Condition="$(IsWindows) == true">transcoder.dll</TranscoderBinary> <TranscoderBinary Condition="$(IsWindows) == true">transcoder.dll</TranscoderBinary>
<TranscoderBinary Condition="$(IsOSX) == true">libtranscoder.dylib</TranscoderBinary> <TranscoderBinary Condition="$(IsOSX) == true">libtranscoder.dylib</TranscoderBinary>

View File

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

View File

@ -1,8 +1,4 @@
<Project> <Project>
<PropertyGroup>
<IsWindows Condition="$([MSBuild]::IsOSPlatform('Windows'))">true</IsWindows>
</PropertyGroup>
<Import Project="Kyoo.Host.WindowsTrait.target" Condition="$(IsWindows) == true" /> <Import Project="Kyoo.Host.WindowsTrait.target" Condition="$(IsWindows) == true" />
<Import Project="Kyoo.Host.WindowsTrait.linux.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.People;
using TMDbLib.Objects.Search; using TMDbLib.Objects.Search;
using Images = Kyoo.Abstractions.Models.Images; using Images = Kyoo.Abstractions.Models.Images;
using TvCast = TMDbLib.Objects.TvShows.Cast;
using MovieCast = TMDbLib.Objects.Movies.Cast; using MovieCast = TMDbLib.Objects.Movies.Cast;
using TvCast = TMDbLib.Objects.TvShows.Cast;
namespace Kyoo.TheMovieDb namespace Kyoo.TheMovieDb
{ {

View File

@ -14,6 +14,26 @@ namespace Kyoo.TheMovieDb
/// </summary> /// </summary>
public class PluginTmdb : IPlugin 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 /> /// <inheritdoc />
public string Slug => "the-moviedb"; public string Slug => "the-moviedb";
@ -32,24 +52,6 @@ namespace Kyoo.TheMovieDb
{ TheMovieDbOptions.Path, typeof(TheMovieDbOptions) } { 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 /> /// <inheritdoc />
public void Configure(ContainerBuilder builder) 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": {
}
}