Exemplo n.º 1
0
        public void SqaleSubCharacteristicAttribute()
        {
            var analyzers = new RuleFinder().GetAllAnalyzerTypes();

            foreach (var analyzer in analyzers)
            {
                var noSqaleCount = analyzer.GetCustomAttributes<NoSqaleRemediationAttribute>().Count();

                var subCharacteristicCount = analyzer.GetCustomAttributes<SqaleSubCharacteristicAttribute>().Count();

                if (noSqaleCount > 0)
                {
                    if (subCharacteristicCount > 0)
                    {
                        Assert.Fail(
                            "SqaleSubCharacteristicAttribute can only be assigned to DiagnosticAnalyzers that have a SQALE " +
                            "remediation function, '{0}' has NoSqaleRemediationAttribute",
                            analyzer.Name);
                    }
                }
                else
                {
                    if (subCharacteristicCount != 1)
                    {
                        Assert.Fail(
                            "Only one SqaleSubCharacteristicAttribute can be assigned to DiagnosticAnalyzers, '{0}' has {1}",
                            analyzer.Name, subCharacteristicCount);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void SingleSqaleRemediationAttribute()
        {
            var analyzers = new RuleFinder().GetAllAnalyzerTypes();

            foreach (var analyzer in analyzers)
            {
                var count = analyzer.GetCustomAttributes<SqaleRemediationAttribute>().Count();
                if (count != 1)
                {
                    Assert.Fail("Only one SqaleRemediationAttribute can be assigned to DiagnosticAnalyzers, '{0}' has {1}",
                        analyzer.Name, count);
                }
            }
        }
Exemplo n.º 3
0
        private static RuleDetail GetRuleDetail(Type analyzerType)
        {
            var rule = analyzerType.GetCustomAttributes <RuleAttribute>().Single();

            var ruleDetail = new RuleDetail
            {
                Key                  = rule.Key,
                Title                = rule.Title,
                Severity             = rule.Severity.ToString().ToUpper(CultureInfo.InvariantCulture),
                IsActivatedByDefault = rule.IsActivatedByDefault,
                Description          = GetResourceHtml(analyzerType, rule),
                IsTemplate           = RuleFinder.IsRuleTemplate(analyzerType)
            };

            GetParameters(analyzerType, ruleDetail);
            GetTags(analyzerType, ruleDetail);
            GetSqale(analyzerType, ruleDetail);

            return(ruleDetail);
        }
Exemplo n.º 4
0
        private static RuleDetail GetRuleDetail(Type analyzerType, AnalyzerLanguage language)
        {
            var rule = analyzerType.GetCustomAttributes <RuleAttribute>().Single();

            var ruleDetail = new RuleDetail
            {
                Key                  = rule.Key,
                Title                = rule.Title,
                Severity             = rule.Severity.ToString(),
                IdeSeverity          = (int)rule.Severity.ToDiagnosticSeverity(),
                IsActivatedByDefault = rule.IsActivatedByDefault,
                Description          = GetResourceHtml(rule, language),
                IsTemplate           = RuleFinder.IsRuleTemplate(analyzerType)
            };

            GetParameters(analyzerType, ruleDetail);
            GetTags(analyzerType, ruleDetail);
            GetSqale(analyzerType, ruleDetail);
            GetCodeFixNames(analyzerType, ruleDetail);

            return(ruleDetail);
        }
Exemplo n.º 5
0
 public void GetAllAnalyzerTypes()
 {
     var finder = new RuleFinder();
     var countParameterless = finder.GetParameterlessAnalyzerTypes().Count();
     finder.GetAllAnalyzerTypes().Count().Should().BeGreaterThan(countParameterless);
 }
Exemplo n.º 6
0
 public void GetAnalyzerTypes()
 {
     var analyzers = new RuleFinder().GetAnalyzerTypes(SonarLint.Common.AnalyzerLanguage.CSharp);
     analyzers.Should().Contain(typeof(EmptyStatement));
 }