public void CodeFixProviders_Have_Title() { foreach (var codeFixProvider in GetCodeFixProviderTypes(RuleFinder.PackagedRuleAssemblies)) { RuleDetailBuilder.GetCodeFixTitles(codeFixProvider).Should().NotBeEmpty("CodeFixProvider '{0}' has no title field.", codeFixProvider.Name); } }
private static int GetNumberOfCrossReferences() { return(RuleDetailBuilder.GetParameterlessRuleDetails() .Select(rule => rule.Description) .Select(description => Regex.Matches(description, RuleDescription.CrosslinkPattern).Count) .Sum()); }
private static int GetNumberOfCrossReferences(AnalyzerLanguage language) { return(RuleDetailBuilder.GetParameterlessRuleDetails(language) .Select(rule => rule.Description) .Select(description => Regex.Matches(description, RuleImplementationMeta.CrosslinkPattern).Count) .Sum()); }
public static string GenerateRuleJson(string productVersion) { var cs = RuleDetailBuilder.GetAllRuleDetails(AnalyzerLanguage.CSharp) .Select(ruleDetail => RuleDescription.Convert(ruleDetail, productVersion, AnalyzerLanguage.CSharp)) .ToList(); var vb = RuleDetailBuilder.GetAllRuleDetails(AnalyzerLanguage.VisualBasic) .Select(ruleDetail => RuleDescription.Convert(ruleDetail, productVersion, AnalyzerLanguage.VisualBasic)) .ToList(); foreach (var vbRuleDescription in vb) { var csEquivalent = cs.FirstOrDefault(rd => rd.Key == vbRuleDescription.Key); if (csEquivalent == null) { cs.Add(vbRuleDescription); } else { foreach (var item in vbRuleDescription.Data) { csEquivalent.Data.Add(item.Key, item.Value); } } } return(JsonConvert.SerializeObject(cs, 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 })); }
private static void WriteXmlDescriptorFiles(string rulePath, string profilePath, string sqalePath) { var genericRuleDetails = RuleDetailBuilder.GetAllRuleDetails().ToList(); var ruleDetails = genericRuleDetails.Select(RuleDetail.Convert).ToList(); var sqaleDetails = genericRuleDetails.Select(SqaleDescriptor.Convert).ToList(); WriteRuleDescriptorFile(rulePath, ruleDetails); WriteQualityProfileFile(profilePath, ruleDetails); WriteSqaleDescriptorFile(sqalePath, sqaleDetails); }
public void ThereShouldBeRuleDetailsForAllVbNetRuleClasses() { var ruleDetailsKeys = RuleDetailBuilder.GetAllRuleDetails(AnalyzerLanguage.VisualBasic) .Select(rd => rd.Key) .OrderBy(key => key); var rulesFromClasses = GetRulesFromClasses(typeof(VisualBasicSyntaxHelper).Assembly).OrderBy(key => key); ruleDetailsKeys.Should().Equal(rulesFromClasses); }
private static void WriteXmlDescriptorFiles(string rulePath, string profilePath, string lang) { var language = AnalyzerLanguage.Parse(lang); var genericRuleDetails = RuleDetailBuilder.GetAllRuleDetails(language).ToList(); var ruleDetails = genericRuleDetails.Select(RuleDetail.Convert).ToList(); Directory.CreateDirectory(lang); WriteRuleDescriptorFile(Path.Combine(lang, rulePath), ruleDetails); WriteQualityProfileFile(Path.Combine(lang, profilePath), ruleDetails, language); }
public static string GenerateRuleJson(string productVersion) { var ruleDetails = RuleDetailBuilder.GetParameterlessRuleDetails() .Select(ruleDetail => RuleDescription.Convert(ruleDetail, productVersion)) .ToList(); return(JsonConvert.SerializeObject(ruleDetails, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented })); }
public void CodeFixProviders_Have_Title() { var codeFixProviders = GetCodeFixProviderTypes(RuleFinder.PackagedRuleAssemblies); foreach (var codeFixProvider in codeFixProviders) { var titles = RuleDetailBuilder.GetCodeFixTitles(codeFixProvider); if (!titles.Any()) { Assert.Fail( "CodeFixProvider '{0}' has no title field.", codeFixProvider.Name); } } }
private static void CheckRuleDescriptorsNotEmpty(AnalyzerLanguage language) { var ruleDetails = RuleDetailBuilder.GetAllRuleDetails(language).ToList(); foreach (var ruleDetail in ruleDetails) { ruleDetail.Should().NotBeNull(); ruleDetail.Description.Should().NotBeNull(); ruleDetail.Key.Should().NotBeNull(); ruleDetail.Title.Should().NotBeNull(); } ruleDetails.Should().HaveSameCount( ruleDetails.Select(descriptor => descriptor.Key).Distinct()); }
private static void CheckRuleDescriptorsNotEmpty(AnalyzerLanguage language) { var ruleDetails = RuleDetailBuilder.GetAllRuleDetails(language).ToList(); foreach (var ruleDetail in ruleDetails) { Assert.IsNotNull(ruleDetail); Assert.IsNotNull(ruleDetail.Description); Assert.IsNotNull(ruleDetail.Key); Assert.IsNotNull(ruleDetail.Title); } Assert.AreEqual(ruleDetails.Count, ruleDetails.Select(descriptor => descriptor.Key).Distinct().Count()); }
private static void CheckRuleDescriptorsNotEmpty(AnalyzerLanguage language) { var ruleDetails = RuleDetailBuilder.GetAllRuleDetails(language).ToList(); foreach (var ruleDetail in ruleDetails) { ruleDetail.Should().NotBeNull(); ruleDetail.Type.Should().NotBeNull(); // SECURITY_HOTSPOTS are converted to VULNERABILITY to ensure compatiblity with old versions of SonarQube ruleDetail.Type.Should().BeOneOf("CODE_SMELL", "BUG", "VULNERABILITY"); ruleDetail.Description.Should().NotBeNull(); ruleDetail.Key.Should().NotBeNull(); ruleDetail.Title.Should().NotBeNull(); } ruleDetails.Should().OnlyHaveUniqueItems(); }
public void RuleDescriptors_NotEmpty() { var ruleDetails = RuleDetailBuilder.GetAllRuleDetails().ToList(); foreach (var ruleDetail in ruleDetails) { Assert.IsNotNull(ruleDetail); Assert.IsNotNull(ruleDetail.Description); Assert.IsNotNull(ruleDetail.Key); Assert.IsNotNull(ruleDetail.Title); if (!ruleDetail.IsTemplate) { Assert.IsNotNull(ruleDetail.SqaleDescriptor); Assert.IsNotNull(ruleDetail.SqaleDescriptor.Remediation); } } Assert.AreEqual(ruleDetails.Count(), ruleDetails.Select(descriptor => descriptor.Key).Distinct().Count()); }
private static void ParameterlessRuleDescriptorsCount(AnalyzerLanguage language) { RuleDetailBuilder.GetParameterlessRuleDetails(language) .Should().HaveSameCount(new RuleFinder().GetParameterlessAnalyzerTypes(language)); }
private static void CheckRuleDescriptorsCount(AnalyzerLanguage language) { RuleDetailBuilder.GetAllRuleDetails(language) .Should().HaveSameCount(new RuleFinder().GetAnalyzerTypes(language)); }
private static void ParameterlessRuleDescriptorsCount(AnalyzerLanguage language) { Assert.AreEqual( RuleDetailBuilder.GetParameterlessRuleDetails(language).Count(), new RuleFinder().GetParameterlessAnalyzerTypes(language).Count()); }
private static void CheckRuleDescriptorsCount(AnalyzerLanguage language) { Assert.AreEqual( RuleDetailBuilder.GetAllRuleDetails(language).Count(), new RuleFinder().GetAnalyzerTypes(language).Count()); }
public void GetParameterlessRuleDescriptors_Count() { Assert.AreEqual(RuleDetailBuilder.GetParameterlessRuleDetails().Count(), (new RuleFinder().GetParameterlessAnalyzerTypes().Count())); }