-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to suppress diagnostic from Unity script methods (RCS1213) (…
…fix #585).
- Loading branch information
1 parent
62786df
commit 16d2766
Showing
7 changed files
with
210 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/Analyzers/CSharp/Analysis/UnusedMember/UnityScriptMethods.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Immutable; | ||
using System.Threading; | ||
|
||
namespace Roslynator.CSharp.Analysis.UnusedMember | ||
{ | ||
internal static class UnityScriptMethods | ||
{ | ||
private static ImmutableHashSet<string> _methodNames; | ||
|
||
public static MetadataName MonoBehaviourClassName { get; } = MetadataName.Parse("UnityEngine.MonoBehaviour"); | ||
|
||
public static ImmutableHashSet<string> MethodNames | ||
{ | ||
get | ||
{ | ||
if (_methodNames == null) | ||
Interlocked.CompareExchange(ref _methodNames, LoadMethodNames(), null); | ||
|
||
return _methodNames; | ||
} | ||
} | ||
|
||
private static ImmutableHashSet<string> LoadMethodNames() | ||
{ | ||
return ImmutableHashSet.CreateRange(new[] { | ||
"Awake", | ||
"FixedUpdate", | ||
"LateUpdate", | ||
"OnAnimatorIK", | ||
"OnAnimatorMove", | ||
"OnApplicationFocus", | ||
"OnApplicationPause", | ||
"OnApplicationQuit", | ||
"OnAudioFilterRead", | ||
"OnBecameInvisible", | ||
"OnBecameVisible", | ||
"OnCollisionEnter", | ||
"OnCollisionEnter2D", | ||
"OnCollisionExit", | ||
"OnCollisionExit2D", | ||
"OnCollisionStay", | ||
"OnCollisionStay2D", | ||
"OnConnectedToServer", | ||
"OnControllerColliderHit", | ||
"OnDestroy", | ||
"OnDisable", | ||
"OnDisconnectedFromServer", | ||
"OnDrawGizmos", | ||
"OnDrawGizmosSelected", | ||
"OnEnable", | ||
"OnFailedToConnect", | ||
"OnFailedToConnectToMasterServer", | ||
"OnGUI", | ||
"OnJointBreak", | ||
"OnJointBreak2D", | ||
"OnMasterServerEvent", | ||
"OnMouseDown", | ||
"OnMouseDrag", | ||
"OnMouseEnter", | ||
"OnMouseExit", | ||
"OnMouseOver", | ||
"OnMouseUp", | ||
"OnMouseUpAsButton", | ||
"OnNetworkInstantiate", | ||
"OnParticleCollision", | ||
"OnParticleSystemStopped", | ||
"OnParticleTrigger", | ||
"OnParticleUpdateJobScheduled", | ||
"OnPlayerConnected", | ||
"OnPlayerDisconnected", | ||
"OnPostRender", | ||
"OnPreCull", | ||
"OnPreRender", | ||
"OnRenderImage", | ||
"OnRenderObject", | ||
"OnSerializeNetworkView", | ||
"OnServerInitialized", | ||
"OnTransformChildrenChanged", | ||
"OnTransformParentChanged", | ||
"OnTriggerEnter", | ||
"OnTriggerEnter2D", | ||
"OnTriggerExit", | ||
"OnTriggerExit2D", | ||
"OnTriggerStay", | ||
"OnTriggerStay2D", | ||
"OnValidate", | ||
"OnWillRenderObject", | ||
"Reset", | ||
"Start", | ||
"Update", | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Roslynator.CSharp | ||
{ | ||
internal static class EditorConfigIdentifiers | ||
{ | ||
public static readonly string SuppressUnityScriptMethods | ||
= $"roslynator.{DiagnosticIdentifiers.RemoveUnusedMemberDeclaration}.suppress_unity_script_methods"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) Josef Pihrt. All rights reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
|
||
namespace Roslynator | ||
{ | ||
internal static class EditorConfigOptions | ||
{ | ||
public static bool IsTrue( | ||
SyntaxNodeAnalysisContext context, | ||
SyntaxTree syntaxTree, | ||
string key) | ||
{ | ||
return TryGetValue(context, syntaxTree, key, out bool value) | ||
&& value; | ||
} | ||
|
||
public static bool TryGetValue( | ||
SyntaxNodeAnalysisContext context, | ||
SyntaxTree syntaxTree, | ||
string key, | ||
out bool value) | ||
{ | ||
if (context | ||
.Options | ||
.AnalyzerConfigOptionsProvider | ||
.GetOptions(syntaxTree) | ||
.TryGetValue(key, out string valueText) | ||
&& bool.TryParse(valueText, out value)) | ||
{ | ||
return true; | ||
} | ||
|
||
value = false; | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters