Skip to content

Commit d7404b6

Browse files
authored
Bug fixes (#40)
* Upgrade nuget packages * added check for parts array * bumped version * checkpoint * update * checkpoint * checkpoint * checkpoint * checkpoint * fixed tests * package cleanup * fixed private methods in interfaces tests * cleanup added support to convert settings to editorconfig settings * split out common to netstandard2.0 * cleanup * checkpoint * cp * cleanup * cleanup optionsService * wordmap cleanup * param cleanup * checkpoint * checkpoint * removed optionservice * checkpoint * checkpoint * checkpoint * removed embedded Settings * checkpoint * cleanup * cleanup * updated readme
1 parent 9a11cd7 commit d7404b6

File tree

110 files changed

+2632
-1866
lines changed

Some content is hidden

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

110 files changed

+2632
-1866
lines changed

.github/workflows/dotnet.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ env:
2929
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
3030
DOTNET_NOLOGO: true
3131
VisxDirectory: ${{github.workspace}}/vsix
32-
Version: '2.1.0.${{ github.run_number }}'
33-
BaseVersion: '2.1.0.0'
32+
Version: '2.1.1.${{ github.run_number }}'
33+
BaseVersion: '2.1.1.0'
3434

3535
defaults:
3636
run:
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.13.0" />
9+
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
10+
<PackageReference Include="Pluralize.NET" Version="1.0.2" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
// For definitions of XML nodes see:
22
// https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments see
33
// also https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags
4+
using System;
45
using System.Collections.Generic;
5-
using CodeDocumentor.Helper;
6+
using CodeDocumentor.Common.Models;
67
using Microsoft.CodeAnalysis;
78

8-
namespace CodeDocumentor.Vsix2022
9+
namespace CodeDocumentor.Common
910
{
1011
public static class Constants
1112
{
1213
public const DiagnosticSeverity DefaultDiagnosticSeverityOnError = DiagnosticSeverity.Info;
1314

15+
public const string TODO = "TODO: Add Summary";
16+
1417
public static class EventIds
1518
{
1619
public const int ANALYZER = 1000;
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text.RegularExpressions;
5+
using CodeDocumentor.Common;
6+
using CodeDocumentor.Common.Models;
7+
using Microsoft.CodeAnalysis;
8+
9+
namespace CodeDocumentor.Helper
10+
{
11+
public static class ListExtensions
12+
{
13+
public static List<string> AddCustomPart(this List<string> parts, string part = null, int idx = -1)
14+
{
15+
if (part is null)
16+
{
17+
return parts;
18+
}
19+
if (idx == -1)
20+
{
21+
parts.Add(part);
22+
return parts;
23+
}
24+
parts.Insert(idx, part);
25+
return parts;
26+
}
27+
28+
public static string JoinToString(this List<string> parts, string delimiter = " ")
29+
{
30+
return $"{string.Join(delimiter, parts)}";
31+
}
32+
33+
public static List<string> PluaralizeLastWord(this List<string> parts)
34+
{
35+
var lastIdx = parts.Count - 1;
36+
parts[lastIdx] = Pluralizer.ForcePluralization(parts[lastIdx]);
37+
return parts;
38+
}
39+
40+
public static List<string> Tap(this List<string> parts, Action<List<string>> tapAction)
41+
{
42+
tapAction?.Invoke(parts);
43+
return parts;
44+
}
45+
46+
public static List<string> ToLowerParts(this List<string> parts, bool forceFirstCharToLower = false)
47+
{
48+
var i = forceFirstCharToLower ||
49+
(
50+
parts.Count > 0 &&
51+
!parts[0].Equals("The", StringComparison.InvariantCultureIgnoreCase) &&
52+
!parts[0].Equals("If true,", StringComparison.InvariantCultureIgnoreCase) &&
53+
!parts[0].IsVerb() //if the first word is a verb we are not adding The anyway so we need to leave it Pascal
54+
)
55+
? 0 : 1;
56+
57+
parts.SwapXmlTokens((part) =>
58+
{
59+
if (!part.All(a => char.IsUpper(a)))
60+
{
61+
part = part.ToLower();
62+
}
63+
return part;
64+
}, i);
65+
66+
//First letter is always caps unless it was forced lower
67+
if (!forceFirstCharToLower && parts.Count > 0 && char.IsLower(parts[0], 0))
68+
{
69+
parts[0] = parts[0].ToTitleCase();
70+
}
71+
return parts;
72+
}
73+
74+
public static List<string> TranslateParts(this List<string> parts, WordMap[] wordMaps)
75+
{
76+
for (var i = 0; i < parts.Count; i++)
77+
{
78+
var nextWord = i + 1 < parts.Count ? parts[i + 1] : null;
79+
var userMaps = wordMaps ?? Array.Empty<WordMap>();
80+
foreach (var wordMap in Constants.INTERNAL_WORD_MAPS)
81+
{
82+
if (!CanEvaluateWordMap(wordMap, i))
83+
{
84+
continue;
85+
}
86+
//dont run an internal word map if the user has one for the same thing
87+
if (!userMaps.Any(a => a.Word == wordMap.Word))
88+
{
89+
var wordToLookFor = string.Format(Constants.WORD_MATCH_REGEX_TEMPLATE, wordMap.Word);
90+
parts[i] = Regex.Replace(parts[i], wordToLookFor, wordMap.GetTranslation(nextWord));
91+
}
92+
}
93+
}
94+
return parts;
95+
}
96+
97+
private static bool CanEvaluateWordMap(WordMap wordMap, int partIdx)
98+
{
99+
return wordMap.Word != "Is" || partIdx == 0;
100+
}
101+
102+
public static List<string> TryInsertTheWord(this List<string> parts, Action<List<string>> customInsertCallback = null)
103+
{
104+
if (customInsertCallback != null)
105+
{
106+
customInsertCallback.Invoke(parts);
107+
}
108+
else if (parts.Count > 0)
109+
{
110+
var checkWord = parts[0].GetWordFirstPart();
111+
var skipThe = checkWord.IsVerb();
112+
var addTheAnyway = Constants.ADD_THE_ANYWAY_LIST.Any(w => w.Equals(parts[0], StringComparison.InvariantCultureIgnoreCase));
113+
if (!skipThe || addTheAnyway)
114+
{
115+
if (!parts[0].Equals("the", StringComparison.InvariantCultureIgnoreCase))
116+
{
117+
parts.Insert(0, "The");
118+
}
119+
else
120+
{
121+
parts[0] = "The"; //force casing
122+
}
123+
}
124+
}
125+
return parts;
126+
}
127+
128+
public static List<string> AddPropertyBooleanPart(this List<string> parts)
129+
{
130+
if (parts.Count > 0)
131+
{
132+
var booleanPart = " a value indicating whether to";
133+
if (parts[0].IsPastTense() || parts[0].IsVerb())
134+
{
135+
booleanPart = "a value indicating whether";
136+
}
137+
138+
//is messes up readability. Lets remove it. ex) IsEnabledForDays
139+
var isTwoLettweWord = parts[0].IsTwoLetterPropertyExclusionVerb();//we only care if forst word is relavent
140+
if (isTwoLettweWord)
141+
{
142+
parts.Remove(parts[0]);
143+
}
144+
parts.Insert(0, booleanPart);
145+
}
146+
147+
return parts;
148+
}
149+
150+
public static List<string> HandleAsyncKeyword(this List<string> parts, bool excludeAsyncSuffix)
151+
{
152+
if (excludeAsyncSuffix && parts.Last().IndexOf("async", StringComparison.OrdinalIgnoreCase) > -1)
153+
{
154+
parts.Remove(parts.Last());
155+
}
156+
var idx = parts.FindIndex(f => f.Equals("async", StringComparison.OrdinalIgnoreCase));
157+
if (idx > -1)
158+
{
159+
parts[idx] = "asynchronously";
160+
}
161+
return parts;
162+
}
163+
164+
public static List<string> TryAddTodoSummary(this List<string> parts, string returnType, bool useToDoCommentsOnSummaryError)
165+
{
166+
if (returnType == "void" && (parts.Count == 1 || (parts.Count == 2 && parts.Last() == "asynchronously")))
167+
{
168+
if (useToDoCommentsOnSummaryError)
169+
{
170+
parts = new List<string> { Constants.TODO};
171+
}
172+
else
173+
{
174+
parts = new List<string>();
175+
}
176+
}
177+
return parts;
178+
}
179+
180+
public static List<string> TryPluarizeFirstWord(this List<string> parts)
181+
{
182+
if (parts.Count > 0)
183+
{
184+
if (parts.Count >= 2)
185+
{
186+
parts[0] = Pluralizer.Pluralize(parts[0], parts[1]);
187+
}
188+
else
189+
{
190+
parts[0] = Pluralizer.Pluralize(parts[0]);
191+
}
192+
}
193+
return parts;
194+
}
195+
}
196+
}

0 commit comments

Comments
 (0)