From 0fb64d65cc9897d7f53fe42580d538d15d8d8c96 Mon Sep 17 00:00:00 2001 From: Julien Lebosquain Date: Wed, 21 Jan 2026 08:16:46 +0000 Subject: [PATCH] Enable warnings as errors (#20504) --- .editorconfig | 57 +++++++++---------- Avalonia.sln | 1 - Directory.Build.props | 23 ++++---- build/NullableEnable.props | 8 +-- build/TrimmingEnable.props | 18 +----- build/WarnAsErrors.props | 23 -------- .../Avalonia.HarfBuzz.csproj | 2 - src/Skia/Avalonia.Skia/Avalonia.Skia.csproj | 2 - 8 files changed, 43 insertions(+), 91 deletions(-) delete mode 100644 build/WarnAsErrors.props diff --git a/.editorconfig b/.editorconfig index 7051372383..bfeab8c84f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -138,30 +138,25 @@ space_within_single_line_array_initializer_braces = true #Net Analyzer dotnet_analyzer_diagnostic.category-Performance.severity = none #error - Uncomment when all violations are fixed. -# CS0649: Field 'field' is never assigned to, and will always have its default value 'value' -dotnet_diagnostic.CS0649.severity = error - -# CS0162: Remove unreachable code -dotnet_diagnostic.CS0162.severity = error # CA1018: Mark attributes with AttributeUsageAttribute -dotnet_diagnostic.CA1018.severity = error +dotnet_diagnostic.CA1018.severity = warning # CA1304: Specify CultureInfo dotnet_diagnostic.CA1304.severity = warning # CA1802: Use literals where appropriate dotnet_diagnostic.CA1802.severity = warning # CA1813: Avoid unsealed attributes -dotnet_diagnostic.CA1813.severity = error +dotnet_diagnostic.CA1813.severity = warning # CA1815: Override equals and operator equals on value types dotnet_diagnostic.CA1815.severity = warning # CA1820: Test for empty strings using string length dotnet_diagnostic.CA1820.severity = warning # CA1821: Remove empty finalizers -dotnet_diagnostic.CA1821.severity = error +dotnet_diagnostic.CA1821.severity = warning # CA1822: Mark members as static dotnet_diagnostic.CA1822.severity = suggestion dotnet_code_quality.CA1822.api_surface = private, internal # CA1823: Avoid unused private fields -dotnet_diagnostic.CA1823.severity = error +dotnet_diagnostic.CA1823.severity = warning # CA1825: Avoid zero-length array allocations dotnet_diagnostic.CA1825.severity = warning # CA1826: Use property instead of Linq Enumerable method @@ -179,48 +174,48 @@ dotnet_diagnostic.CA1851.severity = warning #CA1854: Prefer the IDictionary.TryGetValue(TKey, out TValue) method dotnet_diagnostic.CA1854.severity = warning #CA2211:Non-constant fields should not be visible -dotnet_diagnostic.CA2211.severity = error +dotnet_diagnostic.CA2211.severity = warning # Wrapping preferences csharp_wrap_before_ternary_opsigns = false # Avalonia DevAnalyzer preferences -dotnet_diagnostic.AVADEV2001.severity = error +dotnet_diagnostic.AVADEV2001.severity = warning # Avalonia PublicAnalyzer preferences -dotnet_diagnostic.AVP1000.severity = error -dotnet_diagnostic.AVP1001.severity = error -dotnet_diagnostic.AVP1002.severity = error -dotnet_diagnostic.AVP1010.severity = error -dotnet_diagnostic.AVP1011.severity = error +dotnet_diagnostic.AVP1000.severity = warning +dotnet_diagnostic.AVP1001.severity = warning +dotnet_diagnostic.AVP1002.severity = warning +dotnet_diagnostic.AVP1010.severity = warning +dotnet_diagnostic.AVP1011.severity = warning dotnet_diagnostic.AVP1012.severity = warning -dotnet_diagnostic.AVP1013.severity = error -dotnet_diagnostic.AVP1020.severity = error -dotnet_diagnostic.AVP1021.severity = error -dotnet_diagnostic.AVP1022.severity = error -dotnet_diagnostic.AVP1030.severity = error -dotnet_diagnostic.AVP1031.severity = error -dotnet_diagnostic.AVP1032.severity = error -dotnet_diagnostic.AVP1040.severity = error -dotnet_diagnostic.AVA2001.severity = error +dotnet_diagnostic.AVP1013.severity = warning +dotnet_diagnostic.AVP1020.severity = warning +dotnet_diagnostic.AVP1021.severity = warning +dotnet_diagnostic.AVP1022.severity = warning +dotnet_diagnostic.AVP1030.severity = warning +dotnet_diagnostic.AVP1031.severity = warning +dotnet_diagnostic.AVP1032.severity = warning +dotnet_diagnostic.AVP1040.severity = warning +dotnet_diagnostic.AVA2001.severity = warning # Xaml files [*.{xaml,axaml}] indent_size = 2 # DuplicateSetterError -avalonia_xaml_diagnostic.AVLN2203.severity = error +avalonia_xaml_diagnostic.AVLN2203.severity = warning # StyleInMergedDictionaries -avalonia_xaml_diagnostic.AVLN2204.severity = error +avalonia_xaml_diagnostic.AVLN2204.severity = warning # RequiredTemplatePartMissing -avalonia_xaml_diagnostic.AVLN2205.severity = error +avalonia_xaml_diagnostic.AVLN2205.severity = warning # OptionalTemplatePartMissing avalonia_xaml_diagnostic.AVLN2206.severity = info # TemplatePartWrongType -avalonia_xaml_diagnostic.AVLN2207.severity = error +avalonia_xaml_diagnostic.AVLN2207.severity = warning # ItemContainerInsideTemplate -avalonia_xaml_diagnostic.AVLN2208.severity = error +avalonia_xaml_diagnostic.AVLN2208.severity = warning # Obsolete -avalonia_xaml_diagnostic.AVLN5001.severity = error +avalonia_xaml_diagnostic.AVLN5001.severity = warning # Xml project files [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] diff --git a/Avalonia.sln b/Avalonia.sln index 1083462dcc..06c3e051ac 100644 --- a/Avalonia.sln +++ b/Avalonia.sln @@ -106,7 +106,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Props", "Props", "{F3AC8BC1 build\TargetFrameworks.props = build\TargetFrameworks.props build\TrimmingEnable.props = build\TrimmingEnable.props build\UnitTests.NetFX.props = build\UnitTests.NetFX.props - build\WarnAsErrors.props = build\WarnAsErrors.props build\XUnit.props = build\XUnit.props EndProjectSection EndProject diff --git a/Directory.Build.props b/Directory.Build.props index 4498f87dab..400198daf9 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,17 +1,18 @@ - - $(MSBuildThisFileDirectory)build-intermediate/nuget - $(MSBuildThisFileDirectory)\src\tools\Avalonia.Designer.HostApp\bin\$(Configuration)\$(AvsCurrentTargetFramework)\Avalonia.Designer.HostApp.dll - - false - False - 14.0 - true - true - true - true + $(MSBuildThisFileDirectory)build-intermediate/nuget + $(MSBuildThisFileDirectory)\src\tools\Avalonia.Designer.HostApp\bin\$(Configuration)\$(AvsCurrentTargetFramework)\Avalonia.Designer.HostApp.dll + + false + False + 14.0 + $(AvnTreatWarningsAsErrors) + true + true + true + true + true diff --git a/build/NullableEnable.props b/build/NullableEnable.props index ef62ecc50c..60b91b85a3 100644 --- a/build/NullableEnable.props +++ b/build/NullableEnable.props @@ -1,11 +1,7 @@ - enable - $(WarningsAsErrors);nullable - $(NoWarn);nullable + + $(NoWarn);nullable diff --git a/build/TrimmingEnable.props b/build/TrimmingEnable.props index 34b3e232b6..cf84ae67b4 100644 --- a/build/TrimmingEnable.props +++ b/build/TrimmingEnable.props @@ -1,28 +1,16 @@ - + false true false true - - - true + $(TreatWarningsAsErrors) - - true - - $(WarningsAsErrors);IL2000;IL2001;IL2002;IL2003;IL2004;IL2005;IL2006;IL2007;IL2008;IL2009;IL2010;IL2011;IL2012;IL2013;IL2014;IL2015;IL2016;IL2017;IL2018;IL2019;IL2020;IL2021;IL2022;IL2023;IL2024;IL2025;IL2026;IL2027;IL2028;IL2029;IL2030;IL2031;IL2032;IL2033;IL2034;IL2035;IL2036;IL2037;IL2038;IL2039;IL2040;IL2041;IL2042;IL2043;IL2044;IL2045;IL2046;IL2047;IL2048;IL2049;IL2050;IL2051;IL2052;IL2053;IL2054;IL2055;IL2056;IL2057;IL2058;IL2059;IL2060;IL2061;IL2062;IL2063;IL2064;IL2065;IL2066;IL2067;IL2068;IL2069;IL2070;IL2071;IL2072;IL2073;IL2074;IL2075;IL2076;IL2077;IL2078;IL2079;IL2080;IL2081;IL2082;IL2083;IL2084;IL2085;IL2086;IL2087;IL2088;IL2089;IL2090;IL2091;IL2092;IL2093;IL2094;IL2095;IL2096;IL2097;IL2098;IL2099;IL2100;IL2101;IL2102;IL2103;IL2104;IL2105;IL2106;IL2107;IL2108;IL2109;IL2110;IL2111;IL2112;IL2113;IL2114;IL2115;IL2116;IL2117;IL2118;IL2119;IL2120;IL2121;IL2122;IL2123;IL2124;IL2125;IL2126;IL2127;IL2128;IL2129;IL2130;IL2131;IL2132;IL2133;IL2134;IL2135;IL2136;IL2137;IL2138;IL2139;IL2140;IL2141;IL2142;IL2143;IL2144;IL2145;IL2146;IL2147;IL2148;IL2149;IL2150;IL2151;IL2152;IL2153;IL2154;IL2155;IL2156;IL2157 - - $(WarningsAsErrors);IL3050;IL3051;IL3052;IL3053;IL3054;IL3055;IL3056 - - - - $(WarningsAsErrors);CA1420;CA1421 - + diff --git a/build/WarnAsErrors.props b/build/WarnAsErrors.props deleted file mode 100644 index eaab7bd00c..0000000000 --- a/build/WarnAsErrors.props +++ /dev/null @@ -1,23 +0,0 @@ - - - - - $(WarningsNotAsErrors);CS0649 - - $(WarningsNotAsErrors);CS0162 - - $(WarningsNotAsErrors);CA2211 - - $(WarningsNotAsErrors);CA1821 - - $(WarningsNotAsErrors);CA1823 - - $(WarningsNotAsErrors);AVLN2203 - - $(WarningsNotAsErrors);AVLN2205 - - $(WarningsNotAsErrors);AVLN2207 - - $(WarningsNotAsErrors);AVLN2208 - - diff --git a/src/HarfBuzz/Avalonia.HarfBuzz/Avalonia.HarfBuzz.csproj b/src/HarfBuzz/Avalonia.HarfBuzz/Avalonia.HarfBuzz.csproj index a528326db9..788886f3a9 100644 --- a/src/HarfBuzz/Avalonia.HarfBuzz/Avalonia.HarfBuzz.csproj +++ b/src/HarfBuzz/Avalonia.HarfBuzz/Avalonia.HarfBuzz.csproj @@ -4,8 +4,6 @@ true true true - - $(WarningsAsErrors);CS0618 diff --git a/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj b/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj index 9c4c4f62fb..d5f541a014 100644 --- a/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj +++ b/src/Skia/Avalonia.Skia/Avalonia.Skia.csproj @@ -4,8 +4,6 @@ true true true - - $(WarningsAsErrors);CS0618