Skip to content

Commit daffc33

Browse files
authored
String Method FxCop Error Mop Up (#1337)
* Fix a few more FxCop Warnings about String Methods **Bug** Various FxCop warnings about strings, such as using the implicit overloads vs explicit ones. **Fix** - Make `Parse` methods use invarient culture. - Fix a few more `StartsWith` calls - Fix a few more format calls. * A bit more mopup
1 parent 7166537 commit daffc33

17 files changed

+38
-27
lines changed

Nodejs/Product/LogConverter/LogParsing/LogConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ private static void ParseLocation(string location, out string fileName, out stri
511511
// To cover them all, we just repeatedly strip the tail of the string after the last ':',
512512
// so long as it can be parsed as an integer.
513513
int colon;
514-
while ((colon = location.LastIndexOf(':')) != -1) {
514+
while ((colon = location.LastIndexOf(":", StringComparison.Ordinal)) != -1) {
515515
string tail = location.Substring(colon + 1, location.Length - (colon + 1));
516516
int number;
517517
if (!Int32.TryParse(tail, out number)) {

Nodejs/Product/Nodejs/Commands/ImportWizardCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//*********************************************************//
1616

1717
using System;
18+
using System.Globalization;
1819
using System.IO;
1920
using System.Threading.Tasks;
2021
using System.Threading;
@@ -48,7 +49,7 @@ public override void DoCommand(object sender, EventArgs args) {
4849
".njsproj"
4950
);
5051
dlg.ImportSettings.SourcePath = argItems[1];
51-
commandIdToRaise = int.Parse(argItems[2]);
52+
commandIdToRaise = int.Parse(argItems[2], CultureInfo.InvariantCulture);
5253
}
5354
}
5455
}

Nodejs/Product/Nodejs/Debugger/NodeEvaluationResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//*********************************************************//
1616

1717
using System.Collections.Generic;
18+
using System.Globalization;
1819
using System.Text.RegularExpressions;
1920
using System.Threading;
2021
using System.Threading.Tasks;
@@ -113,7 +114,7 @@ private int GetStringLength(string stringValue) {
113114
return stringValue.Length;
114115
}
115116

116-
return int.Parse(match.Groups[1].Value);
117+
return int.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
117118
}
118119
}
119120
}

