Skip to content

Commit

Permalink
Apply suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink committed Aug 9, 2020
1 parent f83f93e commit d9302b6
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,18 +501,22 @@ private static void AnalyzeTitle(

private static void AnalyzeTitleCore(string title, IArgumentOperation argumentOperation, Location fixLocation, Action<Diagnostic> reportDiagnostic)
{
var hasLeadingOrTrailingWhitespaces = HasLeadingOrTrailingWhitespaces(title);
if (hasLeadingOrTrailingWhitespaces)
{
title = RemoveLeadingAndTrailingWhitespaces(title);
}

var isMultiSentences = IsMultiSentences(title);
var endsWithPeriod = EndsWithPeriod(title);
var containsLineReturn = ContainsLineReturn(title);
var hasLeadingOrTrailingWhitespaces = HasLeadingOrTrailingWhitespaces(title);

if (isMultiSentences || endsWithPeriod || containsLineReturn || hasLeadingOrTrailingWhitespaces)
{
// Leading and trailing spaces were already fixed
var fixedTitle = endsWithPeriod ? RemoveTrailingPeriod(title) : title;
fixedTitle = isMultiSentences ? FixMultiSentences(fixedTitle) : fixedTitle;
fixedTitle = containsLineReturn ? FixLineReturns(fixedTitle, allowMultisentences: false) : fixedTitle;
fixedTitle = hasLeadingOrTrailingWhitespaces ? RemoveLeadingAndTrailingWhitespaces(fixedTitle) : fixedTitle;
Debug.Assert(title != fixedTitle);

ReportDefineDiagnosticArgumentCorrectlyDiagnostic(DefineDiagnosticTitleCorrectlyRule,
argumentOperation, fixedTitle, fixLocation, reportDiagnostic);
Expand Down Expand Up @@ -594,13 +598,19 @@ private static void AnalyzeMessage(

private static void AnalyzeMessageCore(string message, IArgumentOperation argumentOperation, Location fixLocation, Action<Diagnostic> reportDiagnostic)
{
var hasLeadingOrTrailingWhitespaces = HasLeadingOrTrailingWhitespaces(message);
if (hasLeadingOrTrailingWhitespaces)
{
message = RemoveLeadingAndTrailingWhitespaces(message);
}

var isMultiSentences = IsMultiSentences(message);
var endsWithPeriod = EndsWithPeriod(message);
var containsLineReturn = ContainsLineReturn(message);
var hasLeadingOrTrailingWhitespaces = HasLeadingOrTrailingWhitespaces(message);

if (isMultiSentences ^ endsWithPeriod || containsLineReturn || hasLeadingOrTrailingWhitespaces)
{
// Leading and trailing spaces were already fixed
var fixedMessage = containsLineReturn ? FixLineReturns(message, allowMultisentences: true) : message;
isMultiSentences = IsMultiSentences(fixedMessage);
endsWithPeriod = EndsWithPeriod(fixedMessage);
Expand All @@ -610,8 +620,6 @@ private static void AnalyzeMessageCore(string message, IArgumentOperation argume
fixedMessage = endsWithPeriod ? RemoveTrailingPeriod(fixedMessage) : fixedMessage + ".";
}

fixedMessage = hasLeadingOrTrailingWhitespaces ? RemoveLeadingAndTrailingWhitespaces(fixedMessage) : fixedMessage;

ReportDefineDiagnosticArgumentCorrectlyDiagnostic(DefineDiagnosticMessageCorrectlyRule,
argumentOperation, fixedMessage, fixLocation, reportDiagnostic);
}
Expand All @@ -638,12 +646,16 @@ private static void AnalyzeDescription(
private static void AnalyzeDescriptionCore(string description, IArgumentOperation argumentOperation, Location fixLocation, Action<Diagnostic> reportDiagnostic)
{
var hasLeadingOrTrailingWhitespaces = HasLeadingOrTrailingWhitespaces(description);
if (hasLeadingOrTrailingWhitespaces)
{
description = RemoveLeadingAndTrailingWhitespaces(description);
}

var endsWithPunctuation = EndsWithPunctuation(description);

if (!endsWithPunctuation || hasLeadingOrTrailingWhitespaces)
{
var fixedDescription = !endsWithPunctuation ? description + "." : description;
fixedDescription = hasLeadingOrTrailingWhitespaces ? RemoveLeadingAndTrailingWhitespaces(fixedDescription) : fixedDescription;

ReportDefineDiagnosticArgumentCorrectlyDiagnostic(DefineDiagnosticDescriptionCorrectlyRule,
argumentOperation, fixedDescription, fixLocation, reportDiagnostic);
Expand Down
Loading

0 comments on commit d9302b6

Please sign in to comment.