Skip to content

Commit

Permalink
Merge pull request #5737 from bdukes/warnings-as-errors
Browse files Browse the repository at this point in the history
Turn on TreatWarningsAsErrors for all projects
  • Loading branch information
mitchelsellers authored Jul 17, 2023
2 parents 5cb4bf1 + 8661bcc commit a41c60a
Show file tree
Hide file tree
Showing 68 changed files with 2,872 additions and 2,719 deletions.
2 changes: 2 additions & 0 deletions DNN Platform/Connectors/Azure/Dnn.AzureConnector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<DocumentationFile>bin\Dnn.AzureConnector.xml</DocumentationFile>
<LangVersion>7</LangVersion>
<NoWarn>1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -40,6 +41,7 @@
<DocumentationFile>bin\Dnn.AzureConnector.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Cloud_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<DocumentationFile>bin\DNN.Connectors.GoogleAnalytics.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Cloud_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<DocumentationFile>bin\DNN.Connectors.GoogleAnalytics4.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Cloud_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<DocumentationFile>bin\DNN.Connectors.GoogleTagManager.xml</DocumentationFile>
<LangVersion>7</LangVersion>
<NoWarn>1591</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -40,7 +41,7 @@
<DocumentationFile>bin\DNN.Connectors.GoogleTagManager.xml</DocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Cloud_Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
2 changes: 2 additions & 0 deletions DNN Platform/DotNetNuke.Log4net/DotNetNuke.Log4Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7</LangVersion>
<DocumentationFile>bin\DotNetNuke.log4net.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\</OutputPath>
Expand All @@ -63,6 +64,7 @@
<Prefer32Bit>false</Prefer32Bit>
<LangVersion>7</LangVersion>
<DocumentationFile>bin\DotNetNuke.log4net.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<DocumentationFile>bin\DotNetNuke.Web.Client.XML</DocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>SA1600,SA1614</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -44,6 +46,8 @@
<DocumentationFile>bin\DotNetNuke.Web.Client.XML</DocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>SA1600,SA1614</WarningsNotAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="ClientDependency.Core, Version=1.9.10.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
55 changes: 27 additions & 28 deletions DNN Platform/DotNetNuke.Web.Mvc/Common/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,31 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Web.Mvc.Common
{
using System.Web.Routing;
namespace DotNetNuke.Web.Mvc.Common
{
using System.Web.Routing;

public static class TypeHelper
{
/// <summary>
/// Given an object of anonymous type, add each property as a key and associated with its value to a dictionary.
///
/// This helper will cache accessors and types, and is intended when the anonymous object is accessed multiple
/// times throughout the lifetime of the web application.
/// </summary>
/// <returns></returns>
public static RouteValueDictionary ObjectToDictionary(object value)
{
RouteValueDictionary dictionary = new RouteValueDictionary();

if (value != null)
{
foreach (PropertyHelper helper in PropertyHelper.GetProperties(value))
{
dictionary.Add(helper.Name, helper.GetValue(value));
}
}

return dictionary;
}
}
}
public static class TypeHelper
{
/// <summary>
/// Given an object of anonymous type, add each property as a key and associated with its value to a dictionary.
///
/// This helper will cache accessors and types, and is intended when the anonymous object is accessed multiple
/// times throughout the lifetime of the web application.
/// </summary>
public static RouteValueDictionary ObjectToDictionary(object value)
{
RouteValueDictionary dictionary = new RouteValueDictionary();

if (value != null)
{
foreach (PropertyHelper helper in PropertyHelper.GetProperties(value))
{
dictionary.Add(helper.Name, helper.GetValue(value));
}
}

return dictionary;
}
}
}
8 changes: 8 additions & 0 deletions DNN Platform/DotNetNuke.Web.Mvc/DotNetNuke.Web.Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,27 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DocumentationFile>bin\DotNetNuke.Web.Mvc.XML</DocumentationFile>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1591</NoWarn>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,SA1600,SA1611,SA1612,SA1614,SA1615,SA1618</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DocumentationFile>bin\DotNetNuke.Web.Mvc.XML</DocumentationFile>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>1591</NoWarn>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,SA1600,SA1611,SA1612,SA1614,SA1615,SA1618</WarningsNotAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetNuke">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,80 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Web.Mvc.Framework.ActionFilters
{
using System;
using System.Web;
using System.Web.Mvc;
namespace DotNetNuke.Web.Mvc.Framework.ActionFilters
{
using System;
using System.Web;
using System.Web.Mvc;

using DotNetNuke.Common;
using DotNetNuke.Common;

public abstract class AuthorizeAttributeBase : FilterAttribute, IAuthorizationFilter
{
public static bool IsAnonymousAttributePresent(AuthorizationContext filterContext)
{
return filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true)
|| filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true);
public abstract class AuthorizeAttributeBase : FilterAttribute, IAuthorizationFilter
{
public static bool IsAnonymousAttributePresent(AuthorizationContext filterContext)
{
return filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true)
|| filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), inherit: true);
}

/// <inheritdoc/>
public virtual void OnAuthorization(AuthorizationContext filterContext)
{
Requires.NotNull("filterContext", filterContext);

if (this.SkipAuthorization(filterContext))
{
return;
}

if (this.AuthorizeCore(filterContext.HttpContext))
{
this.HandleAuthorizedRequest(filterContext);
}
else
{
this.HandleUnauthorizedRequest(filterContext);
}
}

