Commits

Jon Hanna  committed d398da3

Use StyleCopPlus Settings.

  • Participants
  • Parent commits 01df77a

Comments (0)

Files changed (11)

 obj/*
 *.userprefs
 *.*~
-OpenCover
-*.nupkg
-/packages/**/*
-!/packages/repositories.config
+OpenCover
+*.nupkg
+/packages/**/*
+!/packages/repositories.config
 TestNuGet/packages/**/*
 !TestNuGet/packages/repositories.config
-*.sdps
-StyleCop.Cache
-StyleCopViolations.xml
-/Documentation/*.shfbproj_*
-Help
+*.sdps
+StyleCop.Cache
+StyleCopViolations.xml
+/Documentation/*.shfbproj_*
+Help
+deleteme.*

File SpookilySharp/ExceptionHelper.cs

                 throw new ArgumentNullException(name);
         }
 
-        public static void CheckNotNullS(string arg)
+        public static void CheckNotNullString(string arg)
         {
             CheckNotNull(arg, "s");
         }
             // Analysis disable once NotResolvedInText
             throw new ArgumentOutOfRangeException("startIndex");
         }
-        
+
         private static void PastArrayBounds()
         {
             throw new ArgumentException("Attempt to read beyond the end of the array.");
         }
-        
+
         private static void PastStringBounds()
         {
             throw new ArgumentException("Attempt to read beyond the end of the string.");
         }
-        
+
         public static void CheckArray<T>(T[] message, int startIndex, int length)
         {
             if(startIndex < 0 || startIndex > message.Length)
             if(startIndex + length > message.Length)
                 PastArrayBounds();
         }
-        
+
         public static void CheckArrayIncNull<T>(T[] message, int startIndex, int length)
         {
             CheckMessageNotNull(message);

File SpookilySharp/HashCode128.cs

         }
 
         /// <summary>Tries to parse a <see cref="HashCode128"/> from a string.</summary>
-        /// <returns><see langword="true"/>, if <paramref name="s"/> was converted successfully; otherwise <see langword="false"/>.</returns>
+        /// <returns><see langword="true"/>, if <paramref name="s"/> was converted successfully; otherwise
+        /// <see langword="false"/>.</returns>
         /// <param name="s">A <see cref="string"/> containing the hash code to convert.</param>
         /// <param name="result">The 128-bit has code parsed from the string, or <see cref="HashCode128.Zero"/> if
         /// the parsing was unsuccessful.</param>
         /// <returns>The <see cref="HashCode128"/> represented by <paramref name="s"/>.</returns>
         /// <exception cref="ArgumentNullException"><paramref name="s"/> was null.</exception>
         /// <exception cref="FormatException"><paramref name="s"/> did not contain a 32-digit hexadecimal
-        /// number.</exception> 
+        /// number.</exception>
         /// <remarks>The value passed to <paramref name="s"/> must be a 32-digit hexadecimal number for this to succeed.
         /// Leading, trailing and contained whitespace is allowed. A leading <c>0x</c> is permitted, but not required.
         /// Leading zeros must not be omitted.</remarks>
         public static HashCode128 Parse(string s)
         {
-            ExceptionHelper.CheckNotNullS(s);
+            ExceptionHelper.CheckNotNullString(s);
             HashCode128 ret;
             if(!TryParse(s, out ret))
                 ExceptionHelper.BadHashCode128Format();
         }
 
         /// <inheritdoc/>
-        [WellDistributedHash] // ironically not really true if you create this struct any way other than as the result of a good hash operation in the first place.
+        [WellDistributedHash] // ironically not really true if you create this struct any way other than as the result
+                              // of a good hash operation in the first place.
         public override int GetHashCode()
         {
             return unchecked((int)_hash1);
         /// <summary>Determines whether the specified <see cref="object"/> is equal to the current
         /// <see cref="HashCode128"/>.</summary>
         /// <param name="obj">The <see cref="object"/> to compare with the current <see cref="HashCode128"/>.</param>
-        /// <returns><see langword="true"/> if the specified <see cref="object"/> is a boxed <see cref="HashCode128"/> with the
-        /// same value as the current; otherwise, <see langword="false"/>.</returns>
+        /// <returns><see langword="true"/> if the specified <see cref="object"/> is a boxed <see cref="HashCode128"/>
+        /// with the same value as the current; otherwise, <see langword="false"/>.</returns>
         public override bool Equals(object obj)
         {
             if(obj is HashCode128)
         {
             return _hash1.ToString("X16") + _hash2.ToString("X16");
         }
-    }    
+    }
 }

File SpookilySharp/HashedStream.cs

 
         /// <summary>Initialises a new instance of the <see cref="SpookilySharp.HashedStream"/> class.</summary>
         /// <param name="stream">The stream to read.</param>
-        /// <param name="seed0">The first 64 bits of the seed for both the hash of contents read and the hash of the contents written.</param>
-        /// <param name="seed1">The second 64 bits of the seed for both the hash of contents read and the hash of the contents written.</param>
+        /// <param name="seed0">The first 64 bits of the seed for both the hash of contents read and the hash of the
+        /// contents written.</param>
+        /// <param name="seed1">The second 64 bits of the seed for both the hash of contents read and the hash of the
+        /// contents written.</param>
         [CLSCompliant(false)]
         public HashedStream(Stream stream, ulong seed0, ulong seed1)
             : this(stream, seed0, seed1, seed0, seed1)
 
         /// <summary>Initialises a new instance of the <see cref="SpookilySharp.HashedStream"/> class.</summary>
         /// <param name="stream">The stream to read.</param>
-        /// <param name="seed0">The first 64 bits of the seed for both the hash of contents read and the hash of the contents written.</param>
-        /// <param name="seed1">The second 64 bits of the seed for both the hash of contents read and the hash of the contents written.</param>
+        /// <param name="seed0">The first 64 bits of the seed for both the hash of contents read and the hash of the
+        /// contents written.</param>
+        /// <param name="seed1">The second 64 bits of the seed for both the hash of contents read and the hash of the
+        /// contents written.</param>
         public HashedStream(Stream stream, long seed0, long seed1)
             : this(stream, (ulong)seed0, (ulong)seed1)
         {
         }
 
-        /// <summary>Initialises a new instance of the <see cref="SpookilySharp.HashedStream"/> class with a default seed.</summary>
+        /// <summary>Initialises a new instance of the <see cref="SpookilySharp.HashedStream"/> class with a default
+        /// seed.</summary>
         /// <param name="stream">The stream to read.</param>
         public HashedStream(Stream stream)
         {
             get { return (int)ReadHash128.Hash1; }
         }
 
-        /// <summary>Gets a value indicating whether there had been an operation that moved the point being read from or written to.</summary>
+        /// <summary>Gets a value indicating whether there had been an operation that moved the point being read from or
+        /// written to.</summary>
         /// <value><see langword="true"/> if was moved; otherwise, <see langword="false"/>.</value>
-        /// <remarks>Operations such as <see cref="SetLength"/> or setting properties such as <see cref="Position"/> will mean that while the hashes will remain correct hashes of the values written and read, they may not correspond with e.g. the hash obtained by hashing the contents of a file the stream is backed by, etc.</remarks>
+        /// <remarks>Operations such as <see cref="SetLength"/> or setting properties such as <see cref="Position"/>
+        /// will mean that while the hashes will remain correct hashes of the values written and read, they may not
+        /// correspond with e.g. the hash obtained by hashing the contents of a file the stream is backed by,
+        /// etc.</remarks>
         public bool WasMoved
         {
             get { return _moved; }

File SpookilySharp/Settings.SourceAnalysis

             <BooleanProperty Name="Enabled">False</BooleanProperty>
           </RuleSettings>
         </Rule>
+        <Rule Name="ElementMustNotBeOnSingleLine">
+          <RuleSettings>
+            <BooleanProperty Name="Enabled">False</BooleanProperty>
+          </RuleSettings>
+        </Rule>
       </Rules>
       <AnalyzerSettings />
     </Analyzer>
       </Rules>
       <AnalyzerSettings />
     </Analyzer>
+    <Analyzer AnalyzerId="StyleCopPlus.StyleCopPlusRules">
+      <Rules>
+        <Rule Name="ElementMustNotBeOnSingleLine">
+          <RuleSettings>
+            <BooleanProperty Name="Enabled">True</BooleanProperty>
+          </RuleSettings>
+        </Rule>
+      </Rules>
+      <AnalyzerSettings>
+        <StringProperty Name="AdvancedNaming_Words">U X Y</StringProperty>
+        <StringProperty Name="AdvancedNaming_EnglishOnly">None</StringProperty>
+        <StringProperty Name="AdvancedNaming_CheckLength">6</StringProperty>
+        <StringProperty Name="AdvancedNaming_ProtectedInstanceField">_$(aaBb)</StringProperty>
+        <StringProperty Name="SP2001_Mode">Spaces:False</StringProperty>
+        <StringProperty Name="AdvancedNaming_PrivateInstanceField">_$(aaBb)</StringProperty>
+        <StringProperty Name="SP2002_Mode">NotEmpty</StringProperty>
+        <StringProperty Name="SP2100_Limit">120:4</StringProperty>
+        <StringProperty Name="AdvancedNaming_PrivateStaticField">_$(aaBb):$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_PublicInstanceField">_$(aaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_InternalInstanceField">_$(aaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_ProtectedStaticField">$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_InternalStaticField">_$(aaBb):$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_ProtectedConst">$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_PrivateConst">$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_InternalConst">$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_BlockAt">All</StringProperty>
+        <StringProperty Name="AdvancedNaming_ClassInternal">$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_StructInternal">$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_MethodPrivateEventHandler">$(AaBb):$(AaBb)_$(AaBb)</StringProperty>
+        <StringProperty Name="AdvancedNaming_MethodProtectedEventHandler">$(AaBb):$(AaBb)_$(AaBb)</StringProperty>
+      </AnalyzerSettings>
+    </Analyzer>
   </Analyzers>
 </StyleCopSettings>

File SpookilySharp/SpookierEqualityComparer.cs

             // Note: Hashtable is documented as thread-safe for single-writer, multiple-reader.
             // Dictionary<TKey, TValue> as implemented in both .NET and Mono is safe for that when
             // both key and value types are capable of atomic read or write , but not documented as such,
-            // so we play it safe.            
+            // so we play it safe.
             // Analysis disable once StaticFieldInGenericType
             private static readonly Hashtable Store = new Hashtable();
             public static bool? KnownQuality(Type type)
         }
 
         /// <summary>
-        /// Returns a version of <paramref name="comparer"/> that provides strong distribution of bits in its hash codes.
+        /// Returns a version of <paramref name="comparer"/> that provides strong distribution of bits in its hash
+        /// codes.
         /// </summary>
         /// <returns>An <see cref="IEqualityComparer{T}"/> based on <paramref name="comparer"/>, or
-        /// <paramref name="comparer"/> if its implementation of <see cref="M:System.Collections.Generic.IEqualityComparer`1.GetHashCode(`0)"/> is
-        /// marked with <see cref="WellDistributedHashAttribute"/>, indicating it already provides a strong distribution.</returns>
+        /// <paramref name="comparer"/> if its implementation of
+        /// <see cref="M:System.Collections.Generic.IEqualityComparer`1.GetHashCode(`0)"/> is marked with
+        /// <see cref="WellDistributedHashAttribute"/>, indicating it already provides a strong distribution.</returns>
         /// <param name="comparer">The <see cref="IEqualityComparer{T}"/> to improve.</param>
         /// <typeparam name="T">The type of objects compared by <paramref name="comparer"/>.</typeparam>
-        /// <remarks>This cannot improve the overall risk of collision (indeed, will
-        /// make it slightly worse), it can help when uses of hash codes are particularly sensitive to collisions in the one
-        /// section of bits, e.g. with power-of-two hash tables.</remarks>
+        /// <remarks>This cannot improve the overall risk of collision (indeed, will make it slightly worse), it can
+        /// help when uses of hash codes are particularly sensitive to collisions in the one section of bits, e.g. with
+        /// power-of-two hash tables.</remarks>
         public static IEqualityComparer<T> WellDistributed<T>(
 #if !NET_20 && !NET_30
             this
             return imap.TargetMethods[idx].GetCustomAttributes(typeof(WellDistributedHashAttribute), false).Length != 0;
         }
     }
-}
+}

File SpookilySharp/SpookyHash.cs

             if(AllowUnalignedRead || (((long)message) & 7) == 0)
             {
                 while (p64 < end)
-                { 
+                {
                     h0 += p64[0];    h2 ^= h10;   h11 ^= h0;   h0 =   h0 << 11 | h0 >> -11;   h11 += h1;
                     h1 += p64[1];    h3 ^= h11;   h0 ^= h1;    h1 =   h1 << 32 | h1 >> 32;    h0 += h2;
                     h2 += p64[2];    h4 ^= h0;    h1 ^= h2;    h2 =   h2 << 43 | h2 >> -43;   h1 += h3;
                 while (p64 < end)
                 {
                     Memory.Copy(buf, p64, BlockSize);
-                    
+
                     h0 += buf[0];    h2 ^= h10;   h11 ^= h0;   h0 =   h0 << 11 | h0 >> -11;   h11 += h1;
                     h1 += buf[1];    h3 ^= h11;   h0 ^= h1;    h1 =   h1 << 32 | h1 >> 32;    h0 += h2;
                     h2 += buf[2];    h4 ^= h0;    h1 ^= h2;    h2 =   h2 << 43 | h2 >> -43;   h1 += h3;
         [SuppressMessage("Microsoft.StyleCop.CSharp.ReadabilityRules",
             "SA1107:CodeMustNotContainMultipleStatementsOnOneLine",
             Justification = "More readable with the repeated blocks of the mixing.")]
+        [SuppressMessage("StyleCopPlus.StyleCopPlusRules",
+            "SP2101:MethodMustNotContainMoreLinesThan",
+            Justification = "One of the two main methods of the algorithm (this is a fastpath version); "
+            + "inherenly large, and won't break into calls into other methods as this would gain little, "
+            + "and cause a mild performance hit.")]
         private static unsafe void Short(void* message, int length, ref ulong hash1, ref ulong hash2, bool skipTest)
         {
             ulong* p64;
             : this(SpookyConst, SpookyConst)
         {
         }
-        
+
         private SpookyHash(SerializationInfo info, StreamingContext context)
         {
             _data = (ulong[])info.GetValue("d", typeof(ulong[]));
             ExceptionHelper.CheckMessageNotNull(message);
             Update(message, 0, message.Length);
         }
-        
+
         /// <summary>Updates the in-progress hash generation with each <see cref="string"/> in an sequence of strings.
         /// </summary>
         /// <param name="message">The sequence of <see cref="string"/>s to hash.</param>
             Justification = "More readable with the repeated blocks of the mixing.")]
         [SuppressMessage("Microsoft.StyleCop.CSharp.SpacingRules", "SA1025:CodeMustNotContainMultipleWhitespaceInARow",
             Justification = "More readable with the repeated blocks of the mixing.")]
+        [SuppressMessage("StyleCopPlus.StyleCopPlusRules",
+            "SP2101:MethodMustNotContainMoreLinesThan",
+            Justification = "One of the two main methods of the algorithm; inherenly large, and won't break into calls"
+            + "into other methods as this would gain little, and cause a mild performance hit.")]
         public unsafe void Update(void* message, int length)
         {
             if((int)message == 0)
                 byte remainder = (byte)(length - ((byte*)end - ((byte*)p64)));
                 if(AllowUnalignedRead || (((long)message) & 7) == 0)
                     while (p64 < end)
-                    { 
+                    {
                         h0  += p64[0];  h2  ^= h10; h11 ^= h0;  h0 =  h0 << 11  | h0 >>  -11; h11 += h1;
                         h1  += p64[1];  h3  ^= h11; h0  ^= h1;  h1 =  h1 << 32  | h1 >>  -32; h0  += h2;
                         h2  += p64[2];  h4  ^= h0;  h1  ^= h2;  h2 =  h2 << 43  | h2 >>  -43; h1  += h3;
             info.AddValue("r", _remainder);
         }
     }
-}
+}

File SpookilySharp/SpookyHasher.cs

         {
             return unchecked(SpookyHash128(message, (long)SpookyHash.SpookyConst, (long)SpookyHash.SpookyConst));
         }
-        
+
         [SecurityCritical]
         private static unsafe long SpookyHash64Unchecked(string message, int startIndex, int length, long seed)
         {
             ExceptionHelper.CheckBounds(message, startIndex, length);
             return SpookyHash64Unchecked(message, 0, message.Length, unchecked((long)SpookyHash.SpookyConst));
         }
-        
+
         /// <summary>Produces a 64-bit SpookyHash of a <see cref="string"/>.</summary>
         /// <returns>A <see cref="long"/> containing the 64-bit hash.</returns>
         /// <param name="message">The <see cref="string"/> to hash.</param>
 #endif
             string message)
         {
-            return message == null ? 0 : unchecked(SpookyHash32Unchecked(message, 0, message.Length, (uint)SpookyHash.SpookyConst));
+            return message == null ? 0 : unchecked(SpookyHash32Unchecked(
+                message,
+                0,
+                message.Length,
+                (uint)SpookyHash.SpookyConst));
         }
 
         /// <summary>Produces an 128-bit SpookyHash of a stream.</summary>

File SpookilySharp/SpookyStringEqualityComparer.cs

 
         /// <summary>Initialises a new instance of the <see cref="SpookyStringEqualityComparer"/> class with a default
         /// or randomised seed.</summary>
-        /// <param name="randomizeSeed">If set to <see langword="true"/> the seed is taken from the number of milliseconds the
-        /// system has been up, otherwise the default seed is used.</param>
+        /// <param name="randomizeSeed">If set to <see langword="true"/> the seed is taken from the number of
+        /// milliseconds the system has been up, otherwise the default seed is used.</param>
         /// <remarks>This is useful in reducing Hash DoS attacks, though different instances of the comparer will not
         /// operate together, as each will produce a different hash code.</remarks>
         public SpookyStringEqualityComparer(bool randomizeSeed)
         /// <see cref="SpookyStringEqualityComparer"/>.</summary>
         /// <param name="other">The <see cref="SpookyStringEqualityComparer"/> to compare with the current
         /// <see cref="SpookilySharp.SpookyStringEqualityComparer"/>.</param>
-        /// <returns><see langword="true"/> if the specified <see cref="SpookyStringEqualityComparer"/> is equal to the current
-        /// <see cref="SpookyStringEqualityComparer"/>; otherwise, <see langword="false"/>.</returns>
+        /// <returns><see langword="true"/> if the specified <see cref="SpookyStringEqualityComparer"/> is equal to the
+        /// current <see cref="SpookyStringEqualityComparer"/>; otherwise, <see langword="false"/>.</returns>
         /// <remarks>Two instances of <see cref="SpookyStringEqualityComparer"/> are considered equal if they have the
         /// same seed, and as such can be depended upon to produce the same hash codes for the same input.</remarks>
         public bool Equals(SpookyStringEqualityComparer other)

File SpookilySharp/WellDistributedHashAttribute.cs

 
 namespace SpookilySharp
 {
-    /// <summary>Marks an implementation of <see cref="M:System.Collections.Generic.IEqualityComparer`1.GetHashCode(`0)"/> or an override of
+    /// <summary>Marks an implementation of
+    /// <see cref="M:System.Collections.Generic.IEqualityComparer`1.GetHashCode(`0)"/> or an override of
     /// <see cref="object.GetHashCode()"/> as being known to distribute bits well in its implementation of hash
     /// codes.</summary>
     /// <remarks>When such a method is used by an <see cref="IEqualityComparer{T}"/>, whether as the implementation of

File SpookilySharp/packages.config

 <packages>
   <package id="Mnemosyne" version="1.0.0.1" targetFramework="net451" />
   <package id="StyleCop.MSBuild" version="4.7.49.0" targetFramework="net451" />
+  <package id="StyleCopPlus.MSBuild" version="4.7.49.0" targetFramework="net40" />
 </packages>