Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
656ed62
chore: suppress CA1512 messages
filzrev Mar 8, 2025
4378483
chore: suppress CA1514 messages
filzrev Mar 3, 2025
a7ee9b6
chore: suppress CA1816 messages
filzrev Mar 3, 2025
1909ee3
chore: suppress CA1822 messages
filzrev Mar 8, 2025
b2f1cd3
chore: suppress CA1827 messages
filzrev Mar 3, 2025
347810e
chore: suppress CA1845 messages
filzrev Mar 3, 2025
1adaa14
chore: suppress CA1860 messages
filzrev Mar 3, 2025
9f78270
chore: suppress CA1861 messages
filzrev Mar 3, 2025
d35552a
chore: suppress CA1866 messages
filzrev Mar 3, 2025
df3aa24
chore: suppress CA1869 messages
filzrev Mar 3, 2025
404eea3
chore: suppress CA2016 messages
filzrev Mar 3, 2025
27fcf14
chore: suppress CA2211 messages
filzrev Mar 3, 2025
1103249
chore: suppress CA2263 messages
filzrev Mar 8, 2025
019ec9c
chore: suppress IDE0004 messages
filzrev Mar 3, 2025
6edf9ad
chore: suppress IDE0019 messages
filzrev Mar 3, 2025
9483e74
chore: suppress IDE0044 messages
filzrev Mar 3, 2025
e97adfe
chore: suppress IDE0051 messages
filzrev Mar 3, 2025
e519ccd
chore: suppress IDE0052 messages
filzrev Mar 3, 2025
7f3efd8
chore: suppress IDE0058 messages
filzrev Mar 4, 2025
8e2a797
chore: suppress IDE0130 messages
filzrev Mar 8, 2025
be80196
chore: suppress IDE0530 messages
filzrev Mar 8, 2025
72292ac
chore: suppress SYSLIB1045 messages
filzrev Mar 8, 2025
201160c
chore: suppress xUnit2022 messages
filzrev Mar 8, 2025
4d0df7c
chore: suppress xUnit2024 messages
filzrev Mar 8, 2025
554a387
chore: suppress IDE0303 messages
filzrev Mar 8, 2025
c331117
chore: suppress IDE0036 messages
filzrev Mar 8, 2025
a3920b8
chore: suppress xUnit1033 messages
filzrev Mar 8, 2025
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
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,11 @@ dotnet_diagnostic.IDE0005.severity = warning # IDE0005: Remove unnecessary im
dotnet_diagnostic.IDE0035.severity = suggestion # IDE0035: Remove unreachable code
dotnet_diagnostic.IDE0051.severity = suggestion # IDE0051: Remove unused private member
dotnet_diagnostic.IDE0052.severity = suggestion # IDE0052: Remove unread private member
dotnet_diagnostic.IDE0058.severity = silent # IDE0058: Remove unnecessary expression value
dotnet_diagnostic.IDE0080.severity = suggestion # IDE0080: Remove unnecessary suppression operator
dotnet_diagnostic.IDE0100.severity = suggestion # IDE0100: Remove unnecessary equality operator
dotnet_diagnostic.IDE0110.severity = suggestion # IDE0110: Remove unnecessary discard
dotnet_diagnostic.IDE0130.severity = silent # IDE0130: Namespace does not match folder structure
dotnet_diagnostic.IDE0240.severity = suggestion # IDE0240: Nullable directive is redundant
dotnet_diagnostic.IDE0241.severity = suggestion # IDE0241: Nullable directive is unnecessary

Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.App/PdfBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ Task<byte[]> PrintHeaderFooter(Outline toc, int pageNumber, int totalPages, Page

async Task<byte[]> PrintHeaderFooterCore()
{
await pageLimiter.WaitAsync();
await pageLimiter.WaitAsync(cancellationToken);
var page = pagePool.TryTake(out var pooled) ? pooled : await context.NewPageAsync();

try
Expand Down
9 changes: 9 additions & 0 deletions src/Docfx.Build.Common/DisposableDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public abstract class DisposableDocumentProcessor : IDocumentProcessor, IDisposa

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

protected virtual void Dispose(bool disposing)
{
if (!disposing)
return;

if (BuildSteps != null)
{
foreach (var buildStep in BuildSteps)
Expand Down
3 changes: 2 additions & 1 deletion src/Docfx.Build.RestApi/RestApiDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ private static void CheckOperationId(SwaggerModel swagger, string fileName)

private static string ChangeFileExtension(string file)
{
return file.Substring(0, file.Length - SupportedFileEndings.First(s => IsSupportedFileEnding(file, s)).Length) + ".json";
var suffix = SupportedFileEndings.First(s => IsSupportedFileEnding(file, s));
return $"{file.AsSpan(0, file.Length - suffix.Length)}.json";
}

private static Dictionary<string, object> MergeMetadata(IDictionary<string, object> item, IDictionary<string, object> overwriteItems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private static string MarkupCore(string content, IProcessContext context, string
context.Dependency.UnionWith(mr.Dependency);

if (mr.Html.StartsWith("<p"))
mr.Html = mr.Html.Insert(mr.Html.IndexOf(">"), " jsonPath=\"" + path + "\"");
mr.Html = mr.Html.Insert(mr.Html.IndexOf('>'), " jsonPath=\"" + path + "\"");
return mr.Html;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,4 @@ public object Interpret(BaseSchema schema, object value, IProcessContext context
// TODO implement
return value;
}

private static object MergeCore(object value, IProcessContext context)
{
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ public override SaveResult Save(FileModel model)

if (((IDictionary<string, object>)model.Properties).TryGetValue("XrefSpec", out var value))
{
var xrefSpec = value as XRefSpec;
if (xrefSpec != null)
if (value is XRefSpec xrefSpec)
{
result.XRefSpecs = [xrefSpec];
}
Expand Down
3 changes: 1 addition & 2 deletions src/Docfx.Build/Conceptual/ConceptualDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ public override SaveResult Save(FileModel model)

if (((IDictionary<string, object>)model.Properties).TryGetValue("XrefSpec", out var value))
{
var xrefSpec = value as XRefSpec;
if (xrefSpec != null)
if (value is XRefSpec xrefSpec)
{
result.XRefSpecs = [xrefSpec];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.Build/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Docfx.Build.Engine;

public class DocumentBuilder : IDisposable
public sealed class DocumentBuilder : IDisposable
{
[ImportMany]
internal IEnumerable<IDocumentProcessor> Processors { get; set; }
Expand Down Expand Up @@ -146,7 +146,7 @@ public void Build(IList<DocumentBuildParameters> parameters, string outputDirect
.WriteToManifest(generatedManifest, parameters[0].OutputBaseDir)
.Create();

_postProcessorsManager.Process(generatedManifest, outputDirectory);
_postProcessorsManager.Process(generatedManifest, outputDirectory, cancellationToken);

generatedManifest.Dereference(parameters[0].OutputBaseDir, parameters[0].MaxParallelism);

Expand Down
6 changes: 4 additions & 2 deletions src/Docfx.Build/PostProcessors/ExtractSearchIndex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ partial class ExtractSearchIndex : IPostProcessor
[GeneratedRegex(@"\s+")]
private static partial Regex s_regexWhiteSpace();

private static readonly Regex s_regexCase = new(@"[a-z0-9]+|[A-Z0-9]+[a-z0-9]*|[0-9]+", RegexOptions.Compiled);

[GeneratedRegex(@"[a-z0-9]+|[A-Z0-9]+[a-z0-9]*|[0-9]+")]
private static partial Regex s_regexCase();

private static readonly HashSet<string> s_htmlInlineTags = new(StringComparer.OrdinalIgnoreCase)
{
Expand Down Expand Up @@ -185,7 +187,7 @@ private static string[] GetStems(string str)
return [string.Empty];
}
str = WebUtility.HtmlDecode(str);
return s_regexCase.Matches(str).Select(m => m.Value).ToArray();
return s_regexCase().Matches(str).Select(m => m.Value).ToArray();
}

private static List<string> GetStemAggregations(string str)
Expand Down
6 changes: 3 additions & 3 deletions src/Docfx.Build/TableOfContents/TocDocumentProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override void UpdateHref(FileModel model, IDocumentBuildContext context)
model.Content = toc;
}

private void UpdateTocItemHref(TocItemViewModel toc, FileModel model, IDocumentBuildContext context, string includedFrom = null)
private static void UpdateTocItemHref(TocItemViewModel toc, FileModel model, IDocumentBuildContext context, string includedFrom = null)
{
if (toc.IsHrefUpdated) return;

Expand Down Expand Up @@ -170,7 +170,7 @@ private static string ResolveHref(string pathToFile, string originalPathToFile,
return fli.Href + segments;
}

private void RegisterTocToContext(TocItemViewModel toc, FileModel model, IDocumentBuildContext context)
private static void RegisterTocToContext(TocItemViewModel toc, FileModel model, IDocumentBuildContext context)
{
var key = model.Key;

Expand All @@ -180,7 +180,7 @@ private void RegisterTocToContext(TocItemViewModel toc, FileModel model, IDocume
context.RegisterTocInfo(new() { TocFileKey = key, Order = toc.Order ?? 0 });
}

private void RegisterTocMapToContext(TocItemViewModel item, FileModel model, IDocumentBuildContext context)
private static void RegisterTocMapToContext(TocItemViewModel item, FileModel model, IDocumentBuildContext context)
{
var key = model.Key;
// If tocHref is set, href is originally RelativeFolder type, and href is set to the homepage of TocHref,
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build/TemplateProcessors/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private bool TryExportResourceFiles(List<string> resourceNames, string outputDir
{
ArgumentException.ThrowIfNullOrEmpty(outputDirectory);

if (!resourceNames.Any())
if (resourceNames.Count == 0)
return false;

bool isEmpty = true;
Expand Down
1 change: 0 additions & 1 deletion src/Docfx.Build/XRefMaps/XRefArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public sealed class XRefArchive : IXRefContainer, IDisposable
#region Consts / Fields
public const string MajorFileName = "xrefmap.yml";

private readonly object _syncRoot = new();
private readonly XRefArchiveMode _mode;
private readonly ZipArchive _archive;
private readonly List<string> _entries;
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build/XRefMaps/XRefArchiveReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Docfx.Build.Engine;

public class XRefArchiveReader : XRefRedirectionReader, IDisposable
public sealed class XRefArchiveReader : XRefRedirectionReader, IDisposable
{
#region Fields
private readonly LruList<Tuple<string, XRefMap>> _lru;
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build/XRefMaps/XRefCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<IXRefContainerReader> CreateAsync(CancellationToken cancellati
AddToDownloadList(_uris, cancellationToken);
var dict = new Dictionary<string, IXRefContainer>();

while (_processing.Any())
while (_processing.Count != 0)
{
Task<IXRefContainer> task = await Task.WhenAny(_processing.Keys)
.WaitAsync(cancellationToken);
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Build/XRefMaps/XRefMapDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private ValueTask<IXRefContainer> ReadLocalFileWithFallback(Uri uri, Cancellatio
/// <remarks>
/// Support scheme: http, https, file.
/// </remarks>
private async ValueTask<IXRefContainer> DownloadBySchemeAsync(Uri uri, CancellationToken token = default)
private static async ValueTask<IXRefContainer> DownloadBySchemeAsync(Uri uri, CancellationToken token = default)
{
IXRefContainer result;
if (uri.IsFile)
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Common/Git/GitUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static string GitUrlToHttps(string url)
foreach (var text in File.ReadAllLines(configPath))
{
var line = text.Trim();
if (line.StartsWith("["))
if (line.StartsWith('['))
{
var remote = RemoteRegex().Replace(line, "$1");
key = remote != line ? remote : "";
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Common/Loggers/CompositeLogListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Docfx.Common;

public class CompositeLogListener : ILoggerListener
public sealed class CompositeLogListener : ILoggerListener
{
private readonly object _sync = new();
private readonly List<ILoggerListener> _listeners = [];
Expand Down
6 changes: 2 additions & 4 deletions src/Docfx.Common/Path/RelativePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,8 @@ private static RelativePath Create(bool isFromWorkingFolder, int parentDirectory

private IEnumerable<string> GetSubdirectories(int skip)
{
if (_parts.Length <= skip)
{
throw new ArgumentOutOfRangeException(nameof(skip));
}
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(skip, _parts.Length);

return _parts.Take(_parts.Length - skip - 1);
}

Expand Down
5 changes: 2 additions & 3 deletions src/Docfx.Common/YamlDeserializerWithFallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ private YamlDeserializerWithFallback(
}

public static YamlDeserializerWithFallback Create<T>() =>
new(
(Func<TextReader> tr) => YamlUtility.Deserialize<T>(tr()),
(string path) => YamlUtility.Deserialize<T>(path));
new(tr => YamlUtility.Deserialize<T>(tr()),
path => YamlUtility.Deserialize<T>(path));

public YamlDeserializerWithFallback WithFallback<T>() =>
new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Docfx.DataContracts.Common;

public class ExternalReferencePackageWriter : IDisposable
public sealed class ExternalReferencePackageWriter : IDisposable
{
private readonly ZipArchive _zip;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public string ToAttributeString()

public string GetHighlightLinesString()
{
if (HighlightRanges != null && HighlightRanges.Any())
if (HighlightRanges != null && HighlightRanges.Count != 0)
{
return string.Join(',', HighlightRanges.Select(highlight =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ static void BuildFileExtensionLanguageMap()
{
foreach (var (language, aliases) in s_languageAlias.Select(i => (i.Key, i.Value)))
{
Debug.Assert(!language.StartsWith("."));
Debug.Assert(!language.StartsWith('.'));

s_languageByFileExtension.Add(language, language);
s_languageByFileExtension.Add($".{language}", language);

foreach (var alias in aliases)
{
Debug.Assert(!alias.StartsWith("."));
Debug.Assert(!alias.StartsWith('.'));

s_languageByFileExtension.Add(alias, language);
s_languageByFileExtension.Add($".{alias}", language);
Expand Down Expand Up @@ -418,20 +418,6 @@ private static string CountAndReplaceIndentSpaces(string line, out int count)
return sb.ToString();
}

private static bool IsLineInRange(int lineNumber, List<CodeRange> allCodeRanges)
{
if (allCodeRanges.Count == 0) return true;

for (int rangeNumber = 0; rangeNumber < allCodeRanges.Count; rangeNumber++)
{
var range = allCodeRanges[rangeNumber];
if (lineNumber >= range.Start && lineNumber <= range.End)
return true;
}

return false;
}

private string GetWarning()
{
var warningTitle = _context.GetToken(WarningTitleId) ?? DefaultWarningTitle;
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.MarkdigEngine.Extensions/ExtensionsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private static bool MatchPath(ref StringSlice slice, ref string path)

if (includedFilePath.Length >= 1 && includedFilePath.First() == '<' && slice.CurrentChar == '>')
{
includedFilePath = includedFilePath.Substring(1, includedFilePath.Length - 1).Trim();
includedFilePath = includedFilePath.Substring(1).Trim();
}

if (slice.CurrentChar == ')')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
var name = prop.Name;

var options = prop.Value;
if (options.Count() == 0)
if (!options.Any())
{
return new MarkdigExtensionSetting(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void Write(Utf8JsonWriter writer, MarkdigExtensionSetting value,
if (value == null)
return;

var model = (MarkdigExtensionSetting)value;
var model = value;

if (model.Options == null || !model.Options.HasValue)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.MarkdigEngine.Extensions/MarkdownExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static MarkdownPipelineBuilder UseOptionalExtensions(
this MarkdownPipelineBuilder pipeline,
MarkdigExtensionSetting[] optionalExtensions)
{
if (!optionalExtensions.Any())
if (optionalExtensions.Length == 0)
{
return pipeline;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Docfx.MarkdigEngine.Extensions;

public class MonikerRangeParser : BlockParser
{
private const string StartString = "moniker";
// private const string StartString = "moniker";
private const string EndString = "moniker-end";
private const char Colon = ':';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static string FixUpLink(string link)
{
if (link.StartsWith("http:"))
{
link = "https:" + link.Substring("http:".Length);
link = $"https:{link.AsSpan("http:".Length)}";
}
if (Uri.TryCreate(link, UriKind.Absolute, out Uri videoLink))
{
Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Plugins/DefaultFileAbstractLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Docfx.Plugins;

public class DefaultFileAbstractLayer : IFileAbstractLayer
public sealed class DefaultFileAbstractLayer : IFileAbstractLayer
{
public IEnumerable<string> GetAllInputFiles()
{
Expand Down
6 changes: 1 addition & 5 deletions src/Docfx.Plugins/DocumentExceptionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ public static void RunAll<TElement>(this IEnumerable<TElement> elements, Action<
{
ArgumentNullException.ThrowIfNull(elements);
ArgumentNullException.ThrowIfNull(action);

if (parallelism <= 0)
{
throw new ArgumentOutOfRangeException(nameof(parallelism));
}
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(parallelism);

try
{
Expand Down
4 changes: 2 additions & 2 deletions src/Docfx.YamlSerialization/YamlDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void RegisterTypeConverter(IYamlTypeConverter typeConverter)

public object? Deserialize(TextReader input, IValueDeserializer? deserializer = null)
{
return Deserialize(input, typeof(object), deserializer);
return Deserialize<object>(input, deserializer);
}

public object? Deserialize(TextReader input, Type type, IValueDeserializer? deserializer = null)
Expand All @@ -161,7 +161,7 @@ public void RegisterTypeConverter(IYamlTypeConverter typeConverter)

public object? Deserialize(IParser reader, IValueDeserializer? deserializer = null)
{
return Deserialize(reader, typeof(object), deserializer);
return Deserialize<object>(reader, deserializer);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/docfx/Models/MetadataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static Dictionary<string, string> ResolveMSBuildProperties(MetadataComma
if (index > -1)
{
// Latter one overwrites former one
properties[pair.Substring(0, index)] = pair.Substring(index + 1, pair.Length - index - 1);
properties[pair.Substring(0, index)] = pair.Substring(index + 1);
}
}
}
Expand Down
Loading