-
Notifications
You must be signed in to change notification settings - Fork 3
Cover WTG1001 on edge cases #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,17 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <diagnostics severity="Hidden"> | ||
| <languageVersion>9.0</languageVersion> | ||
| <suppressId justtification="To ignore when only one method in one class have the code fix removing 'private' applied.">CS8799</suppressId> | ||
| <diagnostic id="WTG1001" message="Our convention is to omit the 'private' modifier where it is already the default."> | ||
| <location>Test0.cs: (15,3-10)</location> | ||
| <location>Test0.cs: (9,3-10)</location> | ||
| </diagnostic> | ||
| <diagnostic id="WTG1001" message="Our convention is to omit the 'private' modifier where it is already the default."> | ||
| <location>Test0.cs: (19,3-10)</location> | ||
| </diagnostic> | ||
| <diagnostic id="WTG1001" message="Our convention is to omit the 'private' modifier where it is already the default."> | ||
| <location>Test0.cs: (25,3-10)</location> | ||
| </diagnostic> | ||
| <diagnostic id="WTG1006" message="Our convention is to omit the 'internal' modifier on types where it is already the default." > | ||
| <location>Test0.cs: (20,2-10)</location> | ||
| <location>Test0.cs: (30,2-10)</location> | ||
| </diagnostic> | ||
| </diagnostics> | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,11 +3,21 @@ namespace ns | |||||
| partial class Foo | ||||||
| { | ||||||
| private partial int Bar(); | ||||||
| public partial void FooBar(); | ||||||
| private partial int FooBarBaz(out int value); | ||||||
|
|
||||||
| private partial void Qux(); | ||||||
| private partial void Quux(out int value); | ||||||
| } | ||||||
|
|
||||||
| partial class Foo | ||||||
| { | ||||||
| private partial int Bar() { return default; } | ||||||
| public partial void FooBar() { } | ||||||
| private partial int FooBarBaz(out int value) { value = default; return default; } | ||||||
|
||||||
| private partial int FooBarBaz(out int value) { value = default; return default; } | |
| private partial int FooBarBaz(out int value) => throw null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll apply this.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,8 @@ | ||||||
| using System.Collections.Immutable; | ||||||
| using System.Linq; | ||||||
| using Microsoft.CodeAnalysis; | ||||||
| using Microsoft.CodeAnalysis.CSharp; | ||||||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||||||
| using Microsoft.CodeAnalysis.Diagnostics; | ||||||
| using WTG.Analyzers.Utils; | ||||||
|
|
||||||
|
|
@@ -32,7 +34,8 @@ static void Analyze(SyntaxNodeAnalysisContext context, FileDetailCache cache) | |||||
| return; | ||||||
| } | ||||||
|
|
||||||
| var list = ModifierExtractionVisitor.Instance.Visit(context.Node); | ||||||
| var currentNode = context.Node; | ||||||
| var list = ModifierExtractionVisitor.Instance.Visit(currentNode); | ||||||
| var privateToken = default(SyntaxToken); | ||||||
|
|
||||||
| foreach (var modifier in list) | ||||||
|
|
@@ -47,11 +50,10 @@ static void Analyze(SyntaxNodeAnalysisContext context, FileDetailCache cache) | |||||
|
|
||||||
| case SyntaxKind.ProtectedKeyword: | ||||||
| case SyntaxKind.PublicKeyword: | ||||||
| case SyntaxKind.PartialKeyword when (context.Node.IsKind(SyntaxKind.MethodDeclaration)): | ||||||
| case SyntaxKind.PartialKeyword when (DoesMethodHaveReturnValueOrOutKeyword(currentNode)): | ||||||
|
||||||
| case SyntaxKind.PartialKeyword when (DoesMethodHaveReturnValueOrOutKeyword(currentNode)): | |
| case SyntaxKind.PartialKeyword when (PartialMethodRequiresAccessibilityModifier(currentNode)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll apply the name as suggested.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a Kind check we can perform on methodNode.ReturnType before turning to runtime type casts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the same as Kind check for var methodNode = (MethodDeclarationSyntax)node;, e.g.
if (methodNode.ReturnType.IsKind(SyntaxKind.PredefinedType))
{
var returnType = (PredefinedTypeSyntax)methodNode.ReturnType;
if (!returnType.Keyword.IsKind(SyntaxKind.VoidKeyword))
{
return true;
}
}
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (methodNode.ParameterList?.Parameters.Any(c => c.Modifiers.Any(SyntaxKind.OutKeyword)) == true) | |
| if (methodNode.ParameterList?.Parameters.Any(static c => c.Modifiers.Any(SyntaxKind.OutKeyword)) == true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll apply this.
Uh oh!
There was an error while loading. Please reload this page.