Add StyleCop and fix reported code style issues (#101)

***NO_CI***
This commit is contained in:
Robin Jones 2022-08-20 08:53:48 +01:00 коммит произвёл GitHub
Родитель 7859d2bc52
Коммит 0a65d4d504
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
16 изменённых файлов: 166 добавлений и 69 удалений

112
Settings.StyleCop Normal file
Просмотреть файл

@ -0,0 +1,112 @@
<StyleCopSettings Version="105">
<Analyzers>
<Analyzer AnalyzerId="StyleCop.CSharp.DocumentationRules">
<Rules>
<Rule Name="FileHeaderMustContainFileName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustHaveValidCompanyText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderFileNameDocumentationMustMatchTypeName">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PropertyDocumentationMustHaveValueText">
<RuleSettings>
<BooleanProperty Name="Enabled">True</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustBeginWithACapitalLetter">
<RuleSettings>
<BooleanProperty Name="Enabled">True</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustEndWithAPeriod">
<RuleSettings>
<BooleanProperty Name="Enabled">True</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustShowCopyright">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FileHeaderMustHaveCopyrightText">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementDocumentationMustBeSpelledCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="DocumentationTextMustContainWhitespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings>
<BooleanProperty Name="IgnorePrivates">True</BooleanProperty>
<BooleanProperty Name="IgnoreInternals">True</BooleanProperty>
</AnalyzerSettings>
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.ReadabilityRules">
<Rules>
<Rule Name="PrefixLocalCallsWithThis">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="PrefixCallsCorrectly">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.OrderingRules">
<Rules>
<Rule Name="UsingDirectivesMustBePlacedWithinNamespace">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustAppearInTheCorrectOrder">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="ElementsMustBeOrderedByAccess">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
<Analyzer AnalyzerId="StyleCop.CSharp.NamingRules">
<Rules>
<Rule Name="FieldNamesMustNotBeginWithUnderscore">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
<Rule Name="FieldNamesMustNotUseHungarianNotation">
<RuleSettings>
<BooleanProperty Name="Enabled">False</BooleanProperty>
</RuleSettings>
</Rule>
</Rules>
<AnalyzerSettings />
</Analyzer>
</Analyzers>
</StyleCopSettings>

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{
@ -37,5 +35,5 @@ namespace System.IO.Ports
/// are used.
/// </summary>
RequestToSendXOnXOff
};
}
}

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{
@ -23,6 +21,6 @@ namespace System.IO.Ports
/// <summary>
/// Sets the parity bit so that the count of bits set is an even number.
/// </summary>
Even = 2,
};
Even = 2
}
}

Просмотреть файл

@ -1,4 +1,7 @@
using System.Reflection;
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@ -19,4 +22,3 @@ using System.Runtime.InteropServices;
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
using nanoFramework.Runtime.Events;

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
using System.Collections;
@ -21,7 +19,7 @@ namespace System.IO.Ports
private static ArrayList s_deviceCollection;
/// <summary>
/// Device collection associated with this <see cref="SerialDeviceController"/>.
/// Gets or sets the device collection associated with this <see cref="SerialDeviceController"/>.
/// </summary>
/// <remarks>
/// This collection is for internal use only.

Просмотреть файл

@ -1,10 +1,8 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
using nanoFramework.Runtime.Events;
using System.Collections;
using nanoFramework.Runtime.Events;
namespace System.IO.Ports
{

Просмотреть файл

@ -1,24 +1,22 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{
/// <summary>
/// Defines values for hardware and software mode of operation.
/// </summary>
public enum SerialMode
{
/// <summary>
/// Defines values for hardware and software mode of operation.
/// </summary>
public enum SerialMode
{
/// <summary>
/// Normal Serial mode with handshake define by SerialHandshake.
/// </summary>
Normal,
/// <summary>
/// Used for Half duplex RS485 mode.
/// Puts the port in to half duplex RS485 mode where the RTS is raised while the port is sending data. Once data is completely sent the RTS signal is lowered.
/// </summary>
RS485
}
/// <summary>
/// Used for Half duplex RS485 mode.
/// Puts the port in to half duplex RS485 mode where the RTS is raised while the port is sending data. Once data is completely sent the RTS signal is lowered.
/// </summary>
RS485
}
}

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
using System.Runtime.CompilerServices;
using System.Threading;
@ -32,6 +30,7 @@ namespace System.IO.Ports
private int _writeTimeout = Timeout.Infinite;
private int _readTimeout = Timeout.Infinite;
// default threshold is 1
private int _receivedBytesThreshold = 1;
private int _baudRate;
@ -187,7 +186,6 @@ namespace System.IO.Ports
}
}
//
/// <summary>
/// Gets or sets the handshaking protocol for serial port transmission of data using
/// a value from <see cref="Ports.Handshake"/>.
@ -269,7 +267,7 @@ namespace System.IO.Ports
}
/// <summary>
/// Gets or sets the Serial Mode
/// Gets or sets the Serial Mode.
/// </summary>
/// <remarks>This is a .NET nanoFramework property only.</remarks>
public SerialMode Mode
@ -352,8 +350,7 @@ namespace System.IO.Ports
}
/// <summary>
/// Gets a value indicating the open or closed status of the <see cref="SerialPort"/>
/// object.
/// Gets a value indicating whether the <see cref="SerialPort"/> is open or closed.
/// </summary>
/// <exception cref="ArgumentNullException">The <see cref="IsOpen"/> value passed is null.</exception>
/// <exception cref="ArgumentException">The <see cref="IsOpen"/> value passed is an empty string ("").</exception>
@ -464,7 +461,7 @@ namespace System.IO.Ports
}
/// <summary>
/// Gets or sets the logic level of the RX and TX signals.
/// Gets or sets a value indicating whether the logic level of the RX and TX signals are inverted.
/// </summary>
/// <exception cref="InvalidOperationException">Trying to set this property when the <see cref="SerialPort"/> is already opened and the driver doesn't support it.</exception>
/// <exception cref="NotSupportedException">Trying to set this property on a target that does not support signal inversion.</exception>
@ -658,7 +655,7 @@ namespace System.IO.Ports
/// <exception cref="InvalidOperationException">The specified port is not open.</exception>
/// <exception cref="ArgumentOutOfRangeException">The offset or count parameters are outside a valid region of the buffer being
/// passed. Either offset or count is less than zero.</exception>
/// <exception cref="ArgumentException">offset plus count is greater than the length of the buffer.</exception>
/// <exception cref="ArgumentException">Offset plus count is greater than the length of the buffer.</exception>
/// <exception cref="TimeoutException">No bytes were available to read.</exception>
[MethodImpl(MethodImplOptions.InternalCall)]
#pragma warning disable S4200 // OK to make a direct call
@ -716,7 +713,7 @@ namespace System.IO.Ports
/// <exception cref="InvalidOperationException">The specified port is not open.</exception>
/// <exception cref="ArgumentOutOfRangeException">The offset or count parameters are outside a valid region of the buffer being
/// passed. Either offset or count is less than zero.</exception>
/// <exception cref="ArgumentException">offset plus count is greater than the length of the buffer.</exception>
/// <exception cref="ArgumentException">Offset plus count is greater than the length of the buffer.</exception>
/// <exception cref="TimeoutException">The operation did not complete before the time-out period ended.</exception>
[MethodImpl(MethodImplOptions.InternalCall)]
#pragma warning disable S4200 // OK to make a direct call
@ -742,7 +739,7 @@ namespace System.IO.Ports
/// </summary>
/// <param name="text">The string for output.</param>
/// <exception cref="InvalidOperationException">The specified port is not open.</exception>
/// <exception cref="ArgumentNullException">text is null.</exception>
/// <exception cref="ArgumentNullException">Text is null.</exception>
/// <exception cref="TimeoutException">The operation did not complete before the time-out period ended.</exception>
#pragma warning disable S4200 // OK to make a direct call
public void Write(string text) => NativeWriteString(text, false);
@ -778,7 +775,7 @@ namespace System.IO.Ports
/// Releases the unmanaged resources used by the <see cref="SerialPort"/> and optionally
/// releases the managed resources.
/// </summary>
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged
/// <param name="disposing">True to release both managed and unmanaged resources; false to release only unmanaged
/// resources.</param>
/// <exception cref="IOException">The port is in an invalid state. -or- An attempt to set the state of the underlying
/// port failed. For example, the parameters passed from this <see cref="SerialPort"/>
@ -811,7 +808,7 @@ namespace System.IO.Ports
}
/// <summary>
/// Dispose the Serial Port
/// Dispose the Serial Port.
/// </summary>
public void Dispose()
{

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{

Просмотреть файл

@ -1,7 +1,5 @@
//
// Copyright (c) .NET Foundation and Contributors
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
namespace System.IO.Ports
{
@ -24,5 +22,5 @@ namespace System.IO.Ports
/// 1.5 stop bits are used.
/// </summary>
OnePointFive = 3
};
}
}

Просмотреть файл

@ -87,4 +87,11 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.5.107\build\Nerdbank.GitVersioning.targets'))" />
</Target>
<Import Project="..\packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets" Condition="Exists('..\packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\StyleCop.MSBuild.6.2.0\build\StyleCop.MSBuild.targets'))" />
</Target>
</Project>

Просмотреть файл

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="nanoFramework.CoreLibrary" version="1.12.0" targetFramework="netnanoframework10" />
<package id="nanoFramework.Runtime.Events" version="1.10.0" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.IO.Streams" version="1.1.9" targetFramework="netnanoframework10" />
<package id="nanoFramework.System.Text" version="1.2.3" targetFramework="netnanoframework10" />
<package id="Nerdbank.GitVersioning" version="3.5.107" targetFramework="netnanoframework10" developmentDependency="true" />
<package id="Nerdbank.GitVersioning" version="3.4.194" developmentDependency="true" targetFramework="netnanoframework10" />
<package id="StyleCop.MSBuild" version="6.2.0" targetFramework="netnano1.0" developmentDependency="true" />
</packages>