Skip to content

Commit

Permalink
add code format check (#196)
Browse files Browse the repository at this point in the history
* add code formating check, apply ParquetSharp.DotSettings, add .editorconfig per project

* format code

* format new code
  • Loading branch information
ljubon authored Jul 21, 2021
1 parent 7ea3828 commit 39acb40
Show file tree
Hide file tree
Showing 93 changed files with 377 additions and 243 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2021.1.3",
"commands": [
"jb"
]
}
}
}
29 changes: 29 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[*.{csproj,json,targets}]
indent_size = 2
resharper_xml_wrap_tags_and_pi = false

[*.cs]
csharp_new_line_before_members_in_object_initializers = false
csharp_preserve_single_line_blocks = true
resharper_blank_lines_after_block_statements = 0
resharper_blank_lines_around_auto_property = 0
resharper_blank_lines_around_single_line_type = 0
resharper_csharp_blank_lines_around_field = 0
resharper_csharp_insert_final_newline = true
resharper_csharp_wrap_lines = false
resharper_empty_block_style = multiline
resharper_keep_existing_embedded_block_arrangement = false
resharper_keep_existing_enum_arrangement = false
resharper_max_attribute_length_for_same_line = 70
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_expr_accessor_on_single_line = true
resharper_place_expr_method_on_single_line = true
resharper_place_expr_property_on_single_line = true
resharper_place_field_attribute_on_same_line = false
resharper_place_simple_embedded_statement_on_same_line = true
resharper_place_simple_initializer_on_single_line = false
resharper_remove_blank_lines_near_braces_in_code = false
resharper_remove_blank_lines_near_braces_in_declarations = false
resharper_wrap_array_initializer_style = chop_if_long
resharper_wrap_chained_binary_expressions = chop_if_long
resharper_wrap_object_and_collection_initializer_style = chop_always
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ jobs:

