Skip to content

Commit b3a6bc5

Browse files
Added Wintellect.Analyzers
1 parent d171587 commit b3a6bc5

7 files changed

+85
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ _UpgradeReport_Files/
114114
Backup*/
115115
UpgradeLog*.XML
116116

117+
packages/
117118

118119

119120
############

FF/ArgParser.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,8 @@ public Boolean Parse(String[] args)
199199
{
200200
ss = SwitchStatus.ShowUsage;
201201
}
202-
203-
int errorArg = -1;
204-
int currArg;
202+
Int32 errorArg = -1;
203+
Int32 currArg;
205204
for (currArg = 0;
206205
(ss == SwitchStatus.NoError) && (currArg < args.Length);
207206
currArg++)
@@ -218,9 +217,7 @@ public Boolean Parse(String[] args)
218217

219218
// Get the argument itself.
220219
String processedArg = args[currArg].Substring(1);
221-
222-
// The index into the symbol array.
223-
int n = this.IsSwitchInArray(this.flagSymbols, processedArg);
220+
Int32 n = this.IsSwitchInArray(this.flagSymbols, processedArg);
224221

225222
// If it's not in the flags array, try the data array if
226223
// that array is not null.
@@ -366,17 +363,16 @@ public Boolean Parse(String[] args)
366363
/// <returns>
367364
/// The index of the switch.
368365
/// </returns>
369-
private int IsSwitchInArray(String[] switchArray, String value)
366+
private Int32 IsSwitchInArray(String[] switchArray, String value)
370367
{
371368
String valueCompare = value;
372369
if (this.caseSensitiveSwitches)
373370
{
374371
valueCompare = value.ToUpperInvariant();
375372
}
373+
Int32 retValue = -1;
376374

377-
int retValue = -1;
378-
379-
for (int n = 0; n < switchArray.Length; n++)
375+
for (Int32 n = 0; n < switchArray.Length; n++)
380376
{
381377
String currSwitch = switchArray[n];
382378
if (this.caseSensitiveSwitches)
@@ -406,7 +402,7 @@ private int IsSwitchInArray(String[] switchArray, String value)
406402
private Boolean StartsWithSwitchChar(String value)
407403
{
408404
Boolean isSwitch = false;
409-
for (int n = 0; !isSwitch && (n < this.switchChars.Length); n++)
405+
for (Int32 n = 0; !isSwitch && (n < this.switchChars.Length); n++)
410406
{
411407
if (0 != String.CompareOrdinal(value, 0, this.switchChars[n], 0, 1))
412408
{

FF/FF.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<None Include="FF.ruleset">
6262
<SubType>Designer</SubType>
6363
</None>
64+
<None Include="packages.config" />
6465
</ItemGroup>
6566
<ItemGroup>
6667
<EmbeddedResource Include="Constants.resx">
@@ -74,6 +75,9 @@
7475
<SubType>Designer</SubType>
7576
</CodeAnalysisDictionary>
7677
</ItemGroup>
78+
<ItemGroup>
79+
<Analyzer Include="packages\Wintellect.Analyzers.1.0.5.0\analyzers\dotnet\cs\Wintellect.Analyzers.dll" />
80+
</ItemGroup>
7781
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
7882
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
7983
Other similar extension points exist, see Microsoft.Common.targets.

FF/FF.ruleset

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RuleSet Name="FF Rule Set" Description="This rule set contains all rules. Running this rule set may result in a large number of warnings being reported. Use this rule set to get a comprehensive picture of all issues in your code. This can help you decide which of the more focused rule sets are most appropriate to run for your projects." ToolsVersion="11.0">
2+
<RuleSet Name="FF Rule Set" Description="This rule set contains all rules. Running this rule set may result in a large number of warnings being reported. Use this rule set to get a comprehensive picture of all issues in your code. This can help you decide which of the more focused rule sets are most appropriate to run for your projects." ToolsVersion="14.0">
33
<IncludeAll Action="Warning" />
44
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
55
<Rule Id="CA1000" Action="Error" />
@@ -603,4 +603,7 @@
603603
<Rule Id="C6707" Action="Error" />
604604
<Rule Id="C6995" Action="Error" />
605605
</Rules>
606+
<Rules AnalyzerId="Wintellect.Analyzers" RuleNamespace="Wintellect.Analyzers">
607+
<Rule Id="Wintellect010" Action="None" />
608+
</Rules>
606609
</RuleSet>

FF/FastFindArgumentParser.cs

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,65 @@ namespace FastFind
1212
using System;
1313
using System.Collections.Generic;
1414
using System.Diagnostics;
15+
using System.Globalization;
1516
using System.IO;
1617
using System.Text;
1718
using System.Text.RegularExpressions;
1819

1920
/// <summary>
2021
/// Implements the command line parsing for the Fast Find program.
2122
/// </summary>
22-
internal class FastFindArgumentParser : ArgParser
23+
internal sealed class FastFindArgumentParser : ArgParser
2324
{
2425
/// <summary>
2526
/// The path flag.
2627
/// </summary>
27-
private const string PathFlag = "path";
28+
private const String PathFlag = "path";
2829

2930
/// <summary>
3031
/// The path flag short.
3132
/// </summary>
32-
private const string PathFlagShort = "p";
33+
private const String PathFlagShort = "p";
3334

3435
/// <summary>
3536
/// The use regular expressions flag.
3637
/// </summary>
37-
private const string RegExFlag = "regex";
38+
private const String RegExFlag = "regex";
3839

3940
/// <summary>
4041
/// The short use regular expressions flag.
4142
/// </summary>
42-
private const string RegExFlagShort = "re";
43+
private const String RegExFlagShort = "re";
4344

4445
/// <summary>
4546
/// The only files flag.
4647
/// </summary>
47-
private const string IncludeDirectoryName = "includedir";
48+
private const String IncludeDirectoryName = "includedir";
4849

4950
/// <summary>
5051
/// The short only files flag short.
5152
/// </summary>
52-
private const string IncludeDirectoryNameShort = "i";
53+
private const String IncludeDirectoryNameShort = "i";
5354

5455
/// <summary>
5556
/// The no statistics flag.
5657
/// </summary>
57-
private const string NoStats = "nostats";
58+
private const String NoStats = "nostats";
5859

5960
/// <summary>
6061
/// The short no stats flag.
6162
/// </summary>
62-
private const string NoStatsShort = "ns";
63+
private const String NoStatsShort = "ns";
6364

6465
/// <summary>
6566
/// The help flag.
6667
/// </summary>
67-
private const string HelpFlag = "help";
68+
private const String HelpFlag = "help";
6869

6970
/// <summary>
7071
/// The short help flag.
7172
/// </summary>
72-
private const string HelpFlagShort = "?";
73+
private const String HelpFlagShort = "?";
7374

7475
/// <summary>
7576
/// The raw patterns as they come in from the command line.
@@ -131,7 +132,7 @@ public FastFindArgumentParser()
131132
/// <param name="errorInfo">
132133
/// The string with the invalid command line option.
133134
/// </param>
134-
public override void OnUsage(string errorInfo)
135+
public override void OnUsage(String errorInfo)
135136
{
136137
ProcessModule exe = Process.GetCurrentProcess().Modules[0];
137138
Console.WriteLine(Constants.UsageString, exe.FileVersionInfo.FileVersion);
@@ -159,32 +160,15 @@ public override void OnUsage(string errorInfo)
159160
/// <returns>
160161
/// One of the <see cref="ArgParser.SwitchStatus"/> values.
161162
/// </returns>
162-
protected override SwitchStatus OnSwitch(string switchSymbol, string switchValue)
163+
protected override SwitchStatus OnSwitch(String switchSymbol, String switchValue)
163164
{
164165
SwitchStatus ss = SwitchStatus.NoError;
165166

166167
switch (switchSymbol)
167168
{
168169
case PathFlag:
169170
case PathFlagShort:
170-
if (false == String.IsNullOrEmpty(this.Path))
171-
{
172-
this.errorMessage = Constants.PathMultipleSwitches;
173-
ss = SwitchStatus.Error;
174-
}
175-
else
176-
{
177-
if (Directory.Exists(switchValue))
178-
{
179-
this.Path = switchValue;
180-
}
181-
else
182-
{
183-
this.errorMessage = Constants.PathNotExist;
184-
ss = SwitchStatus.Error;
185-
}
186-
}
187-
171+
ss = TestPath(switchValue);
188172
break;
189173

190174
case RegExFlag:
@@ -225,7 +209,7 @@ protected override SwitchStatus OnSwitch(string switchSymbol, string switchValue
225209
/// <returns>
226210
/// One of the <see cref="ArgParser.SwitchStatus"/> values.
227211
/// </returns>
228-
protected override SwitchStatus OnNonSwitch(string value)
212+
protected override SwitchStatus OnNonSwitch(String value)
229213
{
230214
// Just add this to the list of patterns to search for.
231215
this.rawPatterns.Add(value);
@@ -257,7 +241,7 @@ protected override SwitchStatus OnDoneParse()
257241
else
258242
{
259243
// Convert all the raw patterns into regular expressions.
260-
for (int i = 0; i < this.rawPatterns.Count; i++)
244+
for (Int32 i = 0; i < this.rawPatterns.Count; i++)
261245
{
262246
String thePattern = this.rawPatterns[i];
263247
if (false == this.useRegEx)
@@ -278,7 +262,10 @@ protected override SwitchStatus OnDoneParse()
278262
// when the user specified the -regex switch and they
279263
// used a DOS wildcard pattern like *..
280264
StringBuilder sb = new StringBuilder();
281-
sb.AppendFormat(Constants.InvalidRegExFmt, thePattern, e.Message);
265+
sb.AppendFormat(CultureInfo.CurrentCulture,
266+
Constants.InvalidRegExFmt,
267+
thePattern,
268+
e.Message);
282269
this.errorMessage = sb.ToString();
283270
ss = SwitchStatus.Error;
284271
break;
@@ -288,5 +275,39 @@ protected override SwitchStatus OnDoneParse()
288275

289276
return ss;
290277
}
278+
279+
/// <summary>
280+
/// Isolates the checking for the path parameter.
281+
/// </summary>
282+
/// <param name="pathToTest">
283+
/// The path value to test.
284+
/// </param>
285+
/// <returns>
286+
/// A valid <see cref="SwitchStatus"/> value.
287+
/// </returns>
288+
private SwitchStatus TestPath(String pathToTest)
289+
{
290+
SwitchStatus ss = SwitchStatus.Error;
291+
if (false == String.IsNullOrEmpty(this.Path))
292+
{
293+
this.errorMessage = Constants.PathMultipleSwitches;
294+
ss = SwitchStatus.Error;
295+
}
296+
else
297+
{
298+
if (Directory.Exists(pathToTest))
299+
{
300+
this.Path = pathToTest;
301+
}
302+
else
303+
{
304+
this.errorMessage = Constants.PathNotExist;
305+
ss = SwitchStatus.Error;
306+
}
307+
}
308+
309+
return ss;
310+
}
311+
291312
}
292313
}

FF/Program.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ internal static class Program
2929
/// <summary>
3030
/// The total number of matching files and directories.
3131
/// </summary>
32-
private static int totalMatches;
32+
private static Int64 totalMatches;
3333

3434
/// <summary>
3535
/// The total number of files looked at.
3636
/// </summary>
37-
private static int totalFiles;
37+
private static Int64 totalFiles;
3838

3939
/// <summary>
4040
/// The total number of directories looked at.
4141
/// </summary>
42-
private static int totalDirectories;
42+
private static Int64 totalDirectories;
4343

4444
/// <summary>
4545
/// The entry point function for the program.
@@ -51,9 +51,9 @@ internal static class Program
5151
/// 0 - Proper execution
5252
/// 1 - Invalid command line.
5353
/// </returns>
54-
internal static int Main(string[] args)
54+
internal static Int32 Main(String[] args)
5555
{
56-
int returnValue = 0;
56+
Int32 returnValue = 0;
5757

5858
Stopwatch timer = new Stopwatch();
5959

@@ -98,7 +98,7 @@ internal static int Main(string[] args)
9898
/// <param name="args">
9999
/// Any additional items to include in the output.
100100
/// </param>
101-
internal static void WriteError(string message, params Object[] args)
101+
internal static void WriteError(String message, params Object[] args)
102102
{
103103
ColorWriteLine(ConsoleColor.Red, message, args);
104104
}
@@ -109,7 +109,7 @@ internal static void WriteError(string message, params Object[] args)
109109
/// <param name="message">
110110
/// The message to write.
111111
/// </param>
112-
internal static void WriteError(string message)
112+
internal static void WriteError(String message)
113113
{
114114
ColorWriteLine(ConsoleColor.Red, message, null);
115115
}
@@ -160,7 +160,7 @@ private static void ColorWriteLine(ConsoleColor color,
160160
/// </returns>
161161
private static Boolean IsNameMatch(String name)
162162
{
163-
for (int i = 0; i < Options.Patterns.Count; i++)
163+
for (Int32 i = 0; i < Options.Patterns.Count; i++)
164164
{
165165
if (Options.Patterns[i].IsMatch(name))
166166
{
@@ -185,7 +185,7 @@ private static void RecurseFiles(String directory)
185185

186186
Interlocked.Add(ref totalFiles, files.Length);
187187

188-
for (int i = 0; i < files.Length; i++)
188+
for (Int32 i = 0; i < files.Length; i++)
189189
{
190190
String currFile = files[i];
191191
if (false == Options.IncludeDirectories)
@@ -204,7 +204,7 @@ private static void RecurseFiles(String directory)
204204
String[] dirs = Directory.GetDirectories(directory);
205205
Interlocked.Add(ref totalDirectories, dirs.Length);
206206

207-
for (int i = 0; i < dirs.Length; i++)
207+
for (Int32 i = 0; i < dirs.Length; i++)
208208
{
209209
String currDir = dirs[i];
210210
if (Options.IncludeDirectories)

FF/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Wintellect.Analyzers" version="1.0.5.0" targetFramework="net461" />
4+
</packages>

0 commit comments

Comments
 (0)