Skip to content

Commit 45a469d

Browse files
authored
Fix csharp code analysis warnings (#538)
* Fix csharp code analysis warnings * fix release build
1 parent d1bca1d commit 45a469d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+31
-116
lines changed

src/Elastic.Markdown.Refactor/Move.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using System.Collections.ObjectModel;
65
using System.IO.Abstractions;
76
using System.Text.RegularExpressions;
87
using Elastic.Markdown.IO;
9-
using Elastic.Markdown.Slices;
108
using Microsoft.Extensions.Logging;
119

1210
namespace Elastic.Markdown.Refactor;
@@ -291,9 +289,7 @@ private string ReplaceLinks(
291289

292290
string newLink;
293291
if (originalPath.StartsWith('/'))
294-
{
295292
newLink = $"[{match.Groups[1].Value}]({absoluteStyleTarget}{anchor})";
296-
}
297293
else
298294
{
299295
var relativeTarget = Path.GetRelativePath(Path.GetDirectoryName(value.FilePath)!, target);

src/Elastic.Markdown/Diagnostics/DiagnosticsChannel.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Concurrent;
66
using System.Threading.Channels;
77
using Microsoft.Extensions.Hosting;
8-
using Microsoft.Extensions.Logging;
98

109
namespace Elastic.Markdown.Diagnostics;
1110

src/Elastic.Markdown/Diagnostics/ProcessorDiagnosticExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO.Abstractions;
66
using Elastic.Markdown.Myst;
77
using Elastic.Markdown.Myst.Directives;
8-
using Markdig.Helpers;
98
using Markdig.Parsers;
109
using Markdig.Syntax.Inlines;
1110

src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ private List<ITocItem> ReadChildren(KeyValuePair<YamlNode, YamlNode> entry, stri
146146
switch (key)
147147
{
148148
case "toc":
149-
toc = ReadNestedToc(entry, parentPath, out fileFound);
149+
toc = ReadNestedToc(entry, out fileFound);
150150
break;
151151
case "hidden":
152152
case "file":
153153
hiddenFile = key == "hidden";
154-
file = ReadFile(entry, parentPath, key, out fileFound);
154+
file = ReadFile(entry, parentPath, out fileFound);
155155
break;
156156
case "folder":
157157
folder = ReadFolder(entry, parentPath, out folderFound);
@@ -230,7 +230,7 @@ private Dictionary<string, string> ReadDictionary(KeyValuePair<YamlNode, YamlNod
230230
return folder;
231231
}
232232

233-
private string? ReadFile(KeyValuePair<YamlNode, YamlNode> entry, string parentPath, string key, out bool found)
233+
private string? ReadFile(KeyValuePair<YamlNode, YamlNode> entry, string parentPath, out bool found)
234234
{
235235
found = false;
236236
var file = ReadString(entry);
@@ -247,7 +247,7 @@ private Dictionary<string, string> ReadDictionary(KeyValuePair<YamlNode, YamlNod
247247
return file;
248248
}
249249

250-
private ConfigurationFile? ReadNestedToc(KeyValuePair<YamlNode, YamlNode> entry, string parentPath, out bool found)
250+
private ConfigurationFile? ReadNestedToc(KeyValuePair<YamlNode, YamlNode> entry, out bool found)
251251
{
252252
found = false;
253253
var tocPath = ReadString(entry);

src/Elastic.Markdown/IO/MarkdownFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private void ReadDocumentInstructions(MarkdownDocument document)
172172
var header = h.Item1!.StripMarkdown();
173173
if (header.AsSpan().ReplaceSubstitutions(subs, out var replacement))
174174
header = replacement;
175-
return new PageTocItem { Heading = header!, Slug = (h.Item2 ?? header).Slugify(), Level = h.Level };
175+
return new PageTocItem { Heading = header, Slug = (h.Item2 ?? header).Slugify(), Level = h.Level };
176176
})
177177
.ToList();
178178

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class EnhancedCodeBlock(BlockParser parser, ParserContext context)
2929

3030
public List<CallOut> CallOuts { get; set; } = [];
3131

32-
public IReadOnlyCollection<CallOut> UniqueCallOuts => CallOuts?.DistinctBy(c => c.Index).ToList() ?? [];
32+
public IReadOnlyCollection<CallOut> UniqueCallOuts => [.. CallOuts.DistinctBy(c => c.Index)];
3333

3434
public bool InlineAnnotations { get; set; }
3535

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockHtmlRenderer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// See the LICENSE file in the project root for more information
44

55
using Elastic.Markdown.Diagnostics;
6-
using Elastic.Markdown.Myst.Directives;
76
using Elastic.Markdown.Slices.Directives;
87
using Markdig.Helpers;
98
using Markdig.Renderers;
@@ -65,7 +64,7 @@ private static void RenderCodeBlockLine(HtmlRenderer renderer, EnhancedCodeBlock
6564

6665
private static void RenderCallouts(HtmlRenderer renderer, EnhancedCodeBlock block, int lineNumber)
6766
{
68-
var callOuts = FindCallouts(block.CallOuts ?? [], lineNumber + 1);
67+
var callOuts = FindCallouts(block.CallOuts, lineNumber + 1);
6968
foreach (var callOut in callOuts)
7069
renderer.Write($"<span class=\"code-callout\" data-index=\"{callOut.Index}\">{callOut.Index}</span>");
7170
}

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,12 @@ public override bool Close(BlockProcessor processor, Block block)
103103
if (codeBlock is not AppliesToDirective appliesToDirective)
104104
ProcessCallOuts(lines, language, codeBlock, context);
105105
else
106-
ProcessAppliesToDirective(appliesToDirective, lines, context);
106+
ProcessAppliesToDirective(appliesToDirective, lines);
107107

108108
return base.Close(processor, block);
109109
}
110110

111-
private static void ProcessAppliesToDirective(AppliesToDirective appliesToDirective, StringLineGroup lines, ParserContext context)
111+
private static void ProcessAppliesToDirective(AppliesToDirective appliesToDirective, StringLineGroup lines)
112112
{
113113
var yaml = lines.ToSlice().AsSpan().ToString();
114114

@@ -195,8 +195,8 @@ private static void ProcessCallOuts(StringLineGroup lines, string language, Enha
195195
}
196196
}
197197

198-
var inlineAnnotations = codeBlock.CallOuts?.Where(c => c.InlineCodeAnnotation).Count() ?? 0;
199-
var classicAnnotations = codeBlock.CallOuts?.Count - inlineAnnotations ?? 0;
198+
var inlineAnnotations = codeBlock.CallOuts.Count(c => c.InlineCodeAnnotation);
199+
var classicAnnotations = codeBlock.CallOuts.Count - inlineAnnotations;
200200
if (inlineAnnotations > 0 && classicAnnotations > 0)
201201
codeBlock.EmitError("Both inline and classic callouts are not supported");
202202

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeMarkdownExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33
// See the LICENSE file in the project root for more information
44

5-
using Elastic.Markdown.Myst.Directives;
65
using Markdig;
76
using Markdig.Parsers;
87
using Markdig.Renderers;

src/Elastic.Markdown/Myst/Comments/CommentBlockParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public override BlockState TryOpen(BlockProcessor processor)
107107
// The optional closing sequence of #s must be preceded by a space and may be followed by spaces only.
108108
var endState = 0;
109109
var countClosingTags = 0;
110-
var sourceEnd = processor.Line.End;
111110
for (var i = processor.Line.End;
112111
i >= processor.Line.Start - 1;
113112
i--) // Go up to Start - 1 in order to match the space after the first ###

0 commit comments

Comments
 (0)