Skip to content

Commit

Permalink
Fix Unity method detection (#1586)
Browse files Browse the repository at this point in the history
  • Loading branch information
josefpihrt authored Nov 23, 2024
1 parent 6210e73 commit 8d47d71
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Fix analyzer [RCS1213](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1213) ([PR](https://github.com/dotnet/roslynator/pull/1586))

## [4.12.9] - 2024-10-25

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ private static void AnalyzeTypeDeclaration(SyntaxNodeAnalysisContext context)
if (IsMainMethod(declaration, modifiers, methodName))
break;

if (declaration.ReturnsVoid()
if ((declaration.ReturnsVoid()
|| (methodName == "Start"
&& semanticModel.GetDeclaredSymbol(declaration, cancellationToken)?.ReturnType.SpecialType == SpecialType.System_Collections_IEnumerator))
&& context.IsUnityCodeAnalysisEnabled() == true)
{
if (canContainUnityScriptMethods is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,30 @@ private void Awake()
}
}
namespace UnityEngine
{
class MonoBehaviour
{
}
}
", options: Options.AddConfigOption(ConfigOptionKeys.UnityCodeAnalysisEnabled, true));
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.RemoveUnusedMemberDeclaration)]
public async Task TestNoDiagnostic_UnityScriptMethods_Start()
{
await VerifyNoDiagnosticAsync(@"
using System.Collections;
using UnityEngine;
class C : MonoBehaviour
{
private IEnumerator Start()
{
yield break;
}
}
namespace UnityEngine
{
class MonoBehaviour
Expand Down

0 comments on commit 8d47d71

Please sign in to comment.