From 46604d68b3326547c81660a25a2961634365badd Mon Sep 17 00:00:00 2001 From: Louis DeJardin Date: Tue, 1 Sep 2015 22:25:51 -0700 Subject: [PATCH] Initial commit for style cleanup #184 * adding private keyword to fields * one type per file --- KestrelHttpServer.sln | 7 + global.json | 3 +- .../Http/Connection.cs | 2 +- .../Http/Frame.cs | 12 +- .../Http/FrameDuplexStream.cs | 4 +- .../Http/FrameHeaders.Generated.cs | 146 +++++++++--------- .../Http/FrameHeaders.cs | 101 +----------- .../Http/FrameRequestHeaders.cs | 57 +++++++ .../Http/FrameRequestStream.cs | 2 +- .../Http/FrameResponseHeaders.cs | 57 +++++++ .../Http/ListenerPrimary.cs | 6 +- .../Http/MemoryPool.cs | 12 +- .../Http/MessageBodyExchanger.cs | 8 +- .../Infrastructure/KestrelThread.cs | 20 +-- .../Networking/Libuv.cs | 8 +- .../Networking/UvConnectRequest.cs | 4 +- .../Networking/UvHandle.cs | 4 +- .../Networking/UvRequest.cs | 2 +- .../Networking/UvShutdownReq.cs | 4 +- .../Networking/UvWriteReq.cs | 10 +- .../ServerRequest.cs | 6 +- .../project.json | 6 +- .../KnownHeaders.cs | 4 +- .../Program.cs | 3 - .../Microsoft.StandardsPolice.xproj | 20 +++ tools/Microsoft.StandardsPolice/Program.cs | 49 ++++++ .../StandardsPoliceCompileModule.cs | 109 +++++++++++++ tools/Microsoft.StandardsPolice/project.json | 28 ++++ 28 files changed, 465 insertions(+), 229 deletions(-) create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs create mode 100644 src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs create mode 100644 tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj create mode 100644 tools/Microsoft.StandardsPolice/Program.cs create mode 100644 tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs create mode 100644 tools/Microsoft.StandardsPolice/project.json diff --git a/KestrelHttpServer.sln b/KestrelHttpServer.sln index 980a5d2537..02d3731464 100644 --- a/KestrelHttpServer.sln +++ b/KestrelHttpServer.sln @@ -29,6 +29,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Server.Kes EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{327F7880-D9AF-46BD-B45C-3B7E34A01DFD}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.StandardsPolice", "tools\Microsoft.StandardsPolice\Microsoft.StandardsPolice.xproj", "{82295647-7C1C-4671-BAB6-0FEF58F949EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -55,6 +57,10 @@ Global {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Debug|Any CPU.Build.0 = Debug|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.ActiveCfg = Release|Any CPU {BD2D4D29-1BD9-40D0-BB31-337D5416B63C}.Release|Any CPU.Build.0 = Release|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82295647-7C1C-4671-BAB6-0FEF58F949EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -65,5 +71,6 @@ Global {2C3CB3DC-EEBF-4F52-9E1C-4F2F972E76C3} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {B35D4D31-E74C-4646-8A11-7A7A40F0021E} = {8A3D00B8-1CCF-4BE6-A060-11104CE2D9CE} {BD2D4D29-1BD9-40D0-BB31-337D5416B63C} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} + {82295647-7C1C-4671-BAB6-0FEF58F949EC} = {327F7880-D9AF-46BD-B45C-3B7E34A01DFD} EndGlobalSection EndGlobal diff --git a/global.json b/global.json index 302a900d30..aa789b9c9c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,6 @@ { "projects": [ - "src" + "src", + "tools" ] } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs index 641d184f8c..81a3551b6d 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Connection.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private readonly UvStreamHandle _socket; private Frame _frame; - long _connectionId = 0; + private long _connectionId = 0; private readonly object _stateLock = new object(); private ConnectionState _connectionState; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs index ded01e3efa..18138ab5e1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/Frame.cs @@ -24,8 +24,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http Terminated, } - static Encoding _ascii = Encoding.ASCII; - Mode _mode; + private static Encoding _ascii = Encoding.ASCII; + private Mode _mode; private bool _responseStarted; private bool _keepAlive; private bool _autoChunk; @@ -38,10 +38,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Http CancellationTokenSource _cts = new CancellationTokenSource(); */ - List, object>> _onStarting; - List, object>> _onCompleted; - object _onStartingSync = new Object(); - object _onCompletedSync = new Object(); + private List, object>> _onStarting; + private List, object>> _onCompleted; + private object _onStartingSync = new Object(); + private object _onCompletedSync = new Object(); public Frame(ConnectionContext context) : base(context) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs index 58b2c88d0a..0086cdf0aa 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameDuplexStream.cs @@ -12,8 +12,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { class FrameDuplexStream : Stream { - readonly Stream _requestStream; - readonly Stream _responseStream; + private readonly Stream _requestStream; + private readonly Stream _responseStream; public FrameDuplexStream(Stream requestStream, Stream responseStream) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs index a79b61d4c4..f0975ff9b0 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.Generated.cs @@ -17,49 +17,49 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial class FrameRequestHeaders { - long _bits = 0; + private long _bits = 0; - StringValues _CacheControl; - StringValues _Connection; - StringValues _Date; - StringValues _KeepAlive; - StringValues _Pragma; - StringValues _Trailer; - StringValues _TransferEncoding; - StringValues _Upgrade; - StringValues _Via; - StringValues _Warning; - StringValues _Allow; - StringValues _ContentLength; - StringValues _ContentType; - StringValues _ContentEncoding; - StringValues _ContentLanguage; - StringValues _ContentLocation; - StringValues _ContentMD5; - StringValues _ContentRange; - StringValues _Expires; - StringValues _LastModified; - StringValues _Accept; - StringValues _AcceptCharset; - StringValues _AcceptEncoding; - StringValues _AcceptLanguage; - StringValues _Authorization; - StringValues _Cookie; - StringValues _Expect; - StringValues _From; - StringValues _Host; - StringValues _IfMatch; - StringValues _IfModifiedSince; - StringValues _IfNoneMatch; - StringValues _IfRange; - StringValues _IfUnmodifiedSince; - StringValues _MaxForwards; - StringValues _ProxyAuthorization; - StringValues _Referer; - StringValues _Range; - StringValues _TE; - StringValues _Translate; - StringValues _UserAgent; + private StringValues _CacheControl; + private StringValues _Connection; + private StringValues _Date; + private StringValues _KeepAlive; + private StringValues _Pragma; + private StringValues _Trailer; + private StringValues _TransferEncoding; + private StringValues _Upgrade; + private StringValues _Via; + private StringValues _Warning; + private StringValues _Allow; + private StringValues _ContentLength; + private StringValues _ContentType; + private StringValues _ContentEncoding; + private StringValues _ContentLanguage; + private StringValues _ContentLocation; + private StringValues _ContentMD5; + private StringValues _ContentRange; + private StringValues _Expires; + private StringValues _LastModified; + private StringValues _Accept; + private StringValues _AcceptCharset; + private StringValues _AcceptEncoding; + private StringValues _AcceptLanguage; + private StringValues _Authorization; + private StringValues _Cookie; + private StringValues _Expect; + private StringValues _From; + private StringValues _Host; + private StringValues _IfMatch; + private StringValues _IfModifiedSince; + private StringValues _IfNoneMatch; + private StringValues _IfRange; + private StringValues _IfUnmodifiedSince; + private StringValues _MaxForwards; + private StringValues _ProxyAuthorization; + private StringValues _Referer; + private StringValues _Range; + private StringValues _TE; + private StringValues _Translate; + private StringValues _UserAgent; protected override int GetCountFast() { @@ -4587,38 +4587,38 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public partial class FrameResponseHeaders { - long _bits = 0; + private long _bits = 0; - StringValues _CacheControl; - StringValues _Connection; - StringValues _Date; - StringValues _KeepAlive; - StringValues _Pragma; - StringValues _Trailer; - StringValues _TransferEncoding; - StringValues _Upgrade; - StringValues _Via; - StringValues _Warning; - StringValues _Allow; - StringValues _ContentLength; - StringValues _ContentType; - StringValues _ContentEncoding; - StringValues _ContentLanguage; - StringValues _ContentLocation; - StringValues _ContentMD5; - StringValues _ContentRange; - StringValues _Expires; - StringValues _LastModified; - StringValues _AcceptRanges; - StringValues _Age; - StringValues _ETag; - StringValues _Location; - StringValues _ProxyAutheticate; - StringValues _RetryAfter; - StringValues _Server; - StringValues _SetCookie; - StringValues _Vary; - StringValues _WWWAuthenticate; + private StringValues _CacheControl; + private StringValues _Connection; + private StringValues _Date; + private StringValues _KeepAlive; + private StringValues _Pragma; + private StringValues _Trailer; + private StringValues _TransferEncoding; + private StringValues _Upgrade; + private StringValues _Via; + private StringValues _Warning; + private StringValues _Allow; + private StringValues _ContentLength; + private StringValues _ContentType; + private StringValues _ContentEncoding; + private StringValues _ContentLanguage; + private StringValues _ContentLocation; + private StringValues _ContentMD5; + private StringValues _ContentRange; + private StringValues _Expires; + private StringValues _LastModified; + private StringValues _AcceptRanges; + private StringValues _Age; + private StringValues _ETag; + private StringValues _Location; + private StringValues _ProxyAutheticate; + private StringValues _RetryAfter; + private StringValues _Server; + private StringValues _SetCookie; + private StringValues _Vary; + private StringValues _WWWAuthenticate; protected override int GetCountFast() { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs index c8a6d7cd44..55191ec076 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameHeaders.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -129,100 +132,4 @@ namespace Microsoft.AspNet.Server.Kestrel.Http return TryGetValueFast(key, out value); } } - - public partial class FrameRequestHeaders : FrameHeaders - { - public Enumerator GetEnumerator() - { - return new Enumerator(this); - } - - protected override IEnumerator> GetEnumeratorFast() - { - return GetEnumerator(); - } - - public partial struct Enumerator : IEnumerator> - { - FrameRequestHeaders _collection; - long _bits; - int _state; - KeyValuePair _current; - bool _hasUnknown; - Dictionary.Enumerator _unknownEnumerator; - - internal Enumerator(FrameRequestHeaders collection) - { - _collection = collection; - _bits = collection._bits; - _state = 0; - _current = default(KeyValuePair); - _hasUnknown = collection.MaybeUnknown != null; - _unknownEnumerator = _hasUnknown - ? collection.MaybeUnknown.GetEnumerator() - : default(Dictionary.Enumerator); - } - - public KeyValuePair Current => _current; - - object IEnumerator.Current => _current; - - public void Dispose() - { - } - - public void Reset() - { - _state = 0; - } - } - } - - public partial class FrameResponseHeaders : FrameHeaders - { - public Enumerator GetEnumerator() - { - return new Enumerator(this); - } - - protected override IEnumerator> GetEnumeratorFast() - { - return GetEnumerator(); - } - - public partial struct Enumerator : IEnumerator> - { - FrameResponseHeaders _collection; - long _bits; - int _state; - KeyValuePair _current; - bool _hasUnknown; - Dictionary.Enumerator _unknownEnumerator; - - internal Enumerator(FrameResponseHeaders collection) - { - _collection = collection; - _bits = collection._bits; - _state = 0; - _current = default(KeyValuePair); - _hasUnknown = collection.MaybeUnknown != null; - _unknownEnumerator = _hasUnknown - ? collection.MaybeUnknown.GetEnumerator() - : default(Dictionary.Enumerator); - } - - public KeyValuePair Current => _current; - - object IEnumerator.Current => _current; - - public void Dispose() - { - } - - public void Reset() - { - _state = 0; - } - } - } } diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs new file mode 100644 index 0000000000..f6d1dc82e0 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestHeaders.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Framework.Primitives; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public partial class FrameRequestHeaders : FrameHeaders + { + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + protected override IEnumerator> GetEnumeratorFast() + { + return GetEnumerator(); + } + + public partial struct Enumerator : IEnumerator> + { + private FrameRequestHeaders _collection; + private long _bits; + private int _state; + private KeyValuePair _current; + private bool _hasUnknown; + private Dictionary.Enumerator _unknownEnumerator; + + internal Enumerator(FrameRequestHeaders collection) + { + _collection = collection; + _bits = collection._bits; + _state = 0; + _current = default(KeyValuePair); + _hasUnknown = collection.MaybeUnknown != null; + _unknownEnumerator = _hasUnknown + ? collection.MaybeUnknown.GetEnumerator() + : default(Dictionary.Enumerator); + } + + public KeyValuePair Current => _current; + + object IEnumerator.Current => _current; + + public void Dispose() + { + } + + public void Reset() + { + _state = 0; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs index 47873ea1d1..2932eab142 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameRequestStream.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class FrameRequestStream : Stream { - readonly MessageBody _body; + private readonly MessageBody _body; //int _readLength; //bool _readFin; diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs new file mode 100644 index 0000000000..7d1b15ade1 --- /dev/null +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/FrameResponseHeaders.cs @@ -0,0 +1,57 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Framework.Primitives; +using System.Collections; +using System.Collections.Generic; + +namespace Microsoft.AspNet.Server.Kestrel.Http +{ + public partial class FrameResponseHeaders : FrameHeaders + { + public Enumerator GetEnumerator() + { + return new Enumerator(this); + } + + protected override IEnumerator> GetEnumeratorFast() + { + return GetEnumerator(); + } + + public partial struct Enumerator : IEnumerator> + { + private FrameResponseHeaders _collection; + private long _bits; + private int _state; + private KeyValuePair _current; + private bool _hasUnknown; + private Dictionary.Enumerator _unknownEnumerator; + + internal Enumerator(FrameResponseHeaders collection) + { + _collection = collection; + _bits = collection._bits; + _state = 0; + _current = default(KeyValuePair); + _hasUnknown = collection.MaybeUnknown != null; + _unknownEnumerator = _hasUnknown + ? collection.MaybeUnknown.GetEnumerator() + : default(Dictionary.Enumerator); + } + + public KeyValuePair Current => _current; + + object IEnumerator.Current => _current; + + public void Dispose() + { + } + + public void Reset() + { + _state = 0; + } + } + } +} diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs index 6df605409d..516c027eac 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerPrimary.cs @@ -17,9 +17,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { UvPipeHandle ListenPipe { get; set; } - List _dispatchPipes = new List(); - int _dispatchIndex; - ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); + private List _dispatchPipes = new List(); + private int _dispatchIndex; + private ArraySegment> _1234 = new ArraySegment>(new[] { new ArraySegment(new byte[] { 1, 2, 3, 4 }) }); protected ListenerPrimary(IMemoryPool memory) : base(memory) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs index e08eba68fd..cc26dad0c1 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MemoryPool.cs @@ -8,12 +8,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http { public class MemoryPool : IMemoryPool { - static readonly byte[] EmptyArray = new byte[0]; + private static readonly byte[] EmptyArray = new byte[0]; class Pool { - readonly Stack _stack = new Stack(); - readonly object _sync = new object(); + private readonly Stack _stack = new Stack(); + private readonly object _sync = new object(); public T[] Alloc(int size) { @@ -39,9 +39,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http } } - readonly Pool _pool1 = new Pool(); - readonly Pool _pool2 = new Pool(); - readonly Pool _pool3 = new Pool(); + private readonly Pool _pool1 = new Pool(); + private readonly Pool _pool2 = new Pool(); + private readonly Pool _pool3 = new Pool(); public byte[] Empty { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs index aee1933230..749f34433b 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/MessageBodyExchanger.cs @@ -17,11 +17,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Http private static readonly WaitCallback _completePending = CompletePending; protected readonly FrameContext _context; - object _sync = new Object(); + private object _sync = new Object(); - ArraySegment _buffer; - Queue _reads = new Queue(); - bool _send100Continue = true; + private ArraySegment _buffer; + private Queue _reads = new Queue(); + private bool _send100Continue = true; public MessageBodyExchanger(FrameContext context) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs index b2a2348c55..2355ae82be 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Infrastructure/KestrelThread.cs @@ -16,16 +16,16 @@ namespace Microsoft.AspNet.Server.Kestrel /// public class KestrelThread { - KestrelEngine _engine; - Thread _thread; - UvLoopHandle _loop; - UvAsyncHandle _post; - Queue _workAdding = new Queue(); - Queue _workRunning = new Queue(); - Queue _closeHandleAdding = new Queue(); - Queue _closeHandleRunning = new Queue(); - object _workSync = new Object(); - bool _stopImmediate = false; + private KestrelEngine _engine; + private Thread _thread; + private UvLoopHandle _loop; + private UvAsyncHandle _post; + private Queue _workAdding = new Queue(); + private Queue _workRunning = new Queue(); + private Queue _closeHandleAdding = new Queue(); + private Queue _closeHandleRunning = new Queue(); + private object _workSync = new Object(); + private bool _stopImmediate = false; private ExceptionDispatchInfo _closeError; public KestrelThread(KestrelEngine engine) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs index 4ff90ecd5b..eec141a421 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/Libuv.cs @@ -397,10 +397,10 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public sockaddr(long ignored) { x3 = x0 = x1 = x2 = x3 = 0; } - long x0; - long x1; - long x2; - long x3; + private long x0; + private long x1; + private long x2; + private long x3; } public struct uv_buf_t diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs index 90791f5fd8..1791fb56e7 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvConnectRequest.cs @@ -15,8 +15,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private readonly static Libuv.uv_connect_cb _uv_connect_cb = UvConnectCb; - Action _callback; - object _state; + private Action _callback; + private object _state; public void Init(UvLoopHandle loop) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs index 4c9f23aec1..cb4d5a37dc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvHandle.cs @@ -8,8 +8,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public abstract class UvHandle : UvMemory { - static Libuv.uv_close_cb _destroyMemory = DestroyMemory; - Action, IntPtr> _queueCloseHandle; + private static Libuv.uv_close_cb _destroyMemory = DestroyMemory; + private Action, IntPtr> _queueCloseHandle; unsafe protected void CreateHandle( Libuv uv, diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs index 42285e536a..e79ff42674 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvRequest.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { public class UvRequest : UvMemory { - GCHandle _pin; + private GCHandle _pin; protected override bool ReleaseHandle() { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs index fc40f8967d..a8841754bf 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvShutdownReq.cs @@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private readonly static Libuv.uv_shutdown_cb _uv_shutdown_cb = UvShutdownCb; - Action _callback; - object _state; + private Action _callback; + private object _state; public void Init(UvLoopHandle loop) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs index 03eee35cd7..39aba8b4dc 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Networking/UvWriteReq.cs @@ -15,13 +15,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking { private readonly static Libuv.uv_write_cb _uv_write_cb = UvWriteCb; - IntPtr _bufs; + private IntPtr _bufs; - Action _callback; - object _state; - const int BUFFER_COUNT = 4; + private Action _callback; + private object _state; + private const int BUFFER_COUNT = 4; - List _pins = new List(); + private List _pins = new List(); public void Init(UvLoopHandle loop) { diff --git a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs index ebfa3f406c..ff4499c472 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/ServerRequest.cs @@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Server.Kestrel { public class ServerRequest : IHttpRequestFeature, IHttpResponseFeature, IHttpUpgradeFeature { - Frame _frame; - string _scheme; - string _pathBase; + private Frame _frame; + private string _scheme; + private string _pathBase; private FeatureCollection _features; public ServerRequest(Frame frame) diff --git a/src/Microsoft.AspNet.Server.Kestrel/project.json b/src/Microsoft.AspNet.Server.Kestrel/project.json index 883cf9570f..4a3d0ab496 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/project.json +++ b/src/Microsoft.AspNet.Server.Kestrel/project.json @@ -7,7 +7,11 @@ }, "dependencies": { "Microsoft.AspNet.Hosting": "1.0.0-*", - "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*" + "Microsoft.Dnx.Runtime.Abstractions": "1.0.0-*", + "Microsoft.StandardsPolice": { + "version": "1.0.0-*", + "type": "build" + } }, "frameworks": { "dnx451": { }, diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs index c9da2fd71a..0593f879c1 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/KnownHeaders.cs @@ -186,9 +186,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http {Each(loops, loop => $@" public partial class {loop.ClassName} {{ - long _bits = 0; + private long _bits = 0; {Each(loop.Headers, header => @" - StringValues _" + header.Identifier + ";")} + private StringValues _" + header.Identifier + ";")} protected override int GetCountFast() {{ diff --git a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs index 610176c1c6..2a77e2542e 100644 --- a/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs +++ b/tools/Microsoft.AspNet.Server.Kestrel.GeneratedCode/Program.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Threading.Tasks; namespace Microsoft.AspNet.Server.Kestrel.GeneratedCode { diff --git a/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj b/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj new file mode 100644 index 0000000000..83282b2e37 --- /dev/null +++ b/tools/Microsoft.StandardsPolice/Microsoft.StandardsPolice.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + 82295647-7c1c-4671-bab6-0fef58f949ec + Microsoft.StandardsPolice + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/tools/Microsoft.StandardsPolice/Program.cs b/tools/Microsoft.StandardsPolice/Program.cs new file mode 100644 index 0000000000..8dd9a0636d --- /dev/null +++ b/tools/Microsoft.StandardsPolice/Program.cs @@ -0,0 +1,49 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Microsoft.StandardsPolice +{ + public class Program + { + public int Main(string[] args) + { + var tree = CSharpSyntaxTree.ParseText(@" +public class Hello { protected int _foo; int _bar; } +public class World { protected int _foo; int _bar; } +"); + var diags = new List(); + + var comp = CSharpCompilation.Create("Comp", new[] { tree }); + + StandardsPoliceCompileModule.ScanSyntaxTree(diags, tree); + + var hello = comp.GetTypeByMetadataName("Hello"); + foreach (var f in hello.GetMembers().OfType()) + { + var syntax = f.DeclaringSyntaxReferences.Single().GetSyntax(); + Console.WriteLine($"{syntax.ToFullString()}"); + + var fds = syntax.Parent.Parent as FieldDeclarationSyntax; + var toks = syntax.DescendantTokens().ToArray(); + var nods = syntax.DescendantNodesAndSelf().ToArray(); + var mods = fds.Modifiers; + + foreach (var mod in fds.Modifiers) + { + Console.WriteLine($"{mod.Kind()} {mod.ToFullString()}"); + } + var locs = f.Locations.ToArray(); + } + + foreach(var d in diags) + { + Console.WriteLine(d); + } + return 0; + } + } +} diff --git a/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs new file mode 100644 index 0000000000..4981e0fc0c --- /dev/null +++ b/tools/Microsoft.StandardsPolice/StandardsPoliceCompileModule.cs @@ -0,0 +1,109 @@ +using Microsoft.Dnx.Compilation.CSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Microsoft.StandardsPolice +{ + // This project can output the Class library as a NuGet Package. + // To enable this option, right-click on the project and select the Properties menu item. In the Build tab select "Produce outputs on build". + public class StandardsPoliceCompileModule : ICompileModule + { + public void BeforeCompile(BeforeCompileContext context) + { + ScanNamespace(context.Diagnostics, context.Compilation.GlobalNamespace); + + foreach (var st in context.Compilation.SyntaxTrees) + { + if (!st.FilePath.EndsWith(".Generated.cs")) + { + ScanSyntaxTree(context.Diagnostics, st); + } + } + } + + internal static void ScanSyntaxTree(IList diagnostics, SyntaxTree syntaxTree) + { + var root = syntaxTree.GetRoot(); + + var typeDeclarations = root.DescendantNodes(descendIntoChildren: node => !(node is TypeDeclarationSyntax)) + .OfType() + .ToArray(); + + if (typeDeclarations.Length > 1) + { + foreach (var typeDeclaration in typeDeclarations) + { + diagnostics.Add(Diagnostic.Create( + "SP1002", "StandardsPolice", "more than one type per file", + DiagnosticSeverity.Warning, + DiagnosticSeverity.Warning, + false, + 3, + location: typeDeclaration.GetLocation())); + } + } + } + + private static void ScanNamespace(IList diagnostics, INamespaceSymbol namespaceSymbol) + { + foreach (var member in namespaceSymbol.GetNamespaceMembers()) + { + ScanNamespace(diagnostics, member); + } + foreach (var member in namespaceSymbol.GetTypeMembers()) + { + ScanType(diagnostics, member); + } + } + + private static void ScanType(IList diagnostics, INamedTypeSymbol typeSymbol) + { + foreach (var member in typeSymbol.GetMembers().OfType()) + { + if (member.DeclaredAccessibility != Accessibility.Private) + { + continue; + } + + foreach (var syntaxReference in member.DeclaringSyntaxReferences) + { + var fieldHasPrivateKeyword = false; + var syntax = syntaxReference.GetSyntax(); + var fds = syntax?.Parent?.Parent as FieldDeclarationSyntax; + if (fds == null) + { + continue; + } + foreach (var mod in fds.Modifiers) + { + if (mod.IsKind(CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword)) + { + fieldHasPrivateKeyword = true; + } + } + if (!fieldHasPrivateKeyword) + { + diagnostics.Add(Diagnostic.Create( + "SP1001", "StandardsPolice", "private keyword missing", + DiagnosticSeverity.Warning, + DiagnosticSeverity.Warning, + false, + 3, + location: member.Locations.SingleOrDefault())); + } + } + } + foreach (var member in typeSymbol.GetTypeMembers()) + { + ScanType(diagnostics, member); + } + } + public void AfterCompile(AfterCompileContext context) + { + } + } +} diff --git a/tools/Microsoft.StandardsPolice/project.json b/tools/Microsoft.StandardsPolice/project.json new file mode 100644 index 0000000000..d279e371a3 --- /dev/null +++ b/tools/Microsoft.StandardsPolice/project.json @@ -0,0 +1,28 @@ +{ + "version": "1.0.0-*", + + "description": "Microsoft.StandardsPolice Class Library", + + "dependencies": { + "Microsoft.Dnx.Compilation.CSharp.Abstractions": "1.0.0-beta8-*" + }, + + "commands": { + "Microsoft.StandardsPolice": "Microsoft.StandardsPolice" + }, + + "frameworks": { + "dnx451": { + "frameworkAssemblies": { + "System.Runtime": "", + "System.Text.Encoding": "", + "System.Threading.Tasks": "" + } + }, + "dnxcore50": { + "dependencies": { + "System.Console": "4.0.0-beta-*" + } + } + } +}