Skip to content
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
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);
}
");
}
}