Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
chore: aesthetic changes
  • Loading branch information
DrSkillIssue committed Jul 19, 2025
commit 42d3cd075bd03ca55cbb2c3767e76fca71c34703
55 changes: 27 additions & 28 deletions Rules/UseConsistentWhitespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,37 +289,36 @@ private IEnumerable<DiagnosticRecord> FindKeywordAfterBraceViolations(TokenOpera
{
var keyword = keywordNode.Value;

if (keywordNode.Previous != null)
if (keywordNode.Previous == null || keywordNode.Previous.Value.Kind != TokenKind.RCurly)
{
if (keywordNode.Previous.Value.Kind == TokenKind.RCurly &&
IsPreviousTokenOnSameLine(keywordNode))
{
var hasWhitespace = IsPreviousTokenApartByWhitespace(keywordNode);
continue;
}

if (!hasWhitespace)
{
var corrections = new List<CorrectionExtent>
{
new CorrectionExtent(
keywordNode.Previous.Value.Extent.EndLineNumber,
keyword.Extent.StartLineNumber,
keywordNode.Previous.Value.Extent.EndColumnNumber,
keyword.Extent.StartColumnNumber,
whiteSpace,
keyword.Extent.File)
};

yield return new DiagnosticRecord(
GetError(ErrorKind.BeforeOpeningBrace),
keyword.Extent,
GetName(),
GetDiagnosticSeverity(),
tokenOperations.Ast.Extent.File,
null,
corrections);
}
}
if (!IsPreviousTokenOnSameLine(keywordNode) || IsPreviousTokenApartByWhitespace(keywordNode))
{
continue;
}

// Whitespace required
var corrections = new List<CorrectionExtent>
{
new CorrectionExtent(
keywordNode.Previous.Value.Extent.EndLineNumber,
keyword.Extent.StartLineNumber,
keywordNode.Previous.Value.Extent.EndColumnNumber,
keyword.Extent.StartColumnNumber,
whiteSpace,
keyword.Extent.File)
};

yield return new DiagnosticRecord(
GetError(ErrorKind.BeforeOpeningBrace),
keyword.Extent,
GetName(),
GetDiagnosticSeverity(),
tokenOperations.Ast.Extent.File,
null,
corrections);
}
}

Expand Down