Skip to content
Browse files

Experimented with Visual Studio's Code Analysis feature. Added new fi…

…les CodeAnalysisRuleSet.ruleset and CustomDictionary.xml. Fixed a few Format strings that Code Analysis found problems with. Code analysis is producing hundreds of warnings. We will work through them little by little. Most are pretty harmless, but it would be nice to get rid of them where possible.
  • Loading branch information...
1 parent cba1e64 commit bed49e7f8c2b49c8c443c5756321dacb04363af7 rstam committed
View
7 Bson/Bson.csproj
@@ -40,7 +40,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
+ <CodeAnalysisRuleSet>..\CodeAnalysisRuleSet.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\Debug\MongoDB.Bson.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -227,6 +227,11 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
+ <ItemGroup>
+ <CodeAnalysisDictionary Include="..\CustomDictionary.xml">
+ <Link>CustomDictionary.xml</Link>
+ </CodeAnalysisDictionary>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
View
2 Bson/IO/BsonBinaryReader.cs
@@ -611,7 +611,7 @@ private int ReadSize()
}
if (size > settings.MaxDocumentSize)
{
- var message = string.Format("Size {0} is not valid because it is larger than MaxDocumentSize {0}.", size, settings.MaxDocumentSize);
+ var message = string.Format("Size {0} is not valid because it is larger than MaxDocumentSize {1}.", size, settings.MaxDocumentSize);
throw new FileFormatException(message);
}
return size;
View
2 Bson/Serialization/Serializers/BsonValueSerializers.cs
@@ -181,7 +181,7 @@ public override void Serialize(BsonWriter bsonWriter, Type nominalType, object v
if (guidRepresentation == GuidRepresentation.Unspecified)
{
var message = string.Format(
- "Cannot serialize BsonBinaryData with GuidRepresentation Unspecified to destination with GuidRepresentation {1}.",
+ "Cannot serialize BsonBinaryData with GuidRepresentation Unspecified to destination with GuidRepresentation {0}.",
writerGuidRepresentation);
throw new BsonSerializationException(message);
}
View
6 Bson/Serialization/Serializers/ObjectSerializer.cs
@@ -62,7 +62,7 @@ public object Deserialize(BsonReader bsonReader, Type nominalType, IBsonSerializ
{
if (nominalType != typeof(object))
{
- var message = string.Format("ObjectSerializer can only be used with nominal type System.Object, not type {1}.", nominalType.FullName);
+ var message = string.Format("ObjectSerializer can only be used with nominal type System.Object, not type {0}.", nominalType.FullName);
throw new InvalidOperationException(message);
}
@@ -111,7 +111,7 @@ public object Deserialize(BsonReader bsonReader, Type nominalType, Type actualTy
{
if (actualType != typeof(object))
{
- var message = string.Format("ObjectSerializer can only be used with actual type System.Object, not type {1}.", actualType.FullName);
+ var message = string.Format("ObjectSerializer can only be used with actual type System.Object, not type {0}.", actualType.FullName);
throw new ArgumentException(message, "actualType");
}
@@ -173,7 +173,7 @@ public void Serialize(BsonWriter bsonWriter, Type nominalType, object value, IBs
var actualType = value.GetType();
if (actualType != typeof(object))
{
- var message = string.Format("ObjectSerializer can only be used with type System.Object, not type {1}.", actualType.FullName);
+ var message = string.Format("ObjectSerializer can only be used with type System.Object, not type {0}.", actualType.FullName);
throw new InvalidOperationException(message);
}
View
2 CSharpDriver-2010.sln
@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DriverOnlineTests", "Driver
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{00502D63-7789-410D-B6BE-5F16327FF810}"
ProjectSection(SolutionItems) = preProject
+ CodeAnalysisRuleSet.ruleset = CodeAnalysisRuleSet.ruleset
+ CustomDictionary.xml = CustomDictionary.xml
GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs
README.md = README.md
Release Notes v1.3.txt = Release Notes v1.3.txt
View
234 CodeAnalysisRuleSet.ruleset
@@ -0,0 +1,234 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RuleSet Name="New Rule Set" Description=" " ToolsVersion="10.0">
+ <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
+ <Rule Id="CA1000" Action="Warning" />
+ <Rule Id="CA1001" Action="Warning" />
+ <Rule Id="CA1002" Action="Warning" />
+ <Rule Id="CA1003" Action="Warning" />
+ <Rule Id="CA1004" Action="Warning" />
+ <Rule Id="CA1005" Action="Warning" />
+ <Rule Id="CA1006" Action="Warning" />
+ <Rule Id="CA1007" Action="Warning" />
+ <Rule Id="CA1008" Action="Warning" />
+ <Rule Id="CA1009" Action="Warning" />
+ <Rule Id="CA1010" Action="Warning" />
+ <Rule Id="CA1011" Action="Warning" />
+ <Rule Id="CA1012" Action="Warning" />
+ <Rule Id="CA1013" Action="Warning" />
+ <Rule Id="CA1014" Action="Warning" />
+ <Rule Id="CA1016" Action="Warning" />
+ <Rule Id="CA1017" Action="Warning" />
+ <Rule Id="CA1018" Action="Warning" />
+ <Rule Id="CA1019" Action="Warning" />
+ <Rule Id="CA1020" Action="Warning" />
+ <Rule Id="CA1021" Action="Warning" />
+ <Rule Id="CA1023" Action="Warning" />
+ <Rule Id="CA1024" Action="Warning" />
+ <Rule Id="CA1025" Action="Warning" />
+ <Rule Id="CA1026" Action="Warning" />
+ <Rule Id="CA1027" Action="Warning" />
+ <Rule Id="CA1028" Action="Warning" />
+ <Rule Id="CA1030" Action="Warning" />
+ <Rule Id="CA1031" Action="Warning" />
+ <Rule Id="CA1032" Action="Warning" />
+ <Rule Id="CA1033" Action="Warning" />
+ <Rule Id="CA1034" Action="Warning" />
+ <Rule Id="CA1035" Action="Warning" />
+ <Rule Id="CA1036" Action="Warning" />
+ <Rule Id="CA1038" Action="Warning" />
+ <Rule Id="CA1039" Action="Warning" />
+ <Rule Id="CA1040" Action="Warning" />
+ <Rule Id="CA1041" Action="Warning" />
+ <Rule Id="CA1043" Action="Warning" />
+ <Rule Id="CA1044" Action="Warning" />
+ <Rule Id="CA1045" Action="Warning" />
+ <Rule Id="CA1046" Action="Warning" />
+ <Rule Id="CA1047" Action="Warning" />
+ <Rule Id="CA1048" Action="Warning" />
+ <Rule Id="CA1049" Action="Warning" />
+ <Rule Id="CA1050" Action="Warning" />
+ <Rule Id="CA1051" Action="Warning" />
+ <Rule Id="CA1052" Action="Warning" />
+ <Rule Id="CA1053" Action="Warning" />
+ <Rule Id="CA1054" Action="Warning" />
+ <Rule Id="CA1055" Action="Warning" />
+ <Rule Id="CA1056" Action="Warning" />
+ <Rule Id="CA1057" Action="Warning" />
+ <Rule Id="CA1058" Action="Warning" />
+ <Rule Id="CA1059" Action="Warning" />
+ <Rule Id="CA1060" Action="Warning" />
+ <Rule Id="CA1061" Action="Warning" />
+ <Rule Id="CA1062" Action="Warning" />
+ <Rule Id="CA1063" Action="Warning" />
+ <Rule Id="CA1064" Action="Warning" />
+ <Rule Id="CA1065" Action="Warning" />
+ <Rule Id="CA1300" Action="Warning" />
+ <Rule Id="CA1301" Action="Warning" />
+ <Rule Id="CA1302" Action="Warning" />
+ <Rule Id="CA1303" Action="Warning" />
+ <Rule Id="CA1304" Action="Warning" />
+ <Rule Id="CA1305" Action="Warning" />
+ <Rule Id="CA1306" Action="Warning" />
+ <Rule Id="CA1307" Action="Warning" />
+ <Rule Id="CA1308" Action="Warning" />
+ <Rule Id="CA1309" Action="Warning" />
+ <Rule Id="CA1400" Action="Warning" />
+ <Rule Id="CA1401" Action="Warning" />
+ <Rule Id="CA1402" Action="Warning" />
+ <Rule Id="CA1403" Action="Warning" />
+ <Rule Id="CA1404" Action="Warning" />
+ <Rule Id="CA1405" Action="Warning" />
+ <Rule Id="CA1406" Action="Warning" />
+ <Rule Id="CA1407" Action="Warning" />
+ <Rule Id="CA1408" Action="Warning" />
+ <Rule Id="CA1409" Action="Warning" />
+ <Rule Id="CA1410" Action="Warning" />
+ <Rule Id="CA1411" Action="Warning" />
+ <Rule Id="CA1412" Action="Warning" />
+ <Rule Id="CA1413" Action="Warning" />
+ <Rule Id="CA1414" Action="Warning" />
+ <Rule Id="CA1415" Action="Warning" />
+ <Rule Id="CA1500" Action="Warning" />
+ <Rule Id="CA1501" Action="Warning" />
+ <Rule Id="CA1502" Action="Warning" />
+ <Rule Id="CA1504" Action="Warning" />
+ <Rule Id="CA1505" Action="Warning" />
+ <Rule Id="CA1506" Action="Warning" />
+ <Rule Id="CA1600" Action="Warning" />
+ <Rule Id="CA1601" Action="Warning" />
+ <Rule Id="CA1700" Action="Warning" />
+ <Rule Id="CA1701" Action="Warning" />
+ <Rule Id="CA1702" Action="Warning" />
+ <Rule Id="CA1703" Action="Warning" />
+ <Rule Id="CA1704" Action="Warning" />
+ <Rule Id="CA1707" Action="Warning" />
+ <Rule Id="CA1708" Action="Warning" />
+ <Rule Id="CA1709" Action="Warning" />
+ <Rule Id="CA1710" Action="Warning" />
+ <Rule Id="CA1711" Action="Warning" />
+ <Rule Id="CA1712" Action="Warning" />
+ <Rule Id="CA1713" Action="Warning" />
+ <Rule Id="CA1714" Action="Warning" />
+ <Rule Id="CA1715" Action="Warning" />
+ <Rule Id="CA1716" Action="Warning" />
+ <Rule Id="CA1717" Action="Warning" />
+ <Rule Id="CA1719" Action="Warning" />
+ <Rule Id="CA1720" Action="Warning" />
+ <Rule Id="CA1721" Action="Warning" />
+ <Rule Id="CA1722" Action="Warning" />
+ <Rule Id="CA1724" Action="Warning" />
+ <Rule Id="CA1725" Action="Warning" />
+ <Rule Id="CA1726" Action="Warning" />
+ <Rule Id="CA1800" Action="Warning" />
+ <Rule Id="CA1801" Action="Warning" />
+ <Rule Id="CA1802" Action="Warning" />
+ <Rule Id="CA1804" Action="Warning" />
+ <Rule Id="CA1806" Action="Warning" />
+ <Rule Id="CA1809" Action="Warning" />
+ <Rule Id="CA1810" Action="Warning" />
+ <Rule Id="CA1811" Action="Warning" />
+ <Rule Id="CA1812" Action="Warning" />
+ <Rule Id="CA1813" Action="Warning" />
+ <Rule Id="CA1814" Action="Warning" />
+ <Rule Id="CA1815" Action="Warning" />
+ <Rule Id="CA1816" Action="Warning" />
+ <Rule Id="CA1819" Action="Warning" />
+ <Rule Id="CA1820" Action="Warning" />
+ <Rule Id="CA1821" Action="Warning" />
+ <Rule Id="CA1822" Action="Warning" />
+ <Rule Id="CA1823" Action="Warning" />
+ <Rule Id="CA1824" Action="Warning" />
+ <Rule Id="CA1900" Action="Warning" />
+ <Rule Id="CA1901" Action="Warning" />
+ <Rule Id="CA1903" Action="Warning" />
+ <Rule Id="CA2000" Action="Warning" />
+ <Rule Id="CA2001" Action="Warning" />
+ <Rule Id="CA2002" Action="Warning" />
+ <Rule Id="CA2003" Action="Warning" />
+ <Rule Id="CA2004" Action="Warning" />
+ <Rule Id="CA2006" Action="Warning" />
+ <Rule Id="CA2100" Action="Warning" />
+ <Rule Id="CA2101" Action="Warning" />
+ <Rule Id="CA2102" Action="Warning" />
+ <Rule Id="CA2103" Action="Warning" />
+ <Rule Id="CA2104" Action="Warning" />
+ <Rule Id="CA2105" Action="Warning" />
+ <Rule Id="CA2106" Action="Warning" />
+ <Rule Id="CA2107" Action="Warning" />
+ <Rule Id="CA2108" Action="Warning" />
+ <Rule Id="CA2109" Action="Warning" />
+ <Rule Id="CA2111" Action="Warning" />
+ <Rule Id="CA2112" Action="Warning" />
+ <Rule Id="CA2114" Action="Warning" />
+ <Rule Id="CA2115" Action="Warning" />
+ <Rule Id="CA2116" Action="Warning" />
+ <Rule Id="CA2117" Action="Warning" />
+ <Rule Id="CA2118" Action="Warning" />
+ <Rule Id="CA2119" Action="Warning" />
+ <Rule Id="CA2120" Action="Warning" />
+ <Rule Id="CA2121" Action="Warning" />
+ <Rule Id="CA2122" Action="Warning" />
+ <Rule Id="CA2123" Action="Warning" />
+ <Rule Id="CA2124" Action="Warning" />
+ <Rule Id="CA2126" Action="Warning" />
+ <Rule Id="CA2130" Action="Warning" />
+ <Rule Id="CA2131" Action="Warning" />
+ <Rule Id="CA2132" Action="Warning" />
+ <Rule Id="CA2133" Action="Warning" />
+ <Rule Id="CA2134" Action="Warning" />
+ <Rule Id="CA2135" Action="Warning" />
+ <Rule Id="CA2136" Action="Warning" />
+ <Rule Id="CA2137" Action="Warning" />
+ <Rule Id="CA2138" Action="Warning" />
+ <Rule Id="CA2139" Action="Warning" />
+ <Rule Id="CA2140" Action="Warning" />
+ <Rule Id="CA2141" Action="Warning" />
+ <Rule Id="CA2142" Action="Warning" />
+ <Rule Id="CA2143" Action="Warning" />
+ <Rule Id="CA2144" Action="Warning" />
+ <Rule Id="CA2145" Action="Warning" />
+ <Rule Id="CA2146" Action="Warning" />
+ <Rule Id="CA2147" Action="Warning" />
+ <Rule Id="CA2149" Action="Warning" />
+ <Rule Id="CA2200" Action="Warning" />
+ <Rule Id="CA2201" Action="Warning" />
+ <Rule Id="CA2202" Action="Warning" />
+ <Rule Id="CA2205" Action="Warning" />
+ <Rule Id="CA2207" Action="Warning" />
+ <Rule Id="CA2208" Action="Warning" />
+ <Rule Id="CA2210" Action="Warning" />
+ <Rule Id="CA2211" Action="Warning" />
+ <Rule Id="CA2212" Action="Warning" />
+ <Rule Id="CA2213" Action="Warning" />
+ <Rule Id="CA2214" Action="Warning" />
+ <Rule Id="CA2215" Action="Warning" />
+ <Rule Id="CA2216" Action="Warning" />
+ <Rule Id="CA2217" Action="Warning" />
+ <Rule Id="CA2218" Action="Warning" />
+ <Rule Id="CA2219" Action="Warning" />
+ <Rule Id="CA2220" Action="Warning" />
+ <Rule Id="CA2221" Action="Warning" />
+ <Rule Id="CA2222" Action="Warning" />
+ <Rule Id="CA2223" Action="Warning" />
+ <Rule Id="CA2224" Action="Warning" />
+ <Rule Id="CA2225" Action="Warning" />
+ <Rule Id="CA2226" Action="Warning" />
+ <Rule Id="CA2227" Action="Warning" />
+ <Rule Id="CA2228" Action="Warning" />
+ <Rule Id="CA2229" Action="Warning" />
+ <Rule Id="CA2230" Action="Warning" />
+ <Rule Id="CA2231" Action="Warning" />
+ <Rule Id="CA2232" Action="Warning" />
+ <Rule Id="CA2233" Action="Warning" />
+ <Rule Id="CA2234" Action="Warning" />
+ <Rule Id="CA2235" Action="Warning" />
+ <Rule Id="CA2236" Action="Warning" />
+ <Rule Id="CA2237" Action="Warning" />
+ <Rule Id="CA2238" Action="Warning" />
+ <Rule Id="CA2239" Action="Warning" />
+ <Rule Id="CA2240" Action="Warning" />
+ <Rule Id="CA2241" Action="Warning" />
+ <Rule Id="CA2242" Action="Warning" />
+ <Rule Id="CA2243" Action="Warning" />
+ </Rules>
+</RuleSet>
View
11 CustomDictionary.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Dictionary>
+ <Words>
+ <Recognized>
+ <Word>Bson</Word>
+ </Recognized>
+ <DiscreteExceptions>
+ <Term>BsonType</Term>
+ </DiscreteExceptions>
+ </Words>
+</Dictionary>

0 comments on commit bed49e7

Please sign in to comment.
Something went wrong with that request. Please try again.