Nodejs/Product/Nodejs/JsonListener.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using System;
1818
using System.Collections.Generic;
1919
using System.Diagnostics;
20+
using System.Globalization;
2021
using System.Net.Sockets;
2122
using System.Text;
2223
using System.Threading;
@@ -81,7 +82,7 @@ private void ListenerThread() {
8182
string body = String.Empty;
8283
string contentLen;
8384
if (headers.TryGetValue("Content-Length", out contentLen)) {
84-
int lengthRemaining = Int32.Parse(contentLen);
85+
int lengthRemaining = int.Parse(contentLen, CultureInfo.InvariantCulture);
8586
if (lengthRemaining != 0) {
8687
StringBuilder bodyBuilder = new StringBuilder();
8788

Nodejs/Product/Npm/PackageComparer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//
1515
//*********************************************************//
1616

17+
using System;
1718
using System.Collections.Generic;
1819

1920
namespace Microsoft.NodejsTools.Npm {
@@ -27,7 +28,7 @@ public int Compare(IPackage x, IPackage y) {
2728
return 1;
2829
}
2930
// TODO: should take into account versions!
30-
return x.Name.CompareTo(y.Name);
31+
return string.Compare(x.Name, y.Name, StringComparison.Ordinal);
3132
}
3233
}
3334

Nodejs/Product/Npm/SPI/DatabasePackageCatalogFilter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public int Compare(CatalogEntry x, CatalogEntry y) {
7373
}
7474

7575
private int? CompareEntryStrings(string x, string y) {
76-
var xIndex = string.IsNullOrEmpty(x) ? -1 : x.ToLower().IndexOf(_filterText, StringComparison.OrdinalIgnoreCase);
77-
var yIndex = string.IsNullOrEmpty(y) ? -1 : y.ToLower().IndexOf(_filterText, StringComparison.OrdinalIgnoreCase);
76+
var xIndex = string.IsNullOrEmpty(x) ? -1 : x.ToLower(CultureInfo.InvariantCulture).IndexOf(_filterText, StringComparison.OrdinalIgnoreCase);
77+
var yIndex = string.IsNullOrEmpty(y) ? -1 : y.ToLower(CultureInfo.InvariantCulture).IndexOf(_filterText, StringComparison.OrdinalIgnoreCase);
7878

7979
int? xEqualsY = null;
8080
const int xBeforeY = -1;

Nodejs/Product/Npm/SPI/DependencyUrl.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//
1515
//*********************************************************//
1616

17+
using System;
18+
1719
namespace Microsoft.NodejsTools.Npm.SPI {
1820
internal class DependencyUrl : IDependencyUrl {
1921
public DependencyUrl(string address) {
@@ -24,7 +26,7 @@ public DependencyUrl(string address) {
2426

2527
public DependencyUrlType Type {
2628
get {
27-
var index = Address.IndexOf("://");
29+
var index = Address.IndexOf("://", StringComparison.Ordinal);
2830
if (index < 0) {
2931
return DependencyUrlType.GitHub;
3032
} else {

Nodejs/Product/Npm/SPI/NodeModules.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public NodeModules(IRootPackage parent, bool showMissingDevOptionalSubPackages,
7575
break;
7676
}
7777

78-
var parentNodeModulesIndex = moduleDir.LastIndexOf(NodejsConstants.NodeModulesFolder, Math.Max(0, moduleDir.Length - NodejsConstants.NodeModulesFolder.Length - dependency.Name.Length - 1));
78+
var parentNodeModulesIndex = moduleDir.LastIndexOf(NodejsConstants.NodeModulesFolder, Math.Max(0, moduleDir.Length - NodejsConstants.NodeModulesFolder.Length - dependency.Name.Length - 1), StringComparison.Ordinal);
7979
moduleDir = moduleDir.Substring(0, parentNodeModulesIndex + NodejsConstants.NodeModulesFolder.Length);
8080
} while (moduleDir.Contains(NodejsConstants.NodeModulesFolder));
8181
}
@@ -140,8 +140,8 @@ private bool AddModuleIfNotExists(IRootPackage parent, string moduleDir, bool sh
140140
}
141141

142142
public override int GetDepth(string filepath) {
143-
var lastNodeModules = filepath.LastIndexOf(NodejsConstants.NodeModulesFolder + "\\");
144-
var directoryToSearch = filepath.IndexOf("\\", lastNodeModules + NodejsConstants.NodeModulesFolder.Length + 1);
143+
var lastNodeModules = filepath.LastIndexOf(NodejsConstants.NodeModulesFolder + "\\", StringComparison.Ordinal);
144+
var directoryToSearch = filepath.IndexOf("\\", lastNodeModules + NodejsConstants.NodeModulesFolder.Length + 1, StringComparison.Ordinal);
145145
var directorySubString = directoryToSearch == -1 ? filepath : filepath.Substring(0, directoryToSearch);
146146

147147
ModuleInfo value = null;

Nodejs/Product/Npm/SPI/NpmSearchFilterStringComparer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//*********************************************************//
1616

1717
using System;
18+
using System.Globalization;
1819
using System.Linq;
1920

2021
namespace Microsoft.NodejsTools.Npm.SPI {
@@ -26,15 +27,15 @@ public NpmSearchFilterStringComparer(string filterString) {
2627
}
2728

2829
private int GetExactKeywordMatchCount(IPackage source) {
29-
return source.Keywords == null ? 0 : source.Keywords.Count(keyword => keyword.ToLower() == _filterString);
30+
return source.Keywords == null ? 0 : source.Keywords.Count(keyword => keyword.ToLower(CultureInfo.InvariantCulture) == _filterString);
3031
}
3132

3233
private int GetStartsWithMatchCount(IPackage source) {
33-
return source.Keywords == null ? 0 : source.Keywords.Count(keyword => keyword.ToLower().StartsWith(_filterString));
34+
return source.Keywords == null ? 0 : source.Keywords.Count(keyword => keyword.ToLower(CultureInfo.InvariantCulture).StartsWith(_filterString, StringComparison.Ordinal));
3435
}
3536

3637
private int GetPartialKeywordMatchCount(IPackage source) {
37-
return source.Keywords == null ? 0 : source.Keywords.Count(keyword => keyword.ToLower().Contains(_filterString));
38+
return source.Keywords == null ? 0 : source.Keywords.Count(keyword => keyword.ToLower(CultureInfo.InvariantCulture).Contains(_filterString));
3839
}
3940

4041
private new int CompareBasedOnKeywords(IPackage x, IPackage y) {

Nodejs/Product/Npm/SemverVersion.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public static SemverVersion Parse(string versionString) {
6262
// /Hack
6363

6464
return new SemverVersion(
65-
ulong.Parse(match.Groups["major"].Value),
66-
ulong.Parse(match.Groups["minor"].Value),
67-
ulong.Parse(patch),
65+
ulong.Parse(match.Groups["major"].Value, CultureInfo.InvariantCulture),
66+
ulong.Parse(match.Groups["minor"].Value, CultureInfo.InvariantCulture),
67+
ulong.Parse(patch, CultureInfo.InvariantCulture),
6868
preRelease.Success ? preRelease.Value : null,
6969
buildMetadata.Success ? buildMetadata.Value : null);
7070
} catch (OverflowException oe) {

0 commit comments

Comments
 (0)