LBPUnion / ProjectLighthouse

Project Lighthouse is a clean-room, open-source custom server for LittleBigPlanet.
GNU Affero General Public License v3.0
211 stars 53 forks source link

Refactor web-based comment deletion routine #1079

Closed sudokoko closed 2 weeks ago

sudokoko commented 2 weeks ago

This PR refactors the web comment deletion routine within ModerationRemovalController.cs by reworking how the notification text is determined, as well as adding handles for cases where the user is trying to delete comments on their own profile/level (this currently throws an exception in prod, it was never handled when notifications were implemented apparently).

Brings the cognitive complexity of the method down by about 30%, for those interested in that sort of thing.

github-actions[bot] commented 2 weeks ago

Qodana for .NET

1085 new problems were found

Inspection name Severity Problems
XML highlighting 🔴 Failure 8
Unresolved reference 🔴 Failure 4
Annotator 🔴 Failure 1
Possible performance issues caused by unlimited string length 🔶 Warning 74
Redundant nullable directive 🔶 Warning 60
Auto-property accessor is never used (non-private accessibility) 🔶 Warning 14
Path error 🔶 Warning 8
Missing required 'alt' attribute 🔶 Warning 6
Redundant using directive 🔶 Warning 5
Element is localizable 🔶 Warning 4
Unused schema declaration 🔶 Warning 4
Usage of navigational property can return incomplete data 🔶 Warning 3
RoslynAnalyzers Avoid using 'async void' for test methods as it is deprecated in xUnit.net v3 🔶 Warning 3
Conditional access qualifier expression is not null according to nullable reference types' annotations 🔶 Warning 2
Non-accessed field (private accessibility) 🔶 Warning 2
Specify string culture explicitly 🔶 Warning 2
Auto-property accessor is never used (private accessibility) 🔶 Warning 2
Unused nullable directive 🔶 Warning 2
Unknown HTML entity 🔶 Warning 1
Unused selector 🔶 Warning 1
Disposal of a variable already captured by the 'using' statement 🔶 Warning 1
Empty statement is redundant 🔶 Warning 1
Return value must be disposed but the method or function is not annotated with [MustDisposeResource] 🔶 Warning 1
Redundant cast 🔶 Warning 1
Redundant member initializer 🔶 Warning 1
Redundant nullable warning suppression expression 🔶 Warning 1
Do not use object initializer for 'using' variable 🔶 Warning 1
Property can be made init-only (non-private accessibility) ◽️ Notice 252
Use collection expression syntax ◽️ Notice 191
Convert constructor into primary constructor ◽️ Notice 135
Auto-property can be made get-only (non-private accessibility) ◽️ Notice 73
RoslynAnalyzers Do not use boolean asserts for simple equality tests ◽️ Notice 38
Type member is never used (non-private accessibility) ◽️ Notice 26
Member can be made private (non-private accessibility) ◽️ Notice 21
Add/remove 'this.' qualifier ◽️ Notice 14
Property can be made init-only (private accessibility) ◽️ Notice 12
Unresolved reference ◽️ Notice 10
Redundant type declaration body ◽️ Notice 8
Type is never used (non-private accessibility) ◽️ Notice 8
RoslynAnalyzers Use the 'StringComparison' method overloads to perform case-insensitive string comparisons ◽️ Notice 6
Important tags or attributes missing (<img> should specify alternative text) ◽️ Notice 6
Remove redundant parentheses ◽️ Notice 4
RoslynAnalyzers Avoid constant arrays as arguments ◽️ Notice 4
RoslynAnalyzers Use char overload ◽️ Notice 4
RoslynAnalyzers Instantiate argument exceptions correctly ◽️ Notice 4
Merge null/pattern/value checks into 'or'/'and' patterns ◽️ Notice 4
Use raw string ◽️ Notice 4
RoslynAnalyzers Use concrete types when possible for improved performance ◽️ Notice 3
Convert constructor into member initializers ◽️ Notice 3
Member can be made protected (non-private accessibility) ◽️ Notice 3
Unused parameter (non-private accessibility) ◽️ Notice 3
Use preferred style for trailing comma before new line in multiline lists ◽️ Notice 2
Class with virtual (overridable) members never inherited (non-private accessibility) ◽️ Notice 2
'if-return' statement can be rewritten as 'return' statement ◽️ Notice 2
Query can return incomplete data for related entities ◽️ Notice 2
Part of foreach loop can be converted into LINQ-expression but another 'GetEnumerator' method will be used ◽️ Notice 2
Merge null/pattern checks into complex pattern ◽️ Notice 2
Non-accessed field (non-private accessibility) ◽️ Notice 2
Unassigned field (non-private accessibility) ◽️ Notice 2
Mapped path ◽️ Notice 2
RoslynAnalyzers Suggest using IHeaderDictionary properties ◽️ Notice 1
Use preferred body style (convert into method or operator with preferred body style) ◽️ Notice 1
Auto-property can be made get-only (private accessibility) ◽️ Notice 1
RoslynAnalyzers Mark members as static ◽️ Notice 1
RoslynAnalyzers Prefer the 'IDictionary.TryGetValue(TKey, out TValue)' method ◽️ Notice 1
RoslynAnalyzers Avoid using 'Enumerable.Any()' extension method ◽️ Notice 1
RoslynAnalyzers Non-constant fields should not be visible ◽️ Notice 1
Dictionary lookup can be simplified with 'GetValueOrDefault' ◽️ Notice 1
Class is never instantiated (non-private accessibility) ◽️ Notice 1
'if' statement can be rewritten as '?:' expression ◽️ Notice 1
Member can be made static (shared) (non-private accessibility) ◽️ Notice 1
Method has async overload ◽️ Notice 1
Put local function after 'return' or 'continue' ◽️ Notice 1
Redundant empty argument list on object creation expression ◽️ Notice 1
Redundant string interpolation ◽️ Notice 1
Some values of the enum are not processed inside 'switch' statement and are handled via default section ◽️ Notice 1
Type member is never accessed via base type (non-private accessibility) ◽️ Notice 1
Method return value is never used (non-private accessibility) ◽️ Notice 1

