Skip to content

Commit

Permalink
Remove trailing whitespaces from generated editorconfig (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored May 14, 2024
1 parent c943f7c commit 38c8e85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ dotnet_diagnostic.CA5400.severity = none
# Enabled: False, Severity: warning
dotnet_diagnostic.CA5401.severity = warning

# CA5402: Use CreateEncryptor with the default IV
# CA5402: Use CreateEncryptor with the default IV
# Help link: https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca5402
# Enabled: False, Severity: warning
dotnet_diagnostic.CA5402.severity = warning
Expand Down
10 changes: 6 additions & 4 deletions tools/ConfigurationFilesGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ await Parallel.ForEachAsync(packages, async (item, cancellationToken) =>
var currentRuleConfiguration = currentConfiguration.Rules.FirstOrDefault(r => r.Id == rule.Id);
var severity = currentRuleConfiguration != null ? currentRuleConfiguration.Severity : rule.DefaultEffectiveSeverity;

sb.AppendLine($"# {rule.Id}: {rule.Title}");
sb.AppendLine($"# {rule.Id}: {rule.Title?.TrimEnd()}");
if (!string.IsNullOrEmpty(rule.Url))
{
sb.AppendLine($"# Help link: {rule.Url}");
sb.AppendLine($"# Help link: {rule.Url?.TrimEnd()}");
}

sb.AppendLine($"# Enabled: {rule.Enabled}, Severity: {GetSeverity(rule.DefaultSeverity)}");
Expand All @@ -92,16 +92,18 @@ await Parallel.ForEachAsync(packages, async (item, cancellationToken) =>
sb.AppendLine();
}

var text = sb.ToString().ReplaceLineEndings("\n");

if (File.Exists(configurationFilePath))
{
if ((await File.ReadAllTextAsync(configurationFilePath, cancellationToken)).ReplaceLineEndings() == sb.ToString().ReplaceLineEndings())
if ((await File.ReadAllTextAsync(configurationFilePath, cancellationToken)).ReplaceLineEndings("\n") == text)
{
return;
}
}

configurationFilePath.CreateParentDirectory();
await File.WriteAllTextAsync(configurationFilePath, sb.ToString(), cancellationToken);
await File.WriteAllTextAsync(configurationFilePath, text, cancellationToken);
_ = Interlocked.Increment(ref writtenFiles);

static string GetSeverity(DiagnosticSeverity? severity)
Expand Down

0 comments on commit 38c8e85

Please sign in to comment.