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 ###

src/Elastic.Markdown/Myst/Directives/AppliesBlock.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +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.FrontMatter;
7-
using Markdig.Syntax;
86

97
namespace Elastic.Markdown.Myst.Directives;
108

src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// See the license.txt file in the project root for more information.
77

88
using System.IO.Abstractions;
9-
using Elastic.Markdown.Diagnostics;
109
using Markdig.Helpers;
1110
using Markdig.Syntax;
1211

src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// See the license.txt file in the project root for more information.
77

88
using Elastic.Markdown.Diagnostics;
9-
using Elastic.Markdown.Myst.FrontMatter;
109
using Elastic.Markdown.Myst.Settings;
1110
using Elastic.Markdown.Myst.Substitution;
1211
using Elastic.Markdown.Slices.Directives;
@@ -121,7 +120,7 @@ private void WriteFigure(HtmlRenderer renderer, ImageBlock block)
121120
(block.ImageUrl.StartsWith("/_static") || block.ImageUrl.StartsWith("_static"))
122121
? $"{block.Build.UrlPathPrefix}/{block.ImageUrl.TrimStart('/')}"
123122
: block.ImageUrl;
124-
var slice = Slices.Directives.Figure.Create(new ImageViewModel
123+
var slice = Figure.Create(new ImageViewModel
125124
{
126125
Label = block.Label,
127126
Align = block.Align,

src/Elastic.Markdown/Myst/Directives/DirectiveParagraphParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public override BlockState TryOpen(BlockProcessor processor)
1313
var line = processor.Line.AsSpan();
1414

1515
// TODO Validate properties on directive.
16-
if (line.StartsWith(":") && processor.CurrentBlock is DirectiveBlock directive)
16+
if (line.StartsWith(":") && processor.CurrentBlock is DirectiveBlock)
1717
return BlockState.None;
18-
else if (line.StartsWith(":"))
18+
if (line.StartsWith(":"))
1919
return BlockState.None;
2020

2121
return base.TryOpen(processor);

src/Elastic.Markdown/Myst/Directives/TabSetBlock.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using Elastic.Markdown.Diagnostics;
66
using Elastic.Markdown.Helpers;
7-
using Elastic.Markdown.Slices.Directives;
87

98
namespace Elastic.Markdown.Myst.Directives;
109

src/Elastic.Markdown/Myst/FrontMatter/AllVersions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class SemVersionConverter : IYamlTypeConverter
1818
{
1919
public bool Accepts(Type type) => type == typeof(SemVersion);
2020

21-
public object? ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
21+
public object ReadYaml(IParser parser, Type type, ObjectDeserializer rootDeserializer)
2222
{
2323
var value = parser.Consume<Scalar>();
2424
if (string.IsNullOrWhiteSpace(value.Value))

src/Elastic.Markdown/Myst/InlineParsers/DiagnosticLinkInlineParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void ValidateAndProcessLink(LinkInline link, InlineProcessor processor,
109109
return;
110110
}
111111

112-
if (ValidateExternalUri(link, processor, context, uri))
112+
if (ValidateExternalUri(link, processor, uri))
113113
return;
114114

115115
ProcessInternalLink(link, processor, context);
@@ -134,7 +134,7 @@ private bool ValidateBasicUrl(LinkInline link, InlineProcessor processor, string
134134
return true;
135135
}
136136

137-
private bool ValidateExternalUri(LinkInline link, InlineProcessor processor, ParserContext context, Uri? uri)
137+
private bool ValidateExternalUri(LinkInline link, InlineProcessor processor, Uri? uri)
138138
{
139139
if (uri == null)
140140
return false;

src/Elastic.Markdown/Myst/InlineParsers/HeadingBlockWithSlugParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Markdig;
77
using Markdig.Helpers;
88
using Markdig.Parsers;
9-
using Markdig.Parsers.Inlines;
109
using Markdig.Renderers;
1110
using Markdig.Syntax;
1211

src/Elastic.Markdown/Myst/InlineParsers/InlineAnchorParser.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using Elastic.Markdown.Helpers;
66
using Markdig;
7-
using Markdig.Extensions.SmartyPants;
87
using Markdig.Helpers;
98
using Markdig.Parsers;
109
using Markdig.Parsers.Inlines;
@@ -35,16 +34,10 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) =>
3534

3635
public class InlineAnchorParser : InlineParser
3736
{
38-
public InlineAnchorParser()
39-
{
40-
OpeningCharacters = ['$'];
41-
}
37+
public InlineAnchorParser() => OpeningCharacters = ['$'];
4238

4339
public override bool Match(InlineProcessor processor, ref StringSlice slice)
4440
{
45-
var startPosition = processor.GetSourcePosition(slice.Start, out var line, out var column);
46-
var c = slice.CurrentChar;
47-
4841
var span = slice.AsSpan();
4942
if (!span.StartsWith("$$$"))
5043
return false;

src/Elastic.Markdown/Myst/MarkdownParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Elastic.Markdown.CrossLinks;
88
using Elastic.Markdown.IO;
99
using Elastic.Markdown.IO.Configuration;
10-
using Elastic.Markdown.IO.State;
1110
using Elastic.Markdown.Myst.CodeBlocks;
1211
using Elastic.Markdown.Myst.Comments;
1312
using Elastic.Markdown.Myst.Directives;

src/Elastic.Markdown/Myst/Substitution/SubstitutionParser.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
// See the LICENSE file in the project root for more information
44
using System.Buffers;
55
using System.Diagnostics;
6-
using System.Net.Mime;
76
using System.Runtime.CompilerServices;
87
using Elastic.Markdown.Diagnostics;
9-
using Markdig;
108
using Markdig.Helpers;
119
using Markdig.Parsers;
1210
using Markdig.Renderers;
@@ -69,7 +67,7 @@ public override string ToString()
6967
}
7068
}
7169

72-
[DebuggerDisplay("{GetType().Name} Line: {Line}, {Lines} Level: {Level}")]
70+
[DebuggerDisplay("{GetType().Name} Line: {Line}, Found: {Found}, Replacement: {Replacement}")]
7371
public class SubstitutionLeaf(string content, bool found, string replacement) : CodeInline(content)
7472
{
7573
public bool Found { get; } = found;
@@ -78,13 +76,8 @@ public class SubstitutionLeaf(string content, bool found, string replacement) :
7876

7977
public class SubstitutionRenderer : HtmlObjectRenderer<SubstitutionLeaf>
8078
{
81-
protected override void Write(HtmlRenderer renderer, SubstitutionLeaf obj)
82-
{
83-
if (obj.Found)
84-
renderer.Write(obj.Replacement);
85-
else
86-
renderer.Write(obj.Content);
87-
}
79+
protected override void Write(HtmlRenderer renderer, SubstitutionLeaf obj) =>
80+
renderer.Write(obj.Found ? obj.Replacement : obj.Content);
8881
}
8982

9083
public class SubstitutionParser : InlineParser

src/Elastic.Markdown/Slices/Directives/ApplicableTo.cshtml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,7 @@
5757

5858
@functions {
5959

60-
private string GetLifeCycleClass(ProductLifecycle cycle)
61-
{
62-
switch (cycle)
63-
{
64-
case ProductLifecycle.Deprecated:
65-
case ProductLifecycle.Coming:
66-
case ProductLifecycle.Discontinued:
67-
case ProductLifecycle.Unavailable:
68-
return "muted";
69-
case ProductLifecycle.GenerallyAvailable:
70-
case ProductLifecycle.TechnicalPreview:
71-
case ProductLifecycle.Beta:
72-
case ProductLifecycle.Development:
73-
return "primary";
74-
default:
75-
throw new ArgumentOutOfRangeException(nameof(cycle), cycle, null);
76-
}
77-
}
78-
private string GetLifeCycleName(ProductLifecycle cycle)
60+
private static string GetLifeCycleName(ProductLifecycle cycle)
7961
{
8062
switch (cycle)
8163
{
@@ -104,7 +86,6 @@
10486
{
10587
foreach (var applicability in applications)
10688
{
107-
var c = GetLifeCycleClass(applicability.Lifecycle);
10889
<span class="applicable-info">
10990
@name
11091
@if (applicability.Lifecycle != ProductLifecycle.GenerallyAvailable)

src/Elastic.Markdown/Slices/Directives/Settings.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@using Elastic.Markdown.Myst.FrontMatter
21
@using Elastic.Markdown.Myst.Settings
32
@inherits RazorSlice<SettingsViewModel>
43

src/Elastic.Markdown/Slices/Directives/_ViewModels.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
using System.Text;
5-
using Elastic.Markdown.Myst.Directives;
65
using Elastic.Markdown.Myst.Settings;
76

87
namespace Elastic.Markdown.Slices.Directives;

src/Elastic.Markdown/Slices/HtmlWriter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ public HtmlWriter(DocumentationSet documentationSet, IFileSystem writeFileSystem
2828
public ILoggerFactory LoggerFactory { get; }
2929
public ServiceProvider ServiceProvider { get; }
3030

31-
private Task<string> RenderEmptyString(MarkdownFile markdown, Cancel ctx = default) =>
32-
Task.FromResult(string.Empty);
33-
3431
private async Task<string> RenderNavigation(MarkdownFile markdown, Cancel ctx = default)
3532
{
3633
var slice = Layout._TocTree.Create(new NavigationViewModel

src/Elastic.Markdown/Slices/Layout/_Announcement.cshtml

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Elastic.Markdown/Slices/Layout/_Head.cshtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<title>@Model.Title</title>
77
<link rel="index" title="Index" href="@Model.Link("genindex.html")"/>
88
<link rel="search" title="Search" href="@Model.Link("search.html")"/>
9-
<link rel="next" title="Elastic content" href="elastic/index.html"/>
109
<link rel="stylesheet" type="text/css" href="@Model.Static("pygments.css")"/>
1110
<link rel="stylesheet" type="text/css" href="@Model.Static("shibuya.css")"/>
1211
<link rel="stylesheet" type="text/css" href="@Model.Static("mystnb.css")"/>

src/Elastic.Markdown/Slices/Layout/_HeadNav.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<small>Description.</small>
4949
</a></li></ul>
5050
</li><li class="link"><a href="#">What's New</a></li></ul></nav>
51+
@* ReSharper disable once Html.PathError *@
5152
<div class="sy-head-extra flex items-center print:hidden"><form class="searchbox flex items-center" action="search.html" method="get">
5253
<input type="text" name="q" placeholder="Search">
5354
<kbd>/</kbd>

src/Elastic.Markdown/SourceGenerationContext.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
using System.Text.Json.Serialization;
66
using Elastic.Markdown.CrossLinks;
7-
using Elastic.Markdown.IO;
87
using Elastic.Markdown.IO.Discovery;
98
using Elastic.Markdown.IO.State;
109

0 commit comments

Comments
 (0)