瀏覽代碼

more code analysis

Vicente Penades 6 年之前
父節點
當前提交
85a167bbdb

+ 13 - 1
SharpGLTF.ruleset

@@ -29,7 +29,7 @@
     <Rule Id="SA1502" Action="None" />
     <Rule Id="SA1503" Action="None" />
     <Rule Id="SA1512" Action="None" />
-    <Rule Id="SA1516" Action="None" />	
+    <Rule Id="SA1516" Action="None" />
     <Rule Id="SA1515" Action="None" />
     <Rule Id="SA1600" Action="None" />
     <Rule Id="SA1601" Action="None" />
@@ -40,4 +40,16 @@
     <Rule Id="SA1649" Action="None" />
     <Rule Id="SA1652" Action="None" />
   </Rules>
+  <Rules AnalyzerId="Microsoft.CodeQuality.CSharp.Analyzers" RuleNamespace="Microsoft.CodeQuality.CSharp.Analyzers">
+    <Rule Id="CA1001" Action="Error" />
+    <Rule Id="CA1032" Action="Info" />
+  </Rules>
+  <Rules AnalyzerId="Microsoft.CodeQuality.Analyzers" RuleNamespace="Microsoft.CodeQuality.Analyzers">
+    <Rule Id="CA1051" Action="None" />
+    <Rule Id="CA1715" Action="None" />
+    <Rule Id="CA1063" Action="Error" />
+    <Rule Id="CA1815" Action="Info" />
+    <Rule Id="CA1710" Action="Info" />
+    <Rule Id="CA2225" Action="Info" />
+  </Rules>
 </RuleSet>

+ 1 - 1
src/Shared/_Extensions.cs

@@ -159,7 +159,7 @@ namespace SharpGLTF
 
             return dst;
         }
-        
+
         #endregion
 
         #region linq

+ 4 - 1
src/SharpGLTF.Core/SharpGLTF.Core.csproj

@@ -40,13 +40,16 @@
   </PropertyGroup>
   
   <ItemGroup>    
-    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.2" />    
     <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
     <PackageReference Include="System.Memory" Version="4.5.3" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
     </PackageReference>
+    <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.2" >
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
+    </PackageReference>
   </ItemGroup>
 
   <ItemGroup>

+ 2 - 0
src/SharpGLTF.Toolkit/Geometry/MeshBuilder.cs

@@ -68,7 +68,9 @@ namespace SharpGLTF.Geometry
 
         private readonly Dictionary<(TMaterial, int), PrimitiveBuilder<TMaterial, TvG, TvM, TvS>> _Primitives = new Dictionary<(TMaterial, int), PrimitiveBuilder<TMaterial, TvG, TvM, TvS>>();
 
+        #pragma warning disable SA1401 // Fields should be private
         internal IPolygonTriangulator _Triangulator = NaivePolygonTriangulation.Default;
+        #pragma warning restore SA1401 // Fields should be private
 
         #endregion
 

+ 4 - 0
src/SharpGLTF.Toolkit/Geometry/VertexColumns.cs

@@ -21,6 +21,8 @@ namespace SharpGLTF.Geometry
     {
         #region Data Columns
 
+#pragma warning disable CA2227 // Collection properties should be read only
+
         public IList<Vector3> Positions { get; set; }
         public IList<Vector3> Normals { get; set; }
         public IList<Vector4> Tangents { get; set; }
@@ -44,6 +46,8 @@ namespace SharpGLTF.Geometry
             public IList<Vector3> Tangents { get; set; }
         }
 
+#pragma warning restore CA2227 // Collection properties should be read only
+
         private List<MorphTarget> _MorphTargets;
 
         private static readonly IReadOnlyList<MorphTarget> _EmptyMorphTargets = new MorphTarget[0];

+ 5 - 5
src/SharpGLTF.Toolkit/Geometry/VertexTypes/VertexSkinning.cs

@@ -9,7 +9,7 @@ namespace SharpGLTF.Geometry.VertexTypes
     /// Represents a a Node Joint index and its weight in a skinning system.
     /// </summary>
     [System.Diagnostics.DebuggerDisplay("{Joint} = {Weight}")]
