Skip to content

Commit

Permalink
Do not remove overriding member in record (RCS1132) (#1015)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Dec 17, 2022
1 parent 52a35d3 commit 6eb7c3c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix [RCS1244](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1244.md) ([#1007](https://github.com/josefpihrt/roslynator/pull/1007)).
- [CLI] Add nullable reference type modifier when creating a list of symbols (`list-symbols` command) ([#1013](https://github.com/josefpihrt/roslynator/pull/1013)).
- Add/remove blank line after file scoped namespace declaration ([RCS0060](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS0060.md)) ([#1014](https://github.com/josefpihrt/roslynator/pull/1014)).
- Do not remove overriding member in record ([RCS1132](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1132.md)) ([#1015](https://github.com/josefpihrt/roslynator/pull/1015)).

## [4.2.0] - 2022-11-27

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ private static void AnalyzeMethodDeclaration(SyntaxNodeAnalysisContext context)
if (!SymbolEqualityComparer.Default.Equals(overriddenMethod, symbol))
return;

if (symbol.ContainingType?.IsRecord == true)
{
switch (symbol.Name)
{
case "ToString":
case "PrintMembers":
case "GetHashCode":
return;
}
}

if (!CheckParameters(methodDeclaration.ParameterList, invocationInfo.ArgumentList, semanticModel, cancellationToken))
return;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) Josef Pihrt and Contributors. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Roslynator.CSharp.CodeFixes;
using Roslynator.Testing.CSharp;
using Xunit;

namespace Roslynator.CSharp.Analysis.Tests;

public class RCS1132RemoveRedundantOverridingMemberTests : AbstractCSharpDiagnosticVerifier<RemoveRedundantOverridingMemberAnalyzer, MemberDeclarationCodeFixProvider>
{
public override DiagnosticDescriptor Descriptor { get; } = DiagnosticRules.RemoveRedundantOverridingMember;

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.RemoveRedundantOverridingMember)]
public async Task TestNoDiagnostic_Record()
{
await VerifyNoDiagnosticAsync(@"
using System;
using System.Text;
public record IntPoint(int X, int Y)
{
public override string ToString() => $""[{X}, {Y}]"";
}
public record IntPointWithValue<T>(T value, int X, int Y) : IntPoint(X, Y)
{
public override string ToString() => base.ToString();
public override int GetHashCode() => base.GetHashCode();
protected override bool PrintMembers(StringBuilder builder) => base.PrintMembers(builder);
}
");
}
}

0 comments on commit 6eb7c3c

Please sign in to comment.