コード例 #1
0
ファイル: RuleTest.cs プロジェクト: rehen/sonar-dotnet
 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);
     }
 }
コード例 #2
0
 private static int GetNumberOfCrossReferences()
 {
     return(RuleDetailBuilder.GetParameterlessRuleDetails()
            .Select(rule => rule.Description)
            .Select(description => Regex.Matches(description, RuleDescription.CrosslinkPattern).Count)
            .Sum());
 }
コード例 #3
0
 private static int GetNumberOfCrossReferences(AnalyzerLanguage language)
 {
     return(RuleDetailBuilder.GetParameterlessRuleDetails(language)
            .Select(rule => rule.Description)
            .Select(description => Regex.Matches(description, RuleImplementationMeta.CrosslinkPattern).Count)
            .Sum());
 }
コード例 #4
0
        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
            }));
        }
コード例 #5
0
        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
            }));
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: wayneYaw/sonarlint-vs
        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
            }));
        }
コード例 #10
0
        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);
                }
            }
        }
コード例 #11
0
        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());
        }
コード例 #12
0
        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());
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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());
        }
コード例 #15
0
 private static void ParameterlessRuleDescriptorsCount(AnalyzerLanguage language)
 {
     RuleDetailBuilder.GetParameterlessRuleDetails(language)
     .Should().HaveSameCount(new RuleFinder().GetParameterlessAnalyzerTypes(language));
 }
コード例 #16
0
 private static void CheckRuleDescriptorsCount(AnalyzerLanguage language)
 {
     RuleDetailBuilder.GetAllRuleDetails(language)
     .Should().HaveSameCount(new RuleFinder().GetAnalyzerTypes(language));
 }
コード例 #17
0
 private static void ParameterlessRuleDescriptorsCount(AnalyzerLanguage language)
 {
     Assert.AreEqual(
         RuleDetailBuilder.GetParameterlessRuleDetails(language).Count(),
         new RuleFinder().GetParameterlessAnalyzerTypes(language).Count());
 }
コード例 #18
0
 private static void CheckRuleDescriptorsCount(AnalyzerLanguage language)
 {
     Assert.AreEqual(
         RuleDetailBuilder.GetAllRuleDetails(language).Count(),
         new RuleFinder().GetAnalyzerTypes(language).Count());
 }
コード例 #19
0
 public void GetParameterlessRuleDescriptors_Count()
 {
     Assert.AreEqual(RuleDetailBuilder.GetParameterlessRuleDetails().Count(),
                     (new RuleFinder().GetParameterlessAnalyzerTypes().Count()));
 }