Skip to content

Commit

Permalink
remove redundant verbatim strings (#10075)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jul 9, 2024
1 parent 740f246 commit c8409b4
Show file tree
Hide file tree
Showing 38 changed files with 310 additions and 310 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ private static string MarkupCore(string content, IProcessContext context, string
(context.UidLinkSources).Merge(mr.UidLinkSources);
(context.Dependency).UnionWith(mr.Dependency);

if (mr.Html.StartsWith(@"<p"))
mr.Html = mr.Html.Insert(mr.Html.IndexOf(@">"), " jsonPath=\"" + path + "\"");
if (mr.Html.StartsWith("<p"))
mr.Html = mr.Html.Insert(mr.Html.IndexOf(">"), " jsonPath=\"" + path + "\"");
return mr.Html;
}
}
4 changes: 2 additions & 2 deletions src/Docfx.Build/TableOfContents/MarkdownTocReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public static class MarkdownTocReader
{
private const string ContinuableCharacters = ".,;:!?~";
private const string StopCharacters = @"\s\""\'<>";
private const string XrefAutoLinkRegexString = @"(<xref:([^ >]+)>)";
private const string XrefAutoLinkRegexString = "(<xref:([^ >]+)>)";
private const string XrefAutoLinkRegexWithQuoteString = @"<xref:(['""])(\s*?\S+?[\s\S]*?)\1>";
private const string XrefShortcutRegexWithQuoteString = @"@(?:(['""])(?<uid>\s*?\S+?[\s\S]*?)\1)";
private const string XrefShortcutRegexString = $@"@(?<uid>[a-zA-Z](?:[{ContinuableCharacters}]?[^{StopCharacters}{ContinuableCharacters}])*)";
private const string XrefShortcutRegexString = $"@(?<uid>[a-zA-Z](?:[{ContinuableCharacters}]?[^{StopCharacters}{ContinuableCharacters}])*)";

public static List<TocItemViewModel> LoadToc(string tocContent, string filePath)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public PreprocessorLoader(ResourceFileReader reader, DocumentBuildContext contex
public IEnumerable<ITemplatePreprocessor> LoadStandalones()
{
// Only files under root folder are allowed
foreach (var res in _reader.GetResources($@"^[^/]*{Regex.Escape(TemplateJintPreprocessor.StandaloneExtension)}$"))
foreach (var res in _reader.GetResources($"^[^/]*{Regex.Escape(TemplateJintPreprocessor.StandaloneExtension)}$"))
{
var name = Path.GetFileNameWithoutExtension(res.Path.Remove(res.Path.LastIndexOf('.')));
var preprocessor = Load(res, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public RendererLoader(ResourceFileReader reader, int maxParallelism)
public IEnumerable<ITemplateRenderer> LoadAll()
{
// Only files under root folder are allowed
foreach (var res in _reader.GetResources($@"^[^/]*({Regex.Escape(MustacheTemplateRenderer.Extension)})$"))
foreach (var res in _reader.GetResources($"^[^/]*({Regex.Escape(MustacheTemplateRenderer.Extension)})$"))
{
var renderer = Load(res);
if (renderer != null)
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 @@ -215,7 +215,7 @@ private static string ResolveDocfxSourceRepoUrl(string originalUrl)
{
// Replace `/{orgName}/{repoName}` and remove `.git` suffix.
var builder = new UriBuilder(parsedOriginalUrl);
builder.Path = Regex.Replace(builder.Path.TrimEnd(".git"), @"^/[^/]+/[^/]+", $"/{orgName}/{repoName}");
builder.Path = Regex.Replace(builder.Path.TrimEnd(".git"), "^/[^/]+/[^/]+", $"/{orgName}/{repoName}");
return builder.Uri.ToString();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Docfx.Dotnet/Parsers/XmlComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace Docfx.Dotnet;
internal class XmlComment
{
private const string IdSelector = @"((?![0-9])[\w_])+[\w\(\)\.\{\}\[\]\|\*\^~#@!`,_<>:]*";
private static readonly Regex CommentIdRegex = new(@"^(?<type>N|T|M|P|F|E|Overload):(?<id>" + IdSelector + ")$", RegexOptions.Compiled);
private static readonly Regex CommentIdRegex = new("^(?<type>N|T|M|P|F|E|Overload):(?<id>" + IdSelector + ")$", RegexOptions.Compiled);
private static readonly Regex RegionRegex = new(@"^\s*#region\s*(.*)$");
private static readonly Regex XmlRegionRegex = new(@"^\s*<!--\s*<([^/\s].*)>\s*-->$");
private static readonly Regex EndRegionRegex = new(@"^\s*#endregion\s*.*$");
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 @@ -10,7 +10,7 @@ namespace Docfx.MarkdigEngine.Extensions;

public static class ExtensionsHelper
{
public static readonly Regex HtmlEscapeWithEncode = new(@"&", RegexOptions.Compiled);
public static readonly Regex HtmlEscapeWithEncode = new("&", RegexOptions.Compiled);
public static readonly Regex HtmlEscapeWithoutEncode = new(@"&(?!#?\w+;)", RegexOptions.Compiled);
public static readonly Regex HtmlUnescape = new(@"&([#\w]+);", RegexOptions.Compiled);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Docfx.MarkdigEngine.Extensions;
/// <summary>
/// Markdig extension setting.
/// </summary>
[DebuggerDisplay(@"Name = {Name}")]
[DebuggerDisplay("Name = {Name}")]
[Newtonsoft.Json.JsonConverter(typeof(MarkdigExtensionSettingConverter))]
public class MarkdigExtensionSetting
{
Expand Down
6 changes: 3 additions & 3 deletions src/Docfx.YamlSerialization/Helpers/Regexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ internal static class Regexes
// |true|True|TRUE|false|False|FALSE
// |null|Null|NULL|~
// |on|On|ON|off|Off|OFF
public static readonly Regex BooleanLike = new(@"^(true|True|TRUE|false|False|FALSE)$", RegexOptions.Compiled);
public static readonly Regex BooleanLike = new("^(true|True|TRUE|false|False|FALSE)$", RegexOptions.Compiled);

public static readonly Regex NullLike = new(@"^(null|Null|NULL|~)$", RegexOptions.Compiled);
public static readonly Regex NullLike = new("^(null|Null|NULL|~)$", RegexOptions.Compiled);

public static readonly Regex IntegerLike = new(@"^-?(0|[1-9][0-9]*)$", RegexOptions.Compiled);
public static readonly Regex IntegerLike = new("^-?(0|[1-9][0-9]*)$", RegexOptions.Compiled);

// https://yaml.org/spec/1.2/spec.html#id2805071
public static readonly Regex FloatLike = new(@"^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$", RegexOptions.Compiled);
Expand Down
14 changes: 7 additions & 7 deletions test/Docfx.Build.RestApi.Tests/SwaggerJsonParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SwaggerJsonParserTest
[Fact]
public void ParseSimpleSwaggerJsonShouldSucceed()
{
var swaggerFile = @"TestData/swagger/simple_swagger2.json";
var swaggerFile = "TestData/swagger/simple_swagger2.json";
var swagger = SwaggerJsonParser.Parse(swaggerFile);

Assert.Single(swagger.Paths.Values);
Expand All @@ -34,7 +34,7 @@ public void ParseSimpleSwaggerJsonShouldSucceed()
[Fact]
public void ParseSwaggerJsonWithReferenceShouldSucceed()
{
var swaggerFile = @"TestData/swagger/ref_swagger2.json";
var swaggerFile = "TestData/swagger/ref_swagger2.json";
var swagger = SwaggerJsonParser.Parse(swaggerFile);

Assert.Single(swagger.Paths);
Expand Down Expand Up @@ -72,7 +72,7 @@ public void ParseSwaggerJsonWithReferenceShouldSucceed()
[Fact]
public void ParseSwaggerJsonWithTagShouldSucceed()
{
const string swaggerFile = @"TestData/swagger/tag_swagger2.json";
const string swaggerFile = "TestData/swagger/tag_swagger2.json";
var swagger = SwaggerJsonParser.Parse(swaggerFile);

Assert.Equal(3, swagger.Tags.Count);
Expand All @@ -90,7 +90,7 @@ public void ParseSwaggerJsonWithTagShouldSucceed()
[Fact]
public void ParseSwaggerJsonWithPathParametersShouldSucceed()
{
const string swaggerFile = @"TestData/swagger/pathParameters_swagger2.json";
const string swaggerFile = "TestData/swagger/pathParameters_swagger2.json";
var swagger = SwaggerJsonParser.Parse(swaggerFile);

Assert.Single(swagger.Paths.Values);
Expand All @@ -111,7 +111,7 @@ public void ParseSwaggerJsonWithPathParametersShouldSucceed()
[Fact]
public void ParseSwaggerJsonWithLoopReferenceShouldSucceed()
{
const string swaggerFile = @"TestData/swagger/loopref_swagger2.json";
const string swaggerFile = "TestData/swagger/loopref_swagger2.json";
var swagger = SwaggerJsonParser.Parse(swaggerFile);

Assert.Single(swagger.Paths.Values);
Expand Down Expand Up @@ -150,7 +150,7 @@ public void ParseSwaggerJsonWithLoopReferenceShouldSucceed()
[Fact]
public void ParseSwaggerJsonWithExternalLoopReferenceShouldSucceed()
{
const string swaggerFile = @"TestData/swagger/externalLoopRef_A.json";
const string swaggerFile = "TestData/swagger/externalLoopRef_A.json";
var swagger = SwaggerJsonParser.Parse(swaggerFile);

Assert.Single(swagger.Paths.Values);
Expand Down Expand Up @@ -188,7 +188,7 @@ public void ParseSwaggerJsonWithExternalLoopReferenceShouldSucceed()
[Fact]
public void ParseKeyWordSwaggerJsonShouldSucceed()
{
var swaggerFile = @"TestData/swagger/resolveKeywordWithRefInside.json";
var swaggerFile = "TestData/swagger/resolveKeywordWithRefInside.json";
var swagger = SwaggerJsonParser.Parse(swaggerFile);

///test x-ms-examples: unresolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void TestFragmentsWithIncremental()
// modify fragments
UpdateFile(
"Suppressions.yml.md",
new string[] { @"# `management.azure.com.advisor.suppressions`",
new string[] { "# `management.azure.com.advisor.suppressions`",
"## ``summary``",
"I update a summary.",
"With [!include[invalid](invalid.md)]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void TestXrefResolver()
// arrange
var schemaFile = CreateFile("template/schemas/mref.test.schema.json", File.ReadAllText("TestData/schemas/mref.test.schema.json"), _templateFolder);
var templateXref = CreateFile(
"template/partials/overview.tmpl", @"{{name}}:{{{summary}}}|{{#boolProperty}}{{intProperty}}{{/boolProperty}}|{{#monikers}}<span>{{.}}</span>{{/monikers}}",
"template/partials/overview.tmpl", "{{name}}:{{{summary}}}|{{#boolProperty}}{{intProperty}}{{/boolProperty}}|{{#monikers}}<span>{{.}}</span>{{/monikers}}",
_templateFolder);
var templateFile = CreateFile("template/ManagedReference.html.tmpl", @"
{{#items}}
Expand Down
4 changes: 2 additions & 2 deletions test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ public void TestSchemaOverwriteWithGeneralSchemaOptions()
xref: uid1
reference: ../inc/inc.md
", _inputFolder);
var includeFile = CreateFile("inc/inc.md", @"[parent](../src/src.yml)", _inputFolder);
var includeFile2 = CreateFile("inc/inc2.md", @"[overwrite](../src/src.yml)", _inputFolder);
var includeFile = CreateFile("inc/inc.md", "[parent](../src/src.yml)", _inputFolder);
var includeFile2 = CreateFile("inc/inc2.md", "[overwrite](../src/src.yml)", _inputFolder);
var overwriteFile = CreateFile("overwrite/a.md", @"---
uid: uid1
summary: *content
Expand Down
4 changes: 2 additions & 2 deletions test/Docfx.Build.Tests/ConceptualDocumentProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public ConceptualDocumentProcessorTest()

// Prepare conceptual template
var templateCreator = new FileCreator(_templateFolder);
var file = templateCreator.CreateFile(@"{{{conceptual}}}", "conceptual.html.tmpl", "default");
var file = templateCreator.CreateFile("{{{conceptual}}}", "conceptual.html.tmpl", "default");
_templateManager = new TemplateManager(new List<string> { "default" }, null, _templateFolder);
}

Expand Down Expand Up @@ -369,7 +369,7 @@ Some content

// Add template for redirection.
var templateCreator = new FileCreator(_templateFolder);
templateCreator.CreateFile(@"{{{redirect_url}}}", "redirection.html.tmpl", "default");
templateCreator.CreateFile("{{{redirect_url}}}", "redirection.html.tmpl", "default");

// act
BuildDocument(files, metadata);
Expand Down
2 changes: 1 addition & 1 deletion test/Docfx.Build.Tests/DocumentBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void TestBuild()
$"Test href generator: <a href=\"GitHub.md?shouldBeAbbreviated=true#test\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"32\">GitHub</a>",
$"Test href generator: <a href=\"Git.md?shouldBeAbbreviated=true#test\" sourcefile=\"{_inputFolder}/test.md\" sourcestartlinenumber=\"33\">Git</a></p>",
"<p>",
@"test",
"test",
"</p>"),
model["conceptual"]);
Assert.Equal(
Expand Down
6 changes: 3 additions & 3 deletions test/Docfx.Build.Tests/TemplateManagerUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public void TestMustacheTemplateWithScriptWithLongStringInModelShouldWork()
// https://github.com/sebastienros/jint/issues/357

var templateName = "TemplateFolder.html";
string defaultTemplate = @"{{name}}";
string defaultTemplate = "{{name}}";
var name = "this is a looooooooooooooooooooooooooooooooooooog name";
var longName = string.Concat(Enumerable.Repeat(name, 20000));
string script = @"
Expand Down Expand Up @@ -480,7 +480,7 @@ public void JsRegexShouldNotShareStatusAmongFunctions()
// https://github.com/sebastienros/jint/issues/364

var templateName = "TemplateFolder.html";
string defaultTemplate = @"{{result1}},{{result2}}";
string defaultTemplate = "{{result1}},{{result2}}";
string script = @"
exports.transform = function (model){
var url = 'https://www.example.com';
Expand Down Expand Up @@ -518,7 +518,7 @@ public void JsRegexShouldNotShareStatusAmongFunctions()
public void JsCreateDateShouldNotThrowError()
{
var templateName = "TemplateFolder.html";
string defaultTemplate = @"{{date}}";
string defaultTemplate = "{{date}}";
string script = @"
exports.transform = function (model){
return {
Expand Down
2 changes: 1 addition & 1 deletion test/Docfx.Build.Tests/TemplateProcessorUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public TemplateProcessorUnitTest()
[Fact]
public void TestXrefWithTemplate()
{
CreateFile("partials/xref.html.tmpl", @"<h2>{{uid}}</h2><p>{{summary}}</p>{{#isGood}}Good!{{/isGood}}", _templateFolder);
CreateFile("partials/xref.html.tmpl", "<h2>{{uid}}</h2><p>{{summary}}</p>{{#isGood}}Good!{{/isGood}}", _templateFolder);
CreateFile("index.html.tmpl", @"
<xref uid=""{{reference}}"" template=""partials/xref.html.tmpl"" />
", _templateFolder);
Expand Down
2 changes: 1 addition & 1 deletion test/Docfx.Build.Tests/TocDocumentProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ public void UrlDecodeHrefInYamlToc()
public void UrlDecodeHrefInMarkdownToc()
{
// Arrange
var tocContent = @"# [NAME](a%20b.md)";
var tocContent = "# [NAME](a%20b.md)";
var files = new FileCollection(_inputFolder);
var tocFile = _fileCreator.CreateFile(tocContent, FileType.MarkdownToc);
var markdownFile = _fileCreator.CreateFile(string.Empty, FileType.MarkdownContent, fileNameWithoutExtension: "a b");
Expand Down
24 changes: 12 additions & 12 deletions test/Docfx.Build.Tests/ValidateBookmarkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public void TestBasicFeature()
}
};

File.WriteAllText(Path.Combine(_outputFolder, "a.html"), @"<a href='http://bing.com#top'>Microsoft Bing</a> <p id='b1'>section</p><a href='#b1'/>");
File.WriteAllText(Path.Combine(_outputFolder, "b.html"), @"<a href='a.html#b1' sourceFile='b.md' sourceStartLineNumber='1'>bookmark existed</a><a href='a.html#b2' data-raw-source='[link with source info](a.md#b2)' sourceFile='b.md' sourceStartLineNumber='1'>link with source info</a> <a href='a.html#b3' data-raw-source='[link in token file](a.md#b3)' sourceFile='token.md' sourceStartLineNumber='1'>link in token file</a><a href='a.html#b4'>link without source info</a>");
File.WriteAllText(Path.Combine(_outputFolder, "c.html"), @"<a href='illegal_path_%3Cillegal character%3E.html#b1'>Test illegal link path</a>");
File.WriteAllText(Path.Combine(_outputFolder, "d.html"), @"<a href='illegal_path_*illegal character.html#b1'>Test illegal link path with wildchar *</a>");
File.WriteAllText(Path.Combine(_outputFolder, "e.html"), @"<a href='illegal_path_%3Fillegal character.html#b1'>Test illegal link path with wildchar ?</a>");
File.WriteAllText(Path.Combine(_outputFolder, "Dir/f.html"), @"<a href='#b1'>Test local link</a>");
File.WriteAllText(Path.Combine(_outputFolder, "g.html"), @"<a href='#b3' data-raw-source='[local link in token file](#b3)' sourceFile='token.md' sourceStartLineNumber='1'>local link in token file</a>");
File.WriteAllText(Path.Combine(_outputFolder, "a.html"), "<a href='http://bing.com#top'>Microsoft Bing</a> <p id='b1'>section</p><a href='#b1'/>");
File.WriteAllText(Path.Combine(_outputFolder, "b.html"), "<a href='a.html#b1' sourceFile='b.md' sourceStartLineNumber='1'>bookmark existed</a><a href='a.html#b2' data-raw-source='[link with source info](a.md#b2)' sourceFile='b.md' sourceStartLineNumber='1'>link with source info</a> <a href='a.html#b3' data-raw-source='[link in token file](a.md#b3)' sourceFile='token.md' sourceStartLineNumber='1'>link in token file</a><a href='a.html#b4'>link without source info</a>");
File.WriteAllText(Path.Combine(_outputFolder, "c.html"), "<a href='illegal_path_%3Cillegal character%3E.html#b1'>Test illegal link path</a>");
File.WriteAllText(Path.Combine(_outputFolder, "d.html"), "<a href='illegal_path_*illegal character.html#b1'>Test illegal link path with wildchar *</a>");
File.WriteAllText(Path.Combine(_outputFolder, "e.html"), "<a href='illegal_path_%3Fillegal character.html#b1'>Test illegal link path with wildchar ?</a>");
File.WriteAllText(Path.Combine(_outputFolder, "Dir/f.html"), "<a href='#b1'>Test local link</a>");
File.WriteAllText(Path.Combine(_outputFolder, "g.html"), "<a href='#b3' data-raw-source='[local link in token file](#b3)' sourceFile='token.md' sourceStartLineNumber='1'>local link in token file</a>");
File.WriteAllText(Path.Combine(_outputFolder, "h.html"), @"<p><a href=""#welcome"">Test if raw title can be loaded as bookmark from metadata of manifest item</a></p>");

Logger.RegisterListener(_listener);
Expand All @@ -74,11 +74,11 @@ public void TestBasicFeature()
Assert.True(logs.All(l => l.Code == WarningCodes.Build.InvalidBookmark));
var expected = new[]
{
Tuple.Create(@"Invalid link: '[link with source info](a.md#b2)'. The file a.md doesn't contain a bookmark named 'b2'.", "b.md"),
Tuple.Create(@"Invalid link: '[link in token file](a.md#b3)'. The file a.md doesn't contain a bookmark named 'b3'.", "token.md"),
Tuple.Create("Invalid link: '[link with source info](a.md#b2)'. The file a.md doesn't contain a bookmark named 'b2'.", "b.md"),
Tuple.Create("Invalid link: '[link in token file](a.md#b3)'. The file a.md doesn't contain a bookmark named 'b3'.", "token.md"),
Tuple.Create(@"Invalid link: '<a href=""a.md#b4"">link without source info</a>'. The file a.md doesn't contain a bookmark named 'b4'.", "b.md"),
Tuple.Create(@"Invalid link: '<a href=""#b1"">Test local link</a>'. The file f.md doesn't contain a bookmark named 'b1'.", "f.md"),
Tuple.Create(@"Invalid link: '[local link in token file](#b3)'. The file g.md doesn't contain a bookmark named 'b3'.", "token.md"),
Tuple.Create("Invalid link: '[local link in token file](#b3)'. The file g.md doesn't contain a bookmark named 'b3'.", "token.md"),
};
var actual = logs.Select(l => Tuple.Create(l.Message, l.File)).ToList();
Assert.True(!expected.Except(actual).Any() && expected.Length == actual.Count);
Expand All @@ -97,8 +97,8 @@ public void TestNoCheck()
new ManifestItem { SourceRelativePath = "testNoCheckBookmark.md", Output = { { ".html", new OutputFileInfo { RelativePath = "testNoCheckBookmark.html" } } } },
}
};
File.WriteAllText(Path.Combine(_outputFolder, "test.html"), @"<a href='test.html#invalid'>test</a>");
File.WriteAllText(Path.Combine(_outputFolder, "testNoCheckBookmark.html"), @"<a href='test.html#invalid' nocheck='bookmark'>test</a>");
File.WriteAllText(Path.Combine(_outputFolder, "test.html"), "<a href='test.html#invalid'>test</a>");
File.WriteAllText(Path.Combine(_outputFolder, "testNoCheckBookmark.html"), "<a href='test.html#invalid' nocheck='bookmark'>test</a>");

// Act
Logger.RegisterListener(_listener);
Expand Down
Loading

0 comments on commit c8409b4

Please sign in to comment.