-    public struct JointBinding : IComparable<JointBinding>
+    public struct JointBinding
     {
         #region constructors
 
@@ -36,12 +36,12 @@ namespace SharpGLTF.Geometry.VertexTypes
 
         #region API
 
-        public int CompareTo(JointBinding other)
+        private static int CompareWeightTo(JointBinding left, JointBinding right)
         {
-            var a = this.Weight.CompareTo(other.Weight);
+            var a = left.Weight.CompareTo(right.Weight);
             if (a != 0) return a;
 
-            return this.Joint.CompareTo(other.Joint);
+            return left.Joint.CompareTo(right.Joint);
         }
 
         internal static void InPlaceReverseBubbleSort(Span<JointBinding> span)
@@ -52,7 +52,7 @@ namespace SharpGLTF.Geometry.VertexTypes
 
                 for (int j = 0; j < span.Length - 1; ++j)
                 {
-                    if (span[j].CompareTo(span[j + 1]) < 0)
+                    if (CompareWeightTo(span[j], span[j + 1]) < 0)
                     {
                         var tmp = span[j];
                         span[j] = span[j + 1];

+ 2 - 1
src/SharpGLTF.Toolkit/IO/WavefrontWriter.cs

@@ -12,10 +12,11 @@ using static System.FormattableString;
 namespace SharpGLTF.IO
 {
     using BYTES = ArraySegment<Byte>;
+    using VEMPTY = Geometry.VertexTypes.VertexEmpty;
     using VERTEX = Geometry.VertexBuilder<Geometry.VertexTypes.VertexPositionNormal, Geometry.VertexTypes.VertexTexture1, Geometry.VertexTypes.VertexEmpty>;
     using VGEOMETRY = Geometry.VertexTypes.VertexPositionNormal;
     using VMATERIAL = Geometry.VertexTypes.VertexTexture1;
-    using VEMPTY = Geometry.VertexTypes.VertexEmpty;
+    
 
     /// <summary>
     /// Tiny wavefront object writer

+ 4 - 7
src/SharpGLTF.Toolkit/Schema2/MeshExtensions.cs

@@ -5,14 +5,11 @@ using System.Text;
 using System.Linq;
 
 using SharpGLTF.Memory;
+using SharpGLTF.Geometry;
+using SharpGLTF.Geometry.VertexTypes;
 
 namespace SharpGLTF.Schema2
 {
-    using Geometry;
-    using Geometry.VertexTypes;
-
-    using VEMPTY = Geometry.VertexTypes.VertexEmpty;
-
     public static partial class Schema2Toolkit
     {
         #region meshes
@@ -307,14 +304,14 @@ namespace SharpGLTF.Schema2
             }
         }
 
-        public static IEnumerable<(VertexBuilder<TvG, TvM, VEMPTY>, VertexBuilder<TvG, TvM, VEMPTY>, VertexBuilder<TvG, TvM, VEMPTY>, Material)> Triangulate<TvG, TvM>(this Mesh mesh, Transforms.ITransform xform)
+        public static IEnumerable<(VertexBuilder<TvG, TvM, VertexEmpty>, VertexBuilder<TvG, TvM, VertexEmpty>, VertexBuilder<TvG, TvM, VertexEmpty>, Material)> Triangulate<TvG, TvM>(this Mesh mesh, Transforms.ITransform xform)
             where TvG : struct, IVertexGeometry
             where TvM : struct, IVertexMaterial
         {
             return mesh.Primitives.SelectMany(item => item.Triangulate<TvG, TvM>(xform));
         }
 
-        public static IEnumerable<(VertexBuilder<TvG, TvM, VEMPTY>, VertexBuilder<TvG, TvM, VEMPTY>, VertexBuilder<TvG, TvM, VEMPTY>, Material)> Triangulate<TvG, TvM>(this MeshPrimitive prim, Transforms.ITransform xform)
+        public static IEnumerable<(VertexBuilder<TvG, TvM, VertexEmpty>, VertexBuilder<TvG, TvM, VertexEmpty>, VertexBuilder<TvG, TvM, VertexEmpty>, Material)> Triangulate<TvG, TvM>(this MeshPrimitive prim, Transforms.ITransform xform)
             where TvG : struct, IVertexGeometry
             where TvM : struct, IVertexMaterial
         {

+ 6 - 3
src/SharpGLTF.Toolkit/SharpGLTF.Toolkit.csproj

@@ -17,6 +17,7 @@
     <DebugSymbols>true</DebugSymbols>
     <PackageLicenseFile>LICENSE</PackageLicenseFile>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <CodeAnalysisRuleSet>..\..\SharpGLTF.ruleset</CodeAnalysisRuleSet>
   </PropertyGroup>
 
   <ItemGroup>
@@ -34,15 +35,17 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.2" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
     </PackageReference>
+    <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="2.9.2" >
+      <PrivateAssets>all</PrivateAssets>
+      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
+    </PackageReference>
   </ItemGroup>
 
-  <PropertyGroup>
-    <CodeAnalysisRuleSet>..\..\SharpGLTF.ruleset</CodeAnalysisRuleSet>    
+  <PropertyGroup>    
     <PackageIconUrl>https://raw.githubusercontent.com/vpenades/SharpGLTF/master/build/Icons/glTF2Sharp.png</PackageIconUrl>
   </PropertyGroup>
   

+ 0 - 1
tests/SharpGLTF.Tests/SharpGLTF.Tests.csproj

@@ -10,7 +10,6 @@
 
   <ItemGroup>
     <PackageReference Include="LibGit2Sharp" Version="0.26.0" />
-    <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.1.0" />
     <PackageReference Include="nunit" Version="3.12.0" />
     <PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />