Skip to content

Commit

Permalink
Update to latest stylecop (dotnet#1279)
Browse files Browse the repository at this point in the history
* Fix tuple warnings

* Remove SA1011 pragma directives
  • Loading branch information
richlander authored Nov 12, 2020
1 parent 15c7568 commit 06fc3a0
Show file tree
Hide file tree
Showing 126 changed files with 218 additions and 245 deletions.
2 changes: 1 addition & 1 deletion eng/Analyzers.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ file which is not marked as such, making StyleCop fail. -->
</PropertyGroup>
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<AdditionalFiles Include="$(MSBuildThisFileDirectory)\stylecop.json" Link="stylecop.json" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using System.Threading;
using System.Threading.Tasks;

#pragma warning disable SA1011 // Closing square brackets should be spaced correctly https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2927

namespace System.Device.Gpio.Drivers
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Ads1115/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// set I2C bus ID: 1
// ADS1115 Addr Pin connect to GND
I2cConnectionSettings settings = new (1, (int)I2cAddress.GND);
I2cConnectionSettings settings = new(1, (int)I2cAddress.GND);
// get I2cDevice (in Linux)
I2cDevice device = I2cDevice.Create(settings);

Expand Down
2 changes: 1 addition & 1 deletion src/devices/Adxl345/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Device.Spi;
using Iot.Device.Adxl345;

SpiConnectionSettings settings = new (0, 0)
SpiConnectionSettings settings = new(0, 0)
{
ClockFrequency = Adxl345.SpiClockFrequency,
Mode = Adxl345.SpiMode
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Ags01db/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading;
using Iot.Device.Ags01db;

I2cConnectionSettings settings = new (1, Ags01db.DefaultI2cAddress);
I2cConnectionSettings settings = new(1, Ags01db.DefaultI2cAddress);
I2cDevice device = I2cDevice.Create(settings);

using Ags01db sensor = new Ags01db(device);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Ahtxx/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Iot.Device.Ahtxx;

const int I2cBus = 1;
I2cConnectionSettings i2cSettings = new (I2cBus, Aht20.DefaultI2cAddress);
I2cConnectionSettings i2cSettings = new(I2cBus, Aht20.DefaultI2cAddress);
I2cDevice i2cDevice = I2cDevice.Create(i2cSettings);

// For AHT10 or AHT15 use:
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Ak8963/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Numerics;
using Iot.Device.Magnetometer;

I2cConnectionSettings mpui2CConnectionSettingmpus = new (1, Ak8963.DefaultI2cAddress);
I2cConnectionSettings mpui2CConnectionSettingmpus = new(1, Ak8963.DefaultI2cAddress);
using Ak8963 ak8963 = new Ak8963(I2cDevice.Create(mpui2CConnectionSettingmpus));
Console.WriteLine(
"Magnetometer calibration is taking couple of seconds, move your sensor in all possible directions! Make sure you don't have a magnet or phone close by.");
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bh1745/Bh1745.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Bh1745(I2cDevice device)
{
_i2cDevice = device;
// ChannelCompensationMultipliers: Red, Green, Blue, Clear
ChannelCompensationMultipliers = new (2.2, 1.0, 1.8, 10.0);
ChannelCompensationMultipliers = new(2.2, 1.0, 1.8, 10.0);

// reset device and set default configuration
InitDevice();
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bh1745/samples/Program.CustomConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
// multipliers affect the compensated values
// ChannelCompensationMultipliers: Red, Green, Blue, Clear
ChannelCompensationMultipliers = new (2.5, 0.9, 1.9, 9.5),
ChannelCompensationMultipliers = new(2.5, 0.9, 1.9, 9.5),

// set custom measurement time
MeasurementTime = MeasurementTime.Ms1280,
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bh1745/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const int busId = 1;

// create device
I2cConnectionSettings i2cSettings = new (busId, Bh1745.DefaultI2cAddress);
I2cConnectionSettings i2cSettings = new(busId, Bh1745.DefaultI2cAddress);
using I2cDevice i2cDevice = I2cDevice.Create(i2cSettings);
using Bh1745 i2cBh1745 = new Bh1745(i2cDevice);
// wait for first measurement
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bh1750fvi/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Threading;
using Iot.Device.Bh1750fvi;

I2cConnectionSettings settings = new (busId: 1, (int)I2cAddress.AddPinLow);
I2cConnectionSettings settings = new(busId: 1, (int)I2cAddress.AddPinLow);
using I2cDevice device = I2cDevice.Create(settings);
using Bh1750fvi sensor = new Bh1750fvi(device);
while (true)
Expand Down
4 changes: 2 additions & 2 deletions src/devices/Bmp180/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// bus id on the raspberry pi 3
const int busId = 1;

I2cConnectionSettings i2cSettings = new (busId, Bmp180.DefaultI2cAddress);
I2cConnectionSettings i2cSettings = new(busId, Bmp180.DefaultI2cAddress);
using I2cDevice i2cDevice = I2cDevice.Create(i2cSettings);

using Bmp180 i2cBmp280 = new Bmp180(i2cDevice);
using Bmp180 i2cBmp280 = new(i2cDevice);
// set samplings
i2cBmp280.SetSampling(Sampling.Standard);

Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bmxx80/samples/Bme280.sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// set this to the current sea level pressure in the area for correct altitude readings
Pressure defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

I2cConnectionSettings i2cSettings = new (busId, Bme280.DefaultI2cAddress);
I2cConnectionSettings i2cSettings = new(busId, Bme280.DefaultI2cAddress);
using I2cDevice i2cDevice = I2cDevice.Create(i2cSettings);
using Bme280 bme80 = new Bme280(i2cDevice)
{
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bmxx80/samples/Bme680.sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// set this to the current sea level pressure in the area for correct altitude readings
Pressure defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

I2cConnectionSettings i2cSettings = new (busId, Bme680.DefaultI2cAddress);
I2cConnectionSettings i2cSettings = new(busId, Bme680.DefaultI2cAddress);
I2cDevice i2cDevice = I2cDevice.Create(i2cSettings);

using Bme680 bme680 = new Bme680(i2cDevice, Temperature.FromDegreesCelsius(20.0));
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bmxx80/samples/Bmp280.sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// set this to the current sea level pressure in the area for correct altitude readings
Pressure defaultSeaLevelPressure = WeatherHelper.MeanSeaLevel;

I2cConnectionSettings i2cSettings = new (busId, Bmp280.DefaultI2cAddress);
I2cConnectionSettings i2cSettings = new(busId, Bmp280.DefaultI2cAddress);
I2cDevice i2cDevice = I2cDevice.Create(i2cSettings);
using var i2CBmp280 = new Bmp280(i2cDevice);

Expand Down
2 changes: 1 addition & 1 deletion src/devices/Bno055/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

Console.WriteLine("Hello BNO055!");
using I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, Bno055Sensor.DefaultI2cAddress));
using Bno055Sensor bno055Sensor = new (i2cDevice);
using Bno055Sensor bno055Sensor = new(i2cDevice);
Console.WriteLine(
$"Id: {bno055Sensor.Info.ChipId}, AccId: {bno055Sensor.Info.AcceleratorId}, GyroId: {bno055Sensor.Info.GyroscopeId}, MagId: {bno055Sensor.Info.MagnetometerId}");
Console.WriteLine(
Expand Down
2 changes: 1 addition & 1 deletion src/devices/BoardLed/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Iot.Device.BoardLed;

// Open the green led on Raspberry Pi.
using BoardLed led = new ("led0");
using BoardLed led = new("led0");

string defaultTrigger = led.Trigger;

Expand Down
2 changes: 0 additions & 2 deletions src/devices/BrickPi3/BrickPi3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,6 @@ public byte[] GetSensor(byte port)
throw new IOException($"{nameof(GetSensor)} error: Sensor not configured or not supported.");
}

#pragma warning disable SA1011
/// <summary>
/// Set the sensor type
/// </summary>
Expand All @@ -871,7 +870,6 @@ public byte[] GetSensor(byte port)
/// </param>
public void SetSensorType(byte port, SensorType type, int[]? param = null)
{
#pragma warning restore SA1011
for (int p = 0; p < 4; p++)
{
if ((port & (1 << p)) > 0)
Expand Down
16 changes: 8 additions & 8 deletions src/devices/Card/CreditCard/BerSplitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ public BerSplitter(ReadOnlySpan<byte> toSplit)
try
{
var resTag = DecodeTag(toSplit.Slice(index));
var tagNumber = resTag.Item1;
var tagNumber = resTag.TagNumber;
// Need to move index depending on how many has been read
index += resTag.Item2;
index += resTag.NumberElements;
var resSize = DecodeSize(toSplit.Slice(index));
var data = new byte[resSize.Item1];
var data = new byte[resSize.Size];
var elem = new Tag(
tagNumber,
data);
Tags.Add(elem);
index += resSize.Item2;
toSplit.Slice(index, resSize.Item1).CopyTo(elem.Data);
index += resSize.Item1;
index += resSize.NumBytes;
toSplit.Slice(index, resSize.Size).CopyTo(elem.Data);
index += resSize.Size;

}
catch (Exception ex) when (ex is ArgumentOutOfRangeException || ex is OverflowException)
Expand All @@ -52,7 +52,7 @@ public BerSplitter(ReadOnlySpan<byte> toSplit)
}
}

private (uint tagNumber, byte numberElements) DecodeTag(ReadOnlySpan<byte> toSplit)
private (uint TagNumber, byte NumberElements) DecodeTag(ReadOnlySpan<byte> toSplit)
{
uint tagValue = toSplit[0];
byte index = 1;
Expand All @@ -70,7 +70,7 @@ public BerSplitter(ReadOnlySpan<byte> toSplit)
return (tagValue, index);
}

private (int size, byte numBytes) DecodeSize(ReadOnlySpan<byte> toSplit)
private (int Size, byte NumBytes) DecodeSize(ReadOnlySpan<byte> toSplit)
{
// Case infinite
if (toSplit[0] == 0b1000_0000)
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Card/CreditCard/TagList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TagList
/// List of Tags description, source, conversion for display as well as if they are templates or contain Data Object Link
/// This list is coming from the EMV documentation, see EMV book 3, Annexe A
/// </summary>
public static List<TagDetails> Tags = new ()
public static List<TagDetails> Tags = new()
{
new TagDetails() { TagNumber = 0x06, Source = Source.Icc, Decoder = ConversionType.ByteArray, Description = "Object Identifier (OID)", IsTemplate = false, IsDol = false },
new TagDetails() { TagNumber = 0x41, Source = Source.Icc, Decoder = ConversionType.ByteArray, Description = "Country code and national data", IsTemplate = false, IsDol = false },
Expand Down
21 changes: 10 additions & 11 deletions src/devices/Card/Mifare/MifareCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class MifareCard
/// </summary>
public MifareCardCommand Command { get; set; }

#pragma warning disable SA1011
/// <summary>
/// Key A Used for encryption/decryption
/// </summary>
Expand Down Expand Up @@ -111,7 +110,7 @@ public int RunMifiCardCommand()
/// </summary>
/// <param name="accessSector">the access sector</param>
/// <returns>the 3 bytes for configuration</returns>
public (byte b6, byte b7, byte b8) EncodeSectorTailer(AccessSector accessSector)
public (byte B6, byte B7, byte B8) EncodeSectorTailer(AccessSector accessSector)
{
byte c1 = 0;
byte c2 = 0;
Expand Down Expand Up @@ -197,7 +196,7 @@ public int RunMifiCardCommand()
/// <param name="blockNumber">The block sector to encode</param>
/// <param name="accessType">The access type to encode</param>
/// <returns>The encoded sector tailer for the specific block</returns>
public (byte b6, byte b7, byte b8) EncodeSectorTailer(byte blockNumber, AccessType accessType)
public (byte B6, byte B7, byte B8) EncodeSectorTailer(byte blockNumber, AccessType accessType)
{
blockNumber = (byte)(blockNumber % 4);

Expand Down Expand Up @@ -445,23 +444,23 @@ public AccessType BlockAccess(byte blockNumber, byte[] sectorData)
/// <param name="accessSector">The access desired</param>
/// <param name="accessTypes">An array of 3 AccessType determining access of each block</param>
/// <returns>The 3 bytes encoding the rights</returns>
public (byte b6, byte b7, byte b8) EncodeSectorAndClockTailer(AccessSector accessSector, AccessType[] accessTypes)
public (byte B6, byte B7, byte B8) EncodeSectorAndClockTailer(AccessSector accessSector, AccessType[] accessTypes)
{
if (accessTypes.Length != 3)
{
throw new ArgumentException(nameof(accessTypes), "Array must have 3 elements.");
}

var tupleRes = EncodeSectorTailer(accessSector);
byte b6 = tupleRes.Item1;
byte b7 = tupleRes.Item2;
byte b8 = tupleRes.Item3;
byte b6 = tupleRes.B6;
byte b7 = tupleRes.B7;
byte b8 = tupleRes.B8;
for (byte i = 0; i < 3; i++)
{
tupleRes = EncodeSectorTailer(i, accessTypes[i]);
b6 |= tupleRes.Item1;
b7 |= tupleRes.Item2;
b8 |= tupleRes.Item3;
b6 |= tupleRes.B6;
b7 |= tupleRes.B7;
b8 |= tupleRes.B8;
}

return (b6, b7, b8);
Expand All @@ -471,7 +470,7 @@ public AccessType BlockAccess(byte blockNumber, byte[] sectorData)
/// Encode with default value the access sector and tailer blocks
/// </summary>
/// <returns></returns>
public (byte b6, byte b7, byte b8) EncodeDefaultSectorAndBlockTailer() => (0xFF, 0x07, 0x80);
public (byte B6, byte B7, byte B8) EncodeDefaultSectorAndBlockTailer() => (0xFF, 0x07, 0x80);

/// <summary>
/// From the ATAQ ans SAK data find common card capacity
Expand Down
2 changes: 0 additions & 2 deletions src/devices/Card/Rfid/Data106kbpsTypeA.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable SA1011

namespace Iot.Device.Rfid
{
/// <summary>
Expand Down
12 changes: 5 additions & 7 deletions src/devices/CharacterLcd/LcdCharacterEncodingFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Collections.Generic;
using System.Globalization;

#pragma warning disable SA1011

namespace Iot.Device.CharacterLcd
{
/// <summary>
Expand Down Expand Up @@ -387,13 +385,13 @@ public LcdCharacterEncoding Create(CultureInfo culture, string romName, char unk
// Need to copy the static map, we must not update that
Dictionary<char, byte> newMap = romName switch
{
"A00" => new (DefaultA00Map),
"A02" => new (DefaultA02Map),
"SplC780" => new (DefaultSplC780Map),
_ => new (DefaultCustomMap),
"A00" => new(DefaultA00Map),
"A02" => new(DefaultA02Map),
"SplC780" => new(DefaultSplC780Map),
_ => new(DefaultCustomMap),
};

List<byte[]> extraCharacters = new ();
List<byte[]> extraCharacters = new();
bool supported = AssignLettersForCurrentCulture(newMap, culture, romName, extraCharacters, maxNumberOfCustomCharacters);

if (!newMap.ContainsKey(unknownLetter))
Expand Down
2 changes: 1 addition & 1 deletion src/devices/CharacterLcd/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void UsingGpioPins()
void UsingMcp()
{
using I2cDevice i2cDevice = I2cDevice.Create(new I2cConnectionSettings(1, 0x21));
using Mcp23008 driver = new (i2cDevice);
using Mcp23008 driver = new(i2cDevice);
int[] dataPins = { 3, 4, 5, 6 };
int registerSelectPin = 1;
int enablePin = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Charlieplex/CharlieplexSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CharlieplexSegment(int[] pins, int nodeCount = 0, GpioController? gpioCo
}

_shouldDispose = shouldDispose || gpioController is null;
_gpioController = gpioController ?? new ();
_gpioController = gpioController ?? new();

// first two pins will be needed as Output.
_gpioController.OpenPin(pins[0], PinMode.Output);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/Charlieplex/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Console.WriteLine($"Node {i} -- Anode: {node.Anode}; Cathode: {node.Cathode}");
}

using CharlieplexSegment charlie = new (pins, charlieSegmentLength);
using CharlieplexSegment charlie = new(pins, charlieSegmentLength);
var twoSeconds = TimeSpan.FromSeconds(2);

Console.WriteLine("Light all LEDs");
Expand Down
2 changes: 0 additions & 2 deletions src/devices/Common/Iot/Device/Graphics/BdfFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using System.Text;
using System.Threading.Tasks;

#pragma warning disable SA1011 // Closing square brackets should be spaced correctly https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/2927

namespace Iot.Device.Graphics
{
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/devices/CpuTemperature/CpuTemperature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private bool CheckAvailable()
/// Returns all known temperature sensor values.
/// </summary>
/// <returns>A list of name/value pairs for temperature sensors</returns>
public List<(string, Temperature)> ReadTemperatures()
public List<(string Sensor, Temperature Temperature)> ReadTemperatures()
{
if (!_windows)
{
Expand Down
4 changes: 2 additions & 2 deletions src/devices/CpuTemperature/samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
var temperature = cpuTemperature.ReadTemperatures();
foreach (var entry in temperature)
{
if (!double.IsNaN(entry.Item2.DegreesCelsius))
if (!double.IsNaN(entry.Temperature.DegreesCelsius))
{
Console.WriteLine($"Temperature from {entry.Item1.ToString()}: {entry.Item2.DegreesCelsius} °C");
Console.WriteLine($"Temperature from {entry.Sensor.ToString()}: {entry.Temperature.DegreesCelsius} °C");
}
else
{
Expand Down
Loading

0 comments on commit 06fc3a0

Please sign in to comment.