protected virtual bool AuthorizeCore(HttpContextBase httpContext)
{
return true;
}

protected virtual void HandleAuthorizedRequest(AuthorizationContext filterContext)
{
HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;
cachePolicy.SetProxyMaxAge(new TimeSpan(0));
cachePolicy.AddValidationCallback(this.CacheValidateHandler, null /* data */);
}

protected virtual void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
const string failureMessage = "Authorization has been denied for this request.";
var authFilterContext = new AuthFilterContext(filterContext, failureMessage);
authFilterContext.HandleUnauthorizedRequest();

// filterContext.HttpContext.Response.Redirect(Globals.AccessDeniedURL());
}

protected virtual HttpValidationStatus OnCacheAuthorization(HttpContextBase httpContext)
{
Requires.NotNull("httpContext", httpContext);

bool isAuthorized = this.AuthorizeCore(httpContext);
return isAuthorized ? HttpValidationStatus.Valid : HttpValidationStatus.IgnoreThisRequest;
}

/// <summary>Skips this authorization step if anonymous attribute is applied, override if auth should never be skipped, or other conditions are required.</summary>
/// <param name="actionContext"></param>
/// <returns></returns>
protected virtual bool SkipAuthorization(AuthorizationContext filterContext)
{
return IsAnonymousAttributePresent(filterContext);
}

private void CacheValidateHandler(HttpContext context, object data, ref HttpValidationStatus validationStatus)
{
validationStatus = this.OnCacheAuthorization(new HttpContextWrapper(context));
}
}
}
public virtual void OnAuthorization(AuthorizationContext filterContext)
{
Requires.NotNull("filterContext", filterContext);

if (this.SkipAuthorization(filterContext))
{
return;
}

if (this.AuthorizeCore(filterContext.HttpContext))
{
this.HandleAuthorizedRequest(filterContext);
}
else
{
this.HandleUnauthorizedRequest(filterContext);
}
}

protected virtual bool AuthorizeCore(HttpContextBase httpContext)
{
return true;
}

protected virtual void HandleAuthorizedRequest(AuthorizationContext filterContext)
{
HttpCachePolicyBase cachePolicy = filterContext.HttpContext.Response.Cache;
cachePolicy.SetProxyMaxAge(new TimeSpan(0));
cachePolicy.AddValidationCallback(this.CacheValidateHandler, null /* data */);
}

protected virtual void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
const string failureMessage = "Authorization has been denied for this request.";
var authFilterContext = new AuthFilterContext(filterContext, failureMessage);
authFilterContext.HandleUnauthorizedRequest();

// filterContext.HttpContext.Response.Redirect(Globals.AccessDeniedURL());
}

protected virtual HttpValidationStatus OnCacheAuthorization(HttpContextBase httpContext)
{
Requires.NotNull("httpContext", httpContext);

bool isAuthorized = this.AuthorizeCore(httpContext);
return isAuthorized ? HttpValidationStatus.Valid : HttpValidationStatus.IgnoreThisRequest;
}

/// <summary>Skips this authorization step if anonymous attribute is applied, override if auth should never be skipped, or other conditions are required.</summary>
protected virtual bool SkipAuthorization(AuthorizationContext filterContext)
{
return IsAnonymousAttributePresent(filterContext);
}

private void CacheValidateHandler(HttpContext context, object data, ref HttpValidationStatus validationStatus)
{
validationStatus = this.OnCacheAuthorization(new HttpContextWrapper(context));
}
}
}
4 changes: 4 additions & 0 deletions DNN Platform/DotNetNuke.Web.Razor/DotNetNuke.Web.Razor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
<WarningLevel>4</WarningLevel>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,CS0809,SA1600</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -45,6 +47,8 @@
<DocumentationFile>bin\DotNetNuke.Web.Razor.XML</DocumentationFile>
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,CS0809,SA1600</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
Expand Down
4 changes: 4 additions & 0 deletions DNN Platform/DotNetNuke.Web/DotNetNuke.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
<NoWarn>1591</NoWarn>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,CS3001,SA1600,SA1602,SA1604,SA1606,SA1611,SA1614</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand All @@ -68,6 +70,8 @@
<NoWarn>1591</NoWarn>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,CS3001,SA1600,SA1602,SA1604,SA1606,SA1611,SA1614</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<NoWarn>1591</NoWarn>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<Optimize>false</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>1</WarningLevel>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<DebugType>full</DebugType>
Expand All @@ -92,7 +92,7 @@
<Optimize>true</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>1</WarningLevel>
<NoWarn>42016,42017,42018,42019,42032,42353,42354,42355</NoWarn>
<DebugType>pdbonly</DebugType>
Expand Down
4 changes: 4 additions & 0 deletions DNN Platform/HttpModules/DotNetNuke.HttpModules.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
<NoWarn>1591</NoWarn>
<LangVersion>7</LangVersion>
<DefineConstants>DEBUG</DefineConstants>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,SA1600,SA1602,SA1608,SA1614</WarningsNotAsErrors>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\</OutputPath>
Expand All @@ -58,6 +60,8 @@
<NoWarn>1591</NoWarn>
<Optimize>true</Optimize>
<LangVersion>7</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CS0618,SA1600,SA1602,SA1608,SA1614</WarningsNotAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetNuke.Instrumentation">
Expand Down
Loading

0 comments on commit a41c60a

Please sign in to comment.