public static string GenerateRuleJson(string productVersion) { var csImplementations = RuleDetailBuilder.GetAllRuleDetails(AnalyzerLanguage.CSharp) .Select(ruleDetail => RuleImplementationMeta.Convert(ruleDetail, productVersion, AnalyzerLanguage.CSharp)) .ToList(); var vbImplementations = RuleDetailBuilder.GetAllRuleDetails(AnalyzerLanguage.VisualBasic) .Select(ruleDetail => RuleImplementationMeta.Convert(ruleDetail, productVersion, AnalyzerLanguage.VisualBasic)) .ToList(); var sonarLintDescriptor = new SonarLintDescriptor { Version = productVersion, Rules = new List<RuleMeta>() }; foreach (var csImplementation in csImplementations) { var rule = new RuleMeta { Id = csImplementation.Id, Title = csImplementation.Title, Implementations = new List<RuleImplementationMeta>(new[] { csImplementation }) }; sonarLintDescriptor.Rules.Add(rule); } foreach (var vbImplementation in vbImplementations) { var rule = sonarLintDescriptor.Rules.FirstOrDefault(r => r.Implementations.First().Id == vbImplementation.Id); if (rule == null) { rule = new RuleMeta { Id = vbImplementation.Id, Title = vbImplementation.Title, Implementations = new List<RuleImplementationMeta>(new[] { vbImplementation }) }; sonarLintDescriptor.Rules.Add(rule); } else { rule.Implementations.Add(vbImplementation); } } foreach (var rule in sonarLintDescriptor.Rules) { rule.Tags = rule.Implementations.SelectMany(i => i.Tags).Distinct(); } return JsonConvert.SerializeObject(sonarLintDescriptor, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented }); }
public static string GenerateRuleJson(string productVersion) { var csImplementations = RuleDetailBuilder.GetAllRuleDetails(AnalyzerLanguage.CSharp) .Select(ruleDetail => RuleImplementationMeta.Convert(ruleDetail, productVersion, AnalyzerLanguage.CSharp)) .ToList(); var vbImplementations = RuleDetailBuilder.GetAllRuleDetails(AnalyzerLanguage.VisualBasic) .Select(ruleDetail => RuleImplementationMeta.Convert(ruleDetail, productVersion, AnalyzerLanguage.VisualBasic)) .ToList(); var sonarLintDescriptor = new SonarLintDescriptor { Version = productVersion, Rules = new List <RuleMeta>() }; foreach (var csImplementation in csImplementations) { var rule = new RuleMeta { Id = csImplementation.Id, Title = csImplementation.Title, Implementations = new List <RuleImplementationMeta>(new[] { csImplementation }) }; sonarLintDescriptor.Rules.Add(rule); } foreach (var vbImplementation in vbImplementations) { var rule = sonarLintDescriptor.Rules.FirstOrDefault(r => r.Implementations.First().Id == vbImplementation.Id); if (rule == null) { rule = new RuleMeta { Id = vbImplementation.Id, Title = vbImplementation.Title, Implementations = new List <RuleImplementationMeta>(new[] { vbImplementation }) }; sonarLintDescriptor.Rules.Add(rule); } else { rule.Implementations.Add(vbImplementation); } } foreach (var rule in sonarLintDescriptor.Rules) { rule.Tags = rule.Implementations.SelectMany(i => i.Tags).Distinct(); } return(JsonConvert.SerializeObject(sonarLintDescriptor, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented })); }