diff options
author | Matt Ward <matt.ward@microsoft.com> | 2020-01-17 18:43:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-17 18:43:53 +0300 |
commit | 7cd10e45004a2422b3a4eab51fae6a62d6442efb (patch) | |
tree | ab2c246cdf1742c88e76437af10cfbd01bf564b7 /main/src/addins | |
parent | 30ff79c2f58be039e7d3b9c430c1be50f6c30253 (diff) | |
parent | 0990511ae1b7a4bcfada1ea2a376e7e16bfd92b2 (diff) |
Merge pull request #9502 from mono/project-code-analysis-ruleset
[C#] Support CodeAnalysisRuleSet file
Diffstat (limited to 'main/src/addins')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs index ef40124eb1..ccedc00488 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CSharpCompilerParameters.cs @@ -28,7 +28,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.Globalization; +using System.IO; using System.Linq; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; @@ -46,7 +46,7 @@ namespace MonoDevelop.CSharp.Project public class CSharpCompilerParameters : DotNetCompilerParameters { // Configuration parameters - + FilePath codeAnalysisRuleSet; int? warninglevel = 4; [ItemProperty ("NoWarn", DefaultValue = "")] @@ -113,6 +113,7 @@ namespace MonoDevelop.CSharp.Project optimize = pset.GetValue ("Optimize", (bool?)null); warninglevel = pset.GetValue<int?> ("WarningLevel", null); outputType = pset.GetValue ("OutputType", "Library"); + codeAnalysisRuleSet = pset.GetPathValue ("CodeAnalysisRuleSet"); } static MetadataReferenceResolver CreateMetadataReferenceResolver (IMetadataService metadataService, string projectDirectory, string outputDirectory) @@ -205,18 +206,43 @@ namespace MonoDevelop.CSharp.Project Dictionary<string, ReportDiagnostic> GetSpecificDiagnosticOptions () { var result = new Dictionary<string, ReportDiagnostic> (); - foreach (var warning in GetSuppressedWarnings ()) - result [warning] = ReportDiagnostic.Suppress; var globalRuleSet = IdeApp.TypeSystemService.RuleSetManager.GetGlobalRuleSet (); if (globalRuleSet != null) { - foreach (var kv in globalRuleSet.SpecificDiagnosticOptions) { - result [kv.Key] = kv.Value; - } + AddSpecificDiagnosticOptions (result, globalRuleSet); + } + + var ruleSet = GetRuleSet (codeAnalysisRuleSet); + if (ruleSet != null) { + AddSpecificDiagnosticOptions (result, ruleSet); } + + foreach (var warning in GetSuppressedWarnings ()) { + result [warning] = ReportDiagnostic.Suppress; + } + return result; } + static RuleSet GetRuleSet (FilePath ruleSetFileName) + { + try { + if (ruleSetFileName.IsNotNull && File.Exists (ruleSetFileName)) { + return RuleSet.LoadEffectiveRuleSetFromFile (ruleSetFileName); + } + } catch (Exception ex) { + LoggingService.LogError (string.Format ("Unable to load ruleset from file: {0}", ruleSetFileName), ex); + } + return null; + } + + static void AddSpecificDiagnosticOptions (Dictionary<string, ReportDiagnostic> result, RuleSet ruleSet) + { + foreach (var kv in ruleSet.SpecificDiagnosticOptions) { + result [kv.Key] = kv.Value; + } + } + Microsoft.CodeAnalysis.Platform GetPlatform () { Microsoft.CodeAnalysis.Platform platform; |