# Note that vcpkg dependencies takes the majority of the build time.
# We cache them using GitHub Actions cache and export, making the scripts below a bit more complex.
check-format:
if: github.event_name == 'push' || github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.dotnet_5_version }}
- name: Code formating check
run: |
dotnet tool restore
dotnet jb cleanupcode "csharp" "csharp.test" "csharp.benchmark" --profile="Built-in: Reformat Code" --settings="ParquetSharp.DotSettings" --dotnetcoresdk=${{ env.dotnet_5_version }} --verbosity=WARN
files=($(git diff --name-only))
if [ ${#files[@]} -gt 0 ]
then
for file in $files; do echo "::error file=$file::Code format check failed"; done
exit 1
fi
# Build everything on all platorms (thus testing the developer workflow).
# Upload the native shared libraries as artifacts.
Expand Down
7 changes: 7 additions & 0 deletions ParquetSharp.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LINES/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/LINE_FEED_AT_FILE_END/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSOR_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
</wpf:ResourceDictionary>
29 changes: 29 additions & 0 deletions csharp.benchmark/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[*.{csproj,json,targets}]
indent_size = 2
resharper_xml_wrap_tags_and_pi = false

[*.cs]
csharp_new_line_before_members_in_object_initializers = false
csharp_preserve_single_line_blocks = true
resharper_blank_lines_after_block_statements = 0
resharper_blank_lines_around_auto_property = 0
resharper_blank_lines_around_single_line_type = 0
resharper_csharp_blank_lines_around_field = 0
resharper_csharp_insert_final_newline = true
resharper_csharp_wrap_lines = false
resharper_empty_block_style = multiline
resharper_keep_existing_embedded_block_arrangement = false
resharper_keep_existing_enum_arrangement = false
resharper_max_attribute_length_for_same_line = 70
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_expr_accessor_on_single_line = true
resharper_place_expr_method_on_single_line = true
resharper_place_expr_property_on_single_line = true
resharper_place_field_attribute_on_same_line = false
resharper_place_simple_embedded_statement_on_same_line = true
resharper_place_simple_initializer_on_single_line = false
resharper_remove_blank_lines_near_braces_in_code = false
resharper_remove_blank_lines_near_braces_in_declarations = false
resharper_wrap_array_initializer_style = chop_if_long
resharper_wrap_chained_binary_expressions = chop_if_long
resharper_wrap_object_and_collection_initializer_style = chop_always
4 changes: 2 additions & 2 deletions csharp.benchmark/DecimalRead.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public DecimalRead()
{
var n = rand.Next();
var sign = rand.NextDouble() < 0.5 ? -1M : +1M;
return sign * ((decimal)n * n * n) / 1000M;
return sign * ((decimal) n * n * n) / 1000M;
}).ToArray();

using (var fileWriter = new ParquetFileWriter(Filename, new Column[] { new Column<decimal>("Value", LogicalType.Decimal(precision: 29, scale: 3)) }))
using (var fileWriter = new ParquetFileWriter(Filename, new Column[] {new Column<decimal>("Value", LogicalType.Decimal(precision: 29, scale: 3))}))
{
using var rowGroupWriter = fileWriter.AppendRowGroup();
using var valueWriter = rowGroupWriter.NextColumn().LogicalWriter<decimal>();
Expand Down
2 changes: 1 addition & 1 deletion csharp.benchmark/DecimalWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public DecimalWrite()
{
var n = rand.Next();
var sign = rand.NextDouble() < 0.5 ? -1M : +1M;
return sign * ((decimal)n * n * n) / 1000M;
return sign * ((decimal) n * n * n) / 1000M;
}).ToArray();

Console.WriteLine("Generated {0:N0} rows in {1:N2} sec", _values.Length, timer.Elapsed.TotalSeconds);
Expand Down
2 changes: 1 addition & 1 deletion csharp.benchmark/FloatTimeSeriesBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected static (DateTime[] dates, int[] objectIds, float[][] values, int numRo
.OrderBy(i => i)
.ToArray();

var values = dates.Select(d => objectIds.Select(o => (float)rand.NextDouble()).ToArray()).ToArray();
var values = dates.Select(d => objectIds.Select(o => (float) rand.NextDouble()).ToArray()).ToArray();
var numRows = values.Select(v => v.Length).Aggregate(0, (sum, l) => sum + l);

return (dates, objectIds, values, numRows);
Expand Down
2 changes: 1 addition & 1 deletion csharp.benchmark/FloatTimeSeriesWrite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public long CsvGz()

return new FileInfo("float_timeseries.csv.gz").Length;
}

[Benchmark(Baseline = true, Description = "Baseline")]
public long Parquet()
{
Expand Down
2 changes: 1 addition & 1 deletion csharp.benchmark/ParquetSharp.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
<ProjectReference Include="..\csharp\ParquetSharp.csproj" />
</ItemGroup>

</Project>
</Project>
8 changes: 4 additions & 4 deletions csharp.benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static int Main()
Console.WriteLine("Working directory: {0}", Environment.CurrentDirectory);

var config = DefaultConfig
.Instance
.AddColumn(new SizeInBytesColumn())
.WithOptions(ConfigOptions.Default | ConfigOptions.StopOnFirstError)
.Instance
.AddColumn(new SizeInBytesColumn())
.WithOptions(ConfigOptions.Default | ConfigOptions.StopOnFirstError)
;

var summaries = BenchmarkRunner.Run(new[]
Expand All @@ -32,7 +32,7 @@ public static int Main()

// Re-print to the console all the summaries.
var logger = ConsoleLogger.Default;

logger.WriteLine();

foreach (var summary in summaries)
Expand Down
2 changes: 1 addition & 1 deletion csharp.benchmark/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"ParquetCppSharp.Test": {
"commandName": "Project",
"nativeDebugging": true
"nativeDebugging": true
}
}
}
29 changes: 29 additions & 0 deletions csharp.test/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[*.{csproj,json,targets}]
indent_size = 2
resharper_xml_wrap_tags_and_pi = false

[*.cs]
csharp_new_line_before_members_in_object_initializers = false
csharp_preserve_single_line_blocks = true
resharper_blank_lines_after_block_statements = 0
resharper_blank_lines_around_auto_property = 0
resharper_blank_lines_around_single_line_type = 0
resharper_csharp_blank_lines_around_field = 0
resharper_csharp_insert_final_newline = true
resharper_csharp_wrap_lines = false
resharper_empty_block_style = multiline
resharper_keep_existing_embedded_block_arrangement = false
resharper_keep_existing_enum_arrangement = false
resharper_max_attribute_length_for_same_line = 70
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_expr_accessor_on_single_line = true
resharper_place_expr_method_on_single_line = true
resharper_place_expr_property_on_single_line = true
resharper_place_field_attribute_on_same_line = false
resharper_place_simple_embedded_statement_on_same_line = true
resharper_place_simple_initializer_on_single_line = false
resharper_remove_blank_lines_near_braces_in_code = false
resharper_remove_blank_lines_near_braces_in_declarations = false
resharper_wrap_array_initializer_style = chop_if_long
resharper_wrap_chained_binary_expressions = chop_if_long
resharper_wrap_object_and_collection_initializer_style = chop_always
2 changes: 1 addition & 1 deletion csharp.test/ParquetSharp.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
<ProjectReference Include="..\csharp\ParquetSharp.csproj" />
</ItemGroup>

</Project>
</Project>
8 changes: 4 additions & 4 deletions csharp.test/PhysicalValueGetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public PhysicalValueGetter(long numValues)
_numValues = numValues;
}