☁️ View the detailed Qodana report

Detected 72 dependencies # Third-party software list This page lists the third-party software dependencies used in ProjectLighthouse | Dependency | Version | Licenses | |----------------------------------------------------------------------------------------------------------------------------------------|----------|-------------------------------------------------------------------------| | [BCrypt.Net-Next](https://www.nuget.org/packages/BCrypt.Net-Next) | 4.0.3 | [MIT](http://opensource.org/licenses/mit-license.php) | | [BouncyCastle.Cryptography](https://www.bouncycastle.org/stable/nuget/csharp/website) | 2.4.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Discord.Net.Core](https://github.com/Discord-Net/Discord.Net) | 3.15.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Discord.Net.Rest](https://github.com/Discord-Net/Discord.Net) | 3.15.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Discord.Net.Webhook](https://github.com/Discord-Net/Discord.Net) | 3.15.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [DistributedLock.Core](https://github.com/madelson/DistributedLock) | 1.0.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [DistributedLock.MySql](https://github.com/madelson/DistributedLock) | 1.0.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [GitInfo](https://clarius.org/GitInfo) | 3.3.5 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Humanizer.Core](https://github.com/Humanizr/Humanizer) | 2.14.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [JetBrains.Annotations](https://www.jetbrains.com/help/resharper/Code_Analysis__Code_Annotations.html) | 2023.3.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore](https://asp.net/) | 8.0.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Bcl.AsyncInterfaces](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.CSharp](https://github.com/dotnet/corefx) | 4.7.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.CodeAnalysis.Analyzers](https://github.com/dotnet/roslyn-analyzers) | 3.3.3 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.CodeAnalysis.CSharp.Workspaces](https://github.com/dotnet/roslyn) | 4.5.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.CodeAnalysis.CSharp](https://github.com/dotnet/roslyn) | 4.5.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.CodeAnalysis.Common](https://github.com/dotnet/roslyn) | 4.5.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.CodeAnalysis.Workspaces.Common](https://github.com/dotnet/roslyn) | 4.5.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.EntityFrameworkCore.Abstractions](https://docs.microsoft.com/ef/core/) | 8.0.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.EntityFrameworkCore.Analyzers](https://docs.microsoft.com/ef/core/) | 8.0.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.EntityFrameworkCore.Design](https://docs.microsoft.com/ef/core/) | 8.0.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.EntityFrameworkCore.Relational](https://docs.microsoft.com/ef/core/) | 8.0.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.EntityFrameworkCore](https://docs.microsoft.com/ef/core/) | 8.0.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.ApiDescription.Server](https://asp.net/) | 6.0.5 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.Caching.Abstractions](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.Caching.Memory](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.Configuration.Abstractions](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.DependencyInjection.Abstractions](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.DependencyInjection](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.DependencyModel](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.Logging.Abstractions](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.Logging](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.Options](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.Extensions.Primitives](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Microsoft.OpenApi](https://github.com/Microsoft/OpenAPI.NET) | 1.6.14 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Mono.TextTemplating](https://github.com/mono/t4) | 2.2.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [MySqlConnector](https://mysqlconnector.net/) | 2.3.5 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Newtonsoft.Json](https://www.newtonsoft.com/json) | 13.0.3 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Pfim](https://nickbabcock.github.io/Pfim/) | 0.11.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Pipelines.Sockets.Unofficial](https://github.com/mgravell/Pipelines.Sockets.Unofficial) | 2.2.8 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Pomelo.EntityFrameworkCore.MySql](https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql) | 8.0.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [QRCoder](https://github.com/codebude/QRCoder/) | 1.5.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Redis.OM](https://github.com/redis/redis-om-dotnet) | 0.7.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [SharpZipLib](https://github.com/icsharpcode/SharpZipLib) | 1.4.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [SixLabors.ImageSharp](https://github.com/SixLabors/ImageSharp) | 3.1.5 | [Apache-2.0](http://www.apache.org/licenses/)
PROPRIETARY-LICENSE | | [StackExchange.Redis](https://stackexchange.github.io/StackExchange.Redis/) | 2.7.17 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Swashbuckle.AspNetCore.Swagger](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) | 6.6.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Swashbuckle.AspNetCore.SwaggerGen](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) | 6.6.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Swashbuckle.AspNetCore.SwaggerUI](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) | 6.6.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Swashbuckle.AspNetCore](https://github.com/domaindrivendev/Swashbuckle.AspNetCore) | 6.6.2 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.CodeDom](https://dot.net/) | 4.4.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Collections.Immutable](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Composition.AttributedModel](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Composition.Convention](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Composition.Hosting](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Composition.Runtime](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Composition.TypedParts](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Composition](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.IO.Pipelines](https://dot.net/) | 6.0.3 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Interactive.Async](https://github.com/dotnet/reactive) | 6.0.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Linq.Async](https://github.com/dotnet/reactive) | 6.0.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Reflection.Metadata](https://dot.net/) | 6.0.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Runtime.CompilerServices.Unsafe](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Text.Encoding.CodePages](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Text.Encodings.Web](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Text.Json](https://dot.net/) | 8.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Threading.Channels](https://dot.net/) | 6.0.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.Threading.Tasks.Extensions](https://dot.net/) | 4.5.4 | [MIT](http://opensource.org/licenses/mit-license.php) | | [System.ValueTuple](https://dot.net/) | 4.5.0 | [MIT](http://opensource.org/licenses/mit-license.php) | | [ThisAssembly.Constants](https://clarius.org/ThisAssembly) | 1.4.1 | [MIT](http://opensource.org/licenses/mit-license.php) | | [Ulid](https://github.com/Cysharp/Ulid) | 1.2.6 | [MIT](http://opensource.org/licenses/mit-license.php) | | [YamlDotNet](https://github.com/aaubry/YamlDotNet/wiki) | 15.1.6 | [MIT](http://opensource.org/licenses/mit-license.php) |
Contact Qodana team Contact us at [qodana-support@jetbrains.com](mailto:qodana-support@jetbrains.com) - Or via our issue tracker: https://jb.gg/qodana-issue - Or share your feedback: https://jb.gg/qodana-discussions