diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..2a93aa0 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "jetbrains.resharper.globaltools": { + "version": "2021.2.2", + "commands": [ + "jb" + ] + } + } +} \ No newline at end of file diff --git a/Common.DotSettings b/Common.DotSettings index 6780c14..5adb19b 100644 --- a/Common.DotSettings +++ b/Common.DotSettings @@ -1,4 +1,6 @@  + False + True True AssemblyInfo.cs True @@ -6,13 +8,30 @@ DO_NOT_SHOW ERROR ERROR + DO_NOT_SHOW True HINT DO_NOT_SHOW DO_NOT_SHOW - <?xml version="1.0" encoding="utf-16"?><Profile name="CatalogueCleanup"><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><HtmlReformatCode>True</HtmlReformatCode><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseVar><BehavourStyle>CAN_CHANGE_BOTH</BehavourStyle><LocalVariableStyle>ALWAYS_IMPLICIT</LocalVariableStyle><ForeachVariableStyle>ALWAYS_IMPLICIT</ForeachVariableStyle></CSUseVar><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSReorderTypeMembers>True</CSReorderTypeMembers><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><XMLReformatCode>True</XMLReformatCode><IDEA_SETTINGS>&lt;profile version="1.0"&gt; + ERROR + ERROR + <?xml version="1.0" encoding="utf-16"?><Profile name="CatalogueCleanup"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><CSRemoveCodeRedundancies>True</CSRemoveCodeRedundancies><CSUseVar><BehavourStyle>CAN_CHANGE_BOTH</BehavourStyle><LocalVariableStyle>ALWAYS_IMPLICIT</LocalVariableStyle><ForeachVariableStyle>ALWAYS_IMPLICIT</ForeachVariableStyle></CSUseVar><CSOptimizeUsings><OptimizeUsings>False</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><CSharpFormatDocComments>True</CSharpFormatDocComments><CSReorderTypeMembers>True</CSReorderTypeMembers><JsReformatCode>True</JsReformatCode><JsFormatDocComments>True</JsFormatDocComments><IDEA_SETTINGS>&lt;profile version="1.0"&gt; &lt;option name="myName" value="CatalogueCleanup" /&gt; + &lt;inspection_tool class="ES6ShorthandObjectProperty" enabled="false" level="INFORMATION" enabled_by_default="false" /&gt; + &lt;inspection_tool class="JSArrowFunctionBracesCanBeRemoved" enabled="false" level="INFORMATION" enabled_by_default="false" /&gt; + &lt;inspection_tool class="JSPrimitiveTypeWrapperUsage" enabled="false" level="WARNING" enabled_by_default="false" /&gt; + &lt;inspection_tool class="JSRemoveUnnecessaryParentheses" enabled="false" level="INFORMATION" enabled_by_default="false" /&gt; + &lt;inspection_tool class="JSUnnecessarySemicolon" enabled="false" level="WARNING" enabled_by_default="false" /&gt; + &lt;inspection_tool class="TypeScriptExplicitMemberType" enabled="false" level="INFORMATION" enabled_by_default="false" /&gt; + &lt;inspection_tool class="UnnecessaryContinueJS" enabled="false" level="WARNING" enabled_by_default="false" /&gt; + &lt;inspection_tool class="UnnecessaryLabelJS" enabled="false" level="WARNING" enabled_by_default="false" /&gt; + &lt;inspection_tool class="UnnecessaryLabelOnBreakStatementJS" enabled="false" level="WARNING" enabled_by_default="false" /&gt; + &lt;inspection_tool class="UnnecessaryLabelOnContinueStatementJS" enabled="false" level="WARNING" enabled_by_default="false" /&gt; + &lt;inspection_tool class="UnnecessaryReturnJS" enabled="false" level="WARNING" enabled_by_default="false" /&gt; +&lt;/profile&gt;</IDEA_SETTINGS><XAMLCollapseEmptyTags>False</XAMLCollapseEmptyTags><FormatAttributeQuoteDescriptor>True</FormatAttributeQuoteDescriptor></Profile> + <?xml version="1.0" encoding="utf-16"?><Profile name="FullCatalogueCleanup"><XMLReformatCode>True</XMLReformatCode><CSCodeStyleAttributes ArrangeTypeAccessModifier="False" ArrangeTypeMemberAccessModifier="False" SortModifiers="False" RemoveRedundantParentheses="False" AddMissingParentheses="False" ArrangeBraces="False" ArrangeAttributes="False" ArrangeArgumentsStyle="False" ArrangeCodeBodyStyle="False" ArrangeVarStyle="False" ArrangeTrailingCommas="False" /><HtmlReformatCode>True</HtmlReformatCode><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><AspOptimizeRegisterDirectives>True</AspOptimizeRegisterDirectives><RemoveCodeRedundanciesVB>True</RemoveCodeRedundanciesVB><VBOptimizeImports>True</VBOptimizeImports><VBShortenReferences>True</VBShortenReferences><VBFormatDocComments>True</VBFormatDocComments><CSharpFormatDocComments>True</CSharpFormatDocComments><CSShortenReferences>True</CSShortenReferences><CSReorderTypeMembers>True</CSReorderTypeMembers><IDEA_SETTINGS>&lt;profile version="1.0"&gt; + &lt;option name="myName" value="FullCatalogueCleanup" /&gt; &lt;/profile&gt;</IDEA_SETTINGS></Profile> CatalogueCleanup public protected internal private new abstract virtual override sealed static readonly extern unsafe volatile async @@ -119,13 +138,15 @@ False False False + False AP AB TTN WB $object$_On$event$ - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="_Test" Style="AaBb_AaBb" /></Policy> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="Test" Suffix="" Style="AaBb_AaBb" /><ExtraRule Prefix="" Suffix="Test" Style="AaBb_AaBb" /></Policy> + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="Test" Suffix="" Style="AaBb" /><ExtraRule Prefix="" Suffix="Test" Style="AaBb" /></Policy> <Policy Inspect="True" Prefix="I" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb"><ExtraRule Prefix="" Suffix="" Style="AaBb_AaBb" /></Policy> @@ -184,22 +205,6 @@ True True True - True - True - True - getCurrentDate("dd.MM.yyyy") - -1 - 1 - True - getUserName() - -1 - 0 - True - True - Everywhere - unstable - True - [Category("Unstable")] // marked by $user$ $date$$END$ True True Imported 29.01.2015 @@ -333,21 +338,23 @@ public void SetUp() cbn True [CanBeNull] - True - True - Imported 29.01.2015 - True - 0 - True - True - 2.0 - InCSharpStatement - True - 2.0 - InCSharpFile - ipse - True - throw new InvalidProgramStateException("$TODO$"); + False + + + + + + + + + + + + + + + True + True diff --git a/Directory.Build.props b/Directory.Build.props index 7e94621..c485c94 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,8 +13,8 @@ - - + + \ No newline at end of file diff --git a/Excel.TemplateEngine.Tests/Excel.TemplateEngine.Tests.csproj b/Excel.TemplateEngine.Tests/Excel.TemplateEngine.Tests.csproj index ff24d8c..6172a3e 100644 --- a/Excel.TemplateEngine.Tests/Excel.TemplateEngine.Tests.csproj +++ b/Excel.TemplateEngine.Tests/Excel.TemplateEngine.Tests.csproj @@ -1,18 +1,18 @@  - net48;net5.0 + net48;net6.0 false SkbKontur.Excel.TemplateEngine.Tests SkbKontur.Excel.TemplateEngine.Tests - - - - - + + + + + diff --git a/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs b/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs index 6356624..b262bba 100644 --- a/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs +++ b/Excel.TemplateEngine.Tests/ObjectPrintingTests/ExcelParsingTests.cs @@ -15,6 +15,7 @@ using SkbKontur.Excel.TemplateEngine.ObjectPrinting.TableNavigator; using SkbKontur.Excel.TemplateEngine.ObjectPrinting.TableParser; +using Vostok.Logging.Abstractions; using Vostok.Logging.Console; namespace SkbKontur.Excel.TemplateEngine.Tests.ObjectPrintingTests @@ -32,6 +33,12 @@ internal class SingleStringContainer [TestFixture] public class ExcelParsingTests : FileBasedTestBase { + [Test] + public void Create() + { + ExcelDocumentFactory.TryCreateFromTemplate(File.ReadAllBytes(@"C:\Users\p.vostretsov\Downloads\ДМ_2010.xlsx"), new ConsoleLog()); + } + [Test] public void TestStringsWithManyFormattedFragments() { @@ -79,14 +86,16 @@ public void TestEnumerableWithPrimaryKey() } model.Type.Should().Be("Основной"); - model.Items.Should().BeEquivalentTo( - new Item {Id = "2311129000009", Name = "СЫР ГОЛЛАНДСКИЙ МОЖГА 1КГ", BuyerProductId = "000074467", Articul = "123456"}, - new Item {Id = "2311131000004", Name = "СЫР РОССИЙСКИЙ МОЖГА 1КГ", BuyerProductId = "000074468", Articul = "123457"}, - new Item {Id = null, Name = "Товар 3"}, - new Item {Id = "123", Articul = "3123123"}, - new Item {Id = "111", Articul = "111111"}, - new Item {Name = "Товар 6"}, - new Item {Id = "222", Name = "Товар 7", Articul = "123"} + model.Items.Should().BeEquivalentTo(new[] + { + new Item {Id = "2311129000009", Name = "СЫР ГОЛЛАНДСКИЙ МОЖГА 1КГ", BuyerProductId = "000074467", Articul = "123456"}, + new Item {Id = "2311131000004", Name = "СЫР РОССИЙСКИЙ МОЖГА 1КГ", BuyerProductId = "000074468", Articul = "123457"}, + new Item {Id = null, Name = "Товар 3"}, + new Item {Id = "123", Articul = "3123123"}, + new Item {Id = "111", Articul = "111111"}, + new Item {Name = "Товар 6"}, + new Item {Id = "222", Name = "Товар 7", Articul = "123"} + } ); } @@ -186,7 +195,7 @@ public void TestImportAfterCreate(string extension) using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(File.ReadAllBytes(GetFilePath($"empty.{extension}")), logger)) { var template = new ExcelTable(templateDocument.GetWorksheet(0)); - var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); + var templateEngine = new TemplateEngine(template, logger); var target = new ExcelTable(targetDocument.GetWorksheet(0)); var tableNavigator = new TableNavigator(new CellPosition("A1"), logger); @@ -219,7 +228,7 @@ public void TestImportAfterCreate(string extension) using (var targetDocument = ExcelDocumentFactory.CreateFromTemplate(targetBytes, logger)) { var template = new ExcelTable(templateDocument.GetWorksheet(0)); - var templateEngine = new SkbKontur.Excel.TemplateEngine.TemplateEngine(template, logger); + var templateEngine = new TemplateEngine(template, logger); var target = new ExcelTable(targetDocument.GetWorksheet(0)); var tableNavigator = new TableNavigator(new CellPosition("A1"), logger); @@ -255,7 +264,7 @@ public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; + if (obj.GetType() != GetType()) return false; return Equals((Item)obj); } diff --git a/Excel.TemplateEngine.Tests/ObjectPrintingTests/ManualPrintingTests.cs b/Excel.TemplateEngine.Tests/ObjectPrintingTests/ManualPrintingTests.cs index 892404c..b9ca610 100644 --- a/Excel.TemplateEngine.Tests/ObjectPrintingTests/ManualPrintingTests.cs +++ b/Excel.TemplateEngine.Tests/ObjectPrintingTests/ManualPrintingTests.cs @@ -199,7 +199,7 @@ public void TestPrintingComments() } /// - /// output file must contain the same comments, but one author + /// output file must contain the same comments, but one author /// [Test] public void TestPrintingCommentsWithSeveralAuthors() @@ -223,7 +223,7 @@ public void TestPrintingCommentsWithSeveralAuthors() Assert.Fail($"Please manually open file:\n{path}\nand check that cells has same comments as in\n{templatePath}\n"); } } - + /// /// output file must contain data validations AND rendered comment /// @@ -255,7 +255,7 @@ public void TestPrintingCommentsWithEnabledDataValidationByOtherSheetData() - D4-D7 has data validation with values from the second worksheet and G4-G7 has data validation with values from K1:K6"); } } - + private void CopySecondaryWorksheets(IExcelDocument templateDocument, IExcelDocument targetDocument) { foreach (var index in Enumerable.Range(1, templateDocument.GetWorksheetCount() - 1)) diff --git a/Excel.TemplateEngine/Excel.TemplateEngine.csproj b/Excel.TemplateEngine/Excel.TemplateEngine.csproj index 77ccfd6..aba20eb 100644 --- a/Excel.TemplateEngine/Excel.TemplateEngine.csproj +++ b/Excel.TemplateEngine/Excel.TemplateEngine.csproj @@ -10,14 +10,14 @@ - - - + + + - + diff --git a/Excel.TemplateEngine/FileGenerating/DataTypes/ExcelCellIndex.cs b/Excel.TemplateEngine/FileGenerating/DataTypes/ExcelCellIndex.cs index cd915f6..0f0e725 100644 --- a/Excel.TemplateEngine/FileGenerating/DataTypes/ExcelCellIndex.cs +++ b/Excel.TemplateEngine/FileGenerating/DataTypes/ExcelCellIndex.cs @@ -32,13 +32,13 @@ public ExcelCellIndex Subtract(ExcelCellIndex other) public int RowIndex { get; } public int ColumnIndex { get; } - private static string ToCellReference(int rowIndex, int columnIndex) + private static string ToCellReference(int rowIndex, int columnIndex) => $"{ToColumnName(columnIndex)}{rowIndex}"; - private static string ToCellReference(uint rowIndex, int columnIndex) + private static string ToCellReference(uint rowIndex, int columnIndex) => ToCellReference((int)rowIndex, columnIndex); - private static int ToRowIndex(string cellReference) + private static int ToRowIndex(string cellReference) => int.Parse(new Regex("[A-Z]+").Replace(cellReference, "")); private static int ToColumnIndex(string cellReference) diff --git a/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelCell.cs b/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelCell.cs index ca59562..d41f235 100644 --- a/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelCell.cs +++ b/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelCell.cs @@ -17,7 +17,7 @@ public ExcelCell(Cell cell, IExcelDocumentStyle documentStyle, IExcelSharedStrin this.excelSharedStrings = excelSharedStrings; } - public IExcelCell SetStringValue(string value) + public IExcelCell SetStringValue(string value) => SetFormattedStringValue(new FormattedStringValue { Blocks = new[] diff --git a/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelWorksheet.cs b/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelWorksheet.cs index 735a3e6..813eed5 100644 --- a/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelWorksheet.cs +++ b/Excel.TemplateEngine/FileGenerating/Primitives/Implementations/ExcelWorksheet.cs @@ -359,6 +359,5 @@ private static T InsertWorksheetChild(Worksheet openXmlWorksheetNodesOrder, T private readonly ILog logger; private readonly Worksheet worksheet; private readonly TreeDictionary rowsCache; - } } \ No newline at end of file diff --git a/Excel.TemplateEngine/ObjectPrinting/ExcelDocumentPrimitives/Implementations/ExcelCell.cs b/Excel.TemplateEngine/ObjectPrinting/ExcelDocumentPrimitives/Implementations/ExcelCell.cs index a642a4b..e3f0f5a 100644 --- a/Excel.TemplateEngine/ObjectPrinting/ExcelDocumentPrimitives/Implementations/ExcelCell.cs +++ b/Excel.TemplateEngine/ObjectPrinting/ExcelDocumentPrimitives/Implementations/ExcelCell.cs @@ -11,11 +11,7 @@ public ExcelCell(IExcelCell excelCell) internalCell = excelCell; } - public string StringValue - { - get => internalCell.GetStringValue(); - set => internalCell.SetStringValue(value); - } + public string StringValue { get => internalCell.GetStringValue(); set => internalCell.SetStringValue(value); } public CellType CellType { diff --git a/Excel.TemplateEngine/ObjectPrinting/Helpers/TypeCheckingHelper.cs b/Excel.TemplateEngine/ObjectPrinting/Helpers/TypeCheckingHelper.cs index d2c5f83..93a00b5 100644 --- a/Excel.TemplateEngine/ObjectPrinting/Helpers/TypeCheckingHelper.cs +++ b/Excel.TemplateEngine/ObjectPrinting/Helpers/TypeCheckingHelper.cs @@ -11,19 +11,19 @@ public static bool IsEnumerable(Type type) => type != typeof(string) && (IsEnumerableDirectly(type) || type.GetInterfaces().Any(IsEnumerableDirectly)); - public static bool IsDictionary(Type type) + public static bool IsDictionary(Type type) => IsDictionaryDirectly(type) || type.GetInterfaces().Any(IsDictionaryDirectly); - public static bool IsIList(Type type) + public static bool IsIList(Type type) => type != typeof(string) && (IsIListDirectly(type) || type.GetInterfaces().Any(IsIListDirectly)); - public static bool IsNullable(Type type) + public static bool IsNullable(Type type) => Nullable.GetUnderlyingType(type) != null; - public static Type GetEnumerableItemType(Type type) + public static Type GetEnumerableItemType(Type type) => GetImplementedEnumerableInterface(type).GetGenericArguments().SingleOrDefault() ?? typeof(object); - public static Type GetIListItemType(Type type) + public static Type GetIListItemType(Type type) => GetImplementedIListInterface(type).GetGenericArguments().SingleOrDefault() ?? typeof(object); public static (Type keyType, Type valueType) GetDictionaryGenericTypeArguments(Type type) @@ -61,22 +61,22 @@ private static Type GetImplementedIListInterface(Type type) return type.GetInterfaces().FirstOrDefault(IsGenericIListDirectly) ?? type.GetInterfaces().FirstOrDefault(IsIListDirectly); } - private static bool IsGenericEnumerableDirectly(Type type) + private static bool IsGenericEnumerableDirectly(Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>); - private static bool IsGenericDictionaryDirectly(Type type) + private static bool IsGenericDictionaryDirectly(Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IDictionary<,>); - private static bool IsEnumerableDirectly(Type type) + private static bool IsEnumerableDirectly(Type type) => type == typeof(IEnumerable) || IsGenericEnumerableDirectly(type); - private static bool IsDictionaryDirectly(Type type) + private static bool IsDictionaryDirectly(Type type) => type == typeof(IDictionary) || IsGenericDictionaryDirectly(type); - private static bool IsIListDirectly(Type type) + private static bool IsIListDirectly(Type type) => type == typeof(IList) || IsGenericIListDirectly(type); - private static bool IsGenericIListDirectly(Type type) + private static bool IsGenericIListDirectly(Type type) => type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IList<>); } } \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 308cdb7..29efc7b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,36 +4,46 @@ skip_commits: files: - '**/*.md' -image: Visual Studio 2019 +image: Visual Studio 2022 init: - cmd: git config --global core.autocrlf false + +nuget: + disable_publish_on_pr: true + +before_build: - ps: | $ErrorActionPreference = "Stop" $tagName = $env:APPVEYOR_REPO_TAG_NAME if ($tagName -match '^v\d+\.\d+') # tag name starts with 'vX.Y' { + $version = $tagName.Substring(1) $env:SHOULD_PUBLISH_NUGET_PACKAGE = "true" Write-Host "Will publish nuget package for $tagName tag" -ForegroundColor "Green" if ($tagName -match '^v\d+\.\d+-release') # tag name starts with 'vX.Y-release' (e.g. use 'v4.2-release.1' tag for the first patch for release v4.2) { + $version = $version.Substring(0, $version.IndexOf("-release")) $env:SHOULD_CREATE_RELEASE = "true" Write-Host "Will create release for $tagName tag" -ForegroundColor "Green" } + $matchVersion = Select-String -Path ./version.json -Pattern "`"version`": `"$version`"" + if ($matchVersion -eq $null) + { + Write-Error "Version in tag ($version) does not match version in version.json" + } } - -nuget: - disable_publish_on_pr: true - -before_build: - cmd: dotnet --info - cmd: dotnet restore ./Excel.TemplateEngine.sln --verbosity minimal + - cmd: dotnet tool restore build_script: - cmd: dotnet build --configuration Release ./Excel.TemplateEngine.sln - cmd: dotnet pack --no-build --configuration Release ./Excel.TemplateEngine.sln test_script: + - cmd: dotnet jb cleanupcode Excel.TemplateEngine.sln --profile=CatalogueCleanup --verbosity=WARN + - cmd: git diff --exit-code - cmd: dotnet test --no-build --configuration Release ./Excel.TemplateEngine.Tests/Excel.TemplateEngine.Tests.csproj artifacts: @@ -43,7 +53,7 @@ deploy: - provider: NuGet server: https://nuget.org api_key: - secure: y2RPf+gBBqffQVm8pg9qZcg99m7K8hsSa4z7VHvIE6t+kuO7r/oIqTVcryZzL93D + secure: 3Myenol+seNdEnkmH7tadxQLsmOE7VWQSp6vQii4vt2dX1S7XwjNV4T24HQTUsrr skip_symbols: true on: SHOULD_PUBLISH_NUGET_PACKAGE: true diff --git a/global.json b/global.json index 8c50959..d6c2c37 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,6 @@ { "sdk": { - "version": "5.0.103" + "version": "6.0.100", + "rollForward": "latestFeature" } } \ No newline at end of file