public (Array values, short[] definitionLevels, short[] repetitionLevels) OnColumnReader<TValue>(ColumnReader<TValue> columnReader)
public (Array values, short[] definitionLevels, short[] repetitionLevels) OnColumnReader<TValue>(ColumnReader<TValue> columnReader)
where TValue : unmanaged
{
var values = new TValue[_numValues];
Expand All @@ -22,11 +22,11 @@ public PhysicalValueGetter(long numValues)
while (columnReader.HasNext)
{
var levelsRead = columnReader.ReadBatch(
_numValues - totalLevels, defLevels.AsSpan(totalLevels), repLevels.AsSpan(totalLevels), values.AsSpan(totalValues),
_numValues - totalLevels, defLevels.AsSpan(totalLevels), repLevels.AsSpan(totalLevels), values.AsSpan(totalValues),
out var valuesRead);

totalValues += (int)valuesRead;
totalLevels += (int)levelsRead;
totalValues += (int) valuesRead;
totalLevels += (int) levelsRead;
}

return (values.Where((v, i) => i < totalValues).ToArray(), defLevels.ToArray(), repLevels.ToArray());
Expand Down
2 changes: 1 addition & 1 deletion csharp.test/PhysicalValueSetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public ValueSetter(Array values, (int begin, int end)? range = null)
_range = range ?? (0, values.Length);
}

