Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

Commit

Permalink
#115: Remove reduntant parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarypiatek committed Oct 31, 2020
1 parent 86c6861 commit 974fe6b
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 115 deletions.
72 changes: 72 additions & 0 deletions MappingGenerator/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,75 @@ dotnet_diagnostic.CA2012.severity = error

# CA2247: Argument passed to TaskCompletionSource constructor should be TaskCreationOptions enum instead of TaskContinuationOptions enum
dotnet_diagnostic.CA2247.severity = error

# CA1822: Mark members as static
dotnet_diagnostic.CA1822.severity = none

# CA1801: Review unused parameters
dotnet_diagnostic.CA1801.severity = error

# VSTHRD114: Avoid returning a null Task
dotnet_diagnostic.VSTHRD114.severity = error

# VSTHRD101: Avoid unsupported async delegates
dotnet_diagnostic.VSTHRD101.severity = error

# VSTHRD106: Use InvokeAsync to raise async events
dotnet_diagnostic.VSTHRD106.severity = error

# VSTHRD111: Use ConfigureAwait(bool)
dotnet_diagnostic.VSTHRD111.severity = error

# VSTHRD113: Check for System.IAsyncDisposable
dotnet_diagnostic.VSTHRD113.severity = error

# VSTHRD100: Avoid async void methods
dotnet_diagnostic.VSTHRD100.severity = error

# VSTHRD001: Avoid legacy thread switching APIs
dotnet_diagnostic.VSTHRD001.severity = error

# VSTHRD002: Avoid problematic synchronous waits
dotnet_diagnostic.VSTHRD002.severity = error

# VSTHRD003: Avoid awaiting foreign Tasks
dotnet_diagnostic.VSTHRD003.severity = error

# VSTHRD004: Await SwitchToMainThreadAsync
dotnet_diagnostic.VSTHRD004.severity = error

# VSTHRD010: Invoke single-threaded types on Main thread
dotnet_diagnostic.VSTHRD010.severity = error

# VSTHRD011: Use AsyncLazy<T>
dotnet_diagnostic.VSTHRD011.severity = error

# VSTHRD012: Provide JoinableTaskFactory where allowed
dotnet_diagnostic.VSTHRD012.severity = error

# VSTHRD102: Implement internal logic asynchronously
dotnet_diagnostic.VSTHRD102.severity = error

# VSTHRD103: Call async methods when in an async method
dotnet_diagnostic.VSTHRD103.severity = error

# VSTHRD104: Offer async methods
dotnet_diagnostic.VSTHRD104.severity = error

# VSTHRD105: Avoid method overloads that assume TaskScheduler.Current
dotnet_diagnostic.VSTHRD105.severity = error

# VSTHRD107: Await Task within using expression
dotnet_diagnostic.VSTHRD107.severity = error

# VSTHRD108: Assert thread affinity unconditionally
dotnet_diagnostic.VSTHRD108.severity = error

# VSTHRD109: Switch instead of assert in async methods
dotnet_diagnostic.VSTHRD109.severity = error

# VSTHRD110: Observe result of async calls
dotnet_diagnostic.VSTHRD110.severity = error

# VSTHRD112: Implement System.IAsyncDisposable
dotnet_diagnostic.VSTHRD112.severity = error
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)

private async Task<Document> GenerateExplicitConversion(Document document, AssignmentExpressionSyntax assignmentExpression, CancellationToken cancellationToken)
{
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, assignmentExpression, cancellationToken).ConfigureAwait(false);
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, cancellationToken).ConfigureAwait(false);
var sourceType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Right).GetAnnotatedType();
var destinationType = mappingEngine.GetExpressionTypeInfo(assignmentExpression.Left).GetAnnotatedType();
var mappingExpression = mappingEngine.MapExpression(assignmentExpression.Right.WithoutTrivia(), sourceType, destinationType, new MappingContext(assignmentExpression, semanticModel));
return await ReplaceNode(document, assignmentExpression, assignmentExpression.WithRight(mappingExpression), cancellationToken).ConfigureAwait(false);
}

private static async Task<(MappingEngine, SemanticModel)> CreateMappingEngine(Document document, SyntaxNode node, CancellationToken cancellationToken)
private static async Task<(MappingEngine, SemanticModel)> CreateMappingEngine(Document document, CancellationToken cancellationToken)
{
var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var mappingEngine = await MappingEngine.Create(document, cancellationToken).ConfigureAwait(false);
Expand All @@ -72,15 +72,15 @@ private async Task<Document> GenerateExplicitConversion(Document document, Assig

private async Task<Document> GenerateExplicitConversion(Document document, ReturnStatementSyntax returnStatement, CancellationToken cancellationToken)
{
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, returnStatement, cancellationToken).ConfigureAwait(false);
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, cancellationToken).ConfigureAwait(false);
var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(returnStatement.Expression);
var mappingExpression = mappingEngine.MapExpression(returnStatement.Expression!.WithoutTrivia(), returnExpressionTypeInfo.GetAnnotatedType(), returnExpressionTypeInfo.GetAnnotatedTypeForConverted(), new MappingContext(returnStatement, semanticModel));
return await ReplaceNode(document, returnStatement, returnStatement.WithExpression(mappingExpression), cancellationToken).ConfigureAwait(false);
}

private async Task<Document> GenerateExplicitConversion(Document document, YieldStatementSyntax yieldStatement, CancellationToken cancellationToken)
{
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, yieldStatement, cancellationToken).ConfigureAwait(false);
var (mappingEngine, semanticModel) = await CreateMappingEngine(document, cancellationToken).ConfigureAwait(false);
var returnExpressionTypeInfo = mappingEngine.GetExpressionTypeInfo(yieldStatement.Expression);
var mappingExpression = mappingEngine.MapExpression(yieldStatement.Expression!.WithoutTrivia(), returnExpressionTypeInfo.GetAnnotatedType(), returnExpressionTypeInfo.GetAnnotatedTypeForConverted(), new MappingContext(yieldStatement, semanticModel));
return await ReplaceNode(document, yieldStatement, yieldStatement.WithExpression(mappingExpression), cancellationToken).ConfigureAwait(false);
Expand All @@ -95,18 +95,14 @@ private static async Task<Document> ReplaceNode(Document document, SyntaxNode ol

private SyntaxNode FindStatementToReplace(SyntaxNode node)
{
switch (node)
return node switch
{
//TODO EqualsValueClauseSyntax - Type1 v = vOfType2
case AssignmentExpressionSyntax assignmentStatement:
return assignmentStatement;
case ReturnStatementSyntax returnStatement:
return returnStatement;
case YieldStatementSyntax yieldStatement:
return yieldStatement;
default:
return node.Parent == null? null: FindStatementToReplace(node.Parent);
}
AssignmentExpressionSyntax assignmentStatement => assignmentStatement,
ReturnStatementSyntax returnStatement => returnStatement,
YieldStatementSyntax yieldStatement => yieldStatement,
_ => node.Parent == null ? null : FindStatementToReplace(node.Parent),
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.7.56" />
<PackageReference Include="Pluralize.NET" Version="0.1.84" PrivateAssets="all" />
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 974fe6b

Please sign in to comment.