Skip to content
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

Fixed issue in SA1500CodeFixProvider with brace at the end of the sou… #2106

Merged
merged 1 commit into from
Mar 17, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private static Dictionary<SyntaxToken, SyntaxToken> GenerateBraceFixes(Document
var indentationSteps = DetermineIndentationSteps(indentationSettings, braceToken);

var previousToken = braceToken.GetPreviousToken();
var nextToken = braceToken.GetNextToken();

if (IsAccessorWithSingleLineBlock(previousToken, braceToken))
{
Expand Down Expand Up @@ -106,9 +105,13 @@ private static Dictionary<SyntaxToken, SyntaxToken> GenerateBraceFixes(Document
braceReplacementToken = braceReplacementToken.WithLeadingTrivia(IndentationHelper.GenerateWhitespaceTrivia(indentationSettings, indentationSteps));
}

// Check if we need to apply a fix after the brace
// if a closing brace is followed by a semi-colon or closing paren, no fix is needed.
if ((LocationHelpers.GetLineSpan(nextToken).StartLinePosition.Line == braceLine) &&
// Check if we need to apply a fix after the brace. No fix is needed when:
// - The closing brace is followed by a semi-colon or closing paren
// - The closing brace is the last token in the file
var nextToken = braceToken.GetNextToken();
var nextTokenLine = nextToken.IsKind(SyntaxKind.None) ? -1 : LocationHelpers.GetLineSpan(nextToken).StartLinePosition.Line;

if ((nextTokenLine == braceLine) &&
(!braceToken.IsKind(SyntaxKind.CloseBraceToken) || !IsValidFollowingToken(nextToken)))
{
var sharedTrivia = nextToken.LeadingTrivia.WithoutTrailingWhitespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,33 @@ namespace InvalidNamespace6
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
}

/// <summary>
/// Verifies that an invalid namespace at the end of the source file will be handled correctly.
/// </summary>
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
[Fact]
public async Task TestNamespaceInvalidAtEndOfFileAsync()
{
var testCode = @"
namespace TestNamespace
{
using System; }";

var fixedTestCode = @"
namespace TestNamespace
{
using System;
}";

DiagnosticResult[] expectedDiagnostics =
{
this.CSharpDiagnostic().WithLocation(4, 17),
};

await this.VerifyCSharpDiagnosticAsync(testCode, expectedDiagnostics, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedTestCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedTestCode).ConfigureAwait(false);
}
}
}