public Array OnColumnWriter<TValue>(ColumnWriter<TValue> columnWriter)
public Array OnColumnWriter<TValue>(ColumnWriter<TValue> columnWriter)
where TValue : unmanaged
{
var values = (TValue[]) _values;
Expand Down
3 changes: 1 addition & 2 deletions csharp.test/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using System;
using System;
using System.Runtime.ExceptionServices;

namespace ParquetSharp.Test
Expand Down
2 changes: 1 addition & 1 deletion csharp.test/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"ParquetCppSharp.Test": {
"commandName": "Project",
"nativeDebugging": true
"nativeDebugging": true
}
}
}
2 changes: 1 addition & 1 deletion csharp.test/TestAadPrefixVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ public TestVerifier(string exceptionMessage)
public override void Verify(string aadPrefix) => throw new ArgumentException(ExceptionMessage);
}
}
}
}
2 changes: 1 addition & 1 deletion csharp.test/TestBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static void TestBufferOutputStreamFinish()
{
var expected = Enumerable.Range(0, 100).ToArray();
using var outStream = new BufferOutputStream();

// Write out a single column
using (var fileWriter = new ParquetFileWriter(outStream, new Column[] {new Column<int>("int_field")}))
{
Expand Down
2 changes: 1 addition & 1 deletion csharp.test/TestByteArrayReaderCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void TestReadingDuplicateStrings([Values(true, false)] bool enable

// When reading back the file, we expect the duplicate strings to point to the same memory instances.
Assert.That(
readValues.Distinct(new StringReferenceComparer()).Count(),
readValues.Distinct(new StringReferenceComparer()).Count(),
enableDictionary ? Is.EqualTo(100) : Is.EqualTo(numRows));
}

Expand Down
2 changes: 1 addition & 1 deletion csharp.test/TestColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void TestUnsupportedType()
[Test]
public static void TestUnsupportedLogicalTypeOverride()
{
var exception = Assert.Throws<ParquetException>(() =>
var exception = Assert.Throws<ParquetException>(() =>
new Column<DateTime>("DateTime", LogicalType.Json()).CreateSchemaNode());

Assert.That(
Expand Down
4 changes: 2 additions & 2 deletions csharp.test/TestColumnPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void TestDotRepresentations()
Assert.AreEqual(new[] {"root", "part0", "part1"}, p1.ToDotVector());

using var p2 = p0.Extend("part2");

Assert.AreEqual("root.part0.part1.part2", p2.ToDotString());
}

Expand Down Expand Up @@ -85,7 +85,7 @@ public static void TestNodeRepresentationUtf8()

Assert.AreEqual("", schema.Path.ToDotString());
Assert.AreEqual(name + "", schema.Field(0).Path.ToDotString());
Assert.AreEqual(name+ ".list", ((GroupNode) schema.Field(0)).Field(0).Path.ToDotString());
Assert.AreEqual(name + ".list", ((GroupNode) schema.Field(0)).Field(0).Path.ToDotString());
Assert.AreEqual(name + ".list.item", ((GroupNode) ((GroupNode) schema.Field(0)).Field(0)).Field(0).Path.ToDotString());
}
}
Expand Down
4 changes: 2 additions & 2 deletions csharp.test/TestColumnReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static void TestSkip()
{
const int numRows = 11;

var schemaColumns = new Column[] { new Column<int>("int32_field") };
var schemaColumns = new Column[] {new Column<int>("int32_field")};
var values = Enumerable.Range(0, numRows).ToArray();

using var buffer = new ResizableBuffer();

using (var outStream = new BufferOutputStream(buffer))
Expand Down
4 changes: 2 additions & 2 deletions csharp.test/TestColumnWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void TestWriteBatchWithNullOptionalField()
using var writer = new ParquetFileWriter(outStream, new Column[] {new Column<int?>("int32?")});
using var rowGroupWriter = writer.AppendRowGroup();
using var colWriter = (ColumnWriter<int>) rowGroupWriter.NextColumn();

var defLevels = new short[] {1, 0, 1};
var values = new[] {1, 2};

Expand All @@ -43,7 +43,7 @@ public static void TestUnsupportedType()
using var buffer = new ResizableBuffer();
using var outStream = new BufferOutputStream(buffer);

var exception = Assert.Throws<ArgumentException>(() =>
var exception = Assert.Throws<ArgumentException>(() =>
new ParquetFileWriter(outStream, new Column[] {new Column<object>("unsupported")}));

Assert.AreEqual("unsupported logical type System.Object", exception?.Message);
Expand Down
4 changes: 2 additions & 2 deletions csharp.test/TestDecimal128.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class TestDecimal128
[TestCaseSource(nameof(Scales))]
public static void TestRoundTrip(int scale)
{
var list = new List<decimal>{0, 1};
var list = new List<decimal> {0, 1};
for (int i = 0; i != 28; ++i)
{
list.Add(list.Last() * 10);
Expand Down Expand Up @@ -65,7 +65,7 @@ public static void TestAgainstThirdParty()
var columns = new Column[] {new Column<decimal>("Decimal", LogicalType.Decimal(precision: 29, scale: 3))};
var values = Enumerable.Range(0, 10_000)
.Select(i => ((decimal) i * i * i) / 1000 - 10)
.Concat(new [] {decimal.MinValue / 1000, decimal.MaxValue / 1000})
.Concat(new[] {decimal.MinValue / 1000, decimal.MaxValue / 1000})
.ToArray();

using var buffer = new ResizableBuffer();
Expand Down
Loading

0 comments on commit 39acb40

Please sign in to comment.