public static RuleDescription Convert(RuleDetail detail, string productVersion)
 {
     return new RuleDescription
     {
         Key = detail.Key,
         Title = detail.Title,
         Description = AddLinksBetweenRulesToDescription(detail.Description, productVersion),
         Tags = string.Join(", ", detail.Tags)
     };
 }
 public static RuleDescription Convert(RuleDetail detail, string productVersion)
 {
     return new RuleDescription
     {
         Key = detail.Key,
         Title = detail.Title,
         Description = AddLinksBetweenRulesToDescription(detail.Description, productVersion) +
             GetCodeFixDescription(detail),
         Tags = detail.Tags,
         Severity = detail.Severity,
         IdeSeverity = detail.IdeSeverity
     };
 }
        private static string GetCodeFixDescription(RuleDetail detail)
        {
            if (!detail.CodeFixTitles.Any())
            {
                return string.Empty;
            }

            const string listItemPattern = "<li>{0}</li>";
            const string codeFixPattern = "<h2>Code Fixes</h2><ul>{0}</ul>";

            return
                string.Format(codeFixPattern,
                    string.Join("", detail.CodeFixTitles.Select(title => string.Format(listItemPattern, title))));
        }
        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;
        }
        private static void GetSqale(Type analyzerType, RuleDetail ruleDetail)
        {
            var sqaleRemediation = analyzerType.GetCustomAttributes<SqaleRemediationAttribute>().FirstOrDefault();

            if (sqaleRemediation == null || sqaleRemediation is NoSqaleRemediationAttribute)
            {
                ruleDetail.SqaleDescriptor = null;
                return;
            }

            var sqaleSubCharacteristic = analyzerType.GetCustomAttributes<SqaleSubCharacteristicAttribute>().First();
            var sqaleDescriptor = new SqaleDescriptor
            {
                SubCharacteristic = sqaleSubCharacteristic.SubCharacteristic.ToSonarQubeString()
            };
            var constantRemediation = sqaleRemediation as SqaleConstantRemediationAttribute;
            if (constantRemediation == null)
            {
                ruleDetail.SqaleDescriptor = sqaleDescriptor;
                return;
            }

            sqaleDescriptor.Remediation.Properties.AddRange(new[]
            {
                new SqaleRemediationProperty
                {
                    Key = SqaleRemediationProperty.RemediationFunctionKey,
                    Text = SqaleRemediationProperty.ConstantRemediationFunctionValue
                },
                new SqaleRemediationProperty
                {
                    Key = SqaleRemediationProperty.OffsetKey,
                    Value = constantRemediation.Value,
                    Text = string.Empty
                }
            });

            ruleDetail.SqaleDescriptor = sqaleDescriptor;
        }
        private static void GetParameters(Type analyzerType, RuleDetail ruleDetail)
        {
            var typeToGetParametersFrom = analyzerType;
            var templateInterface = analyzerType.GetInterfaces()
                .FirstOrDefault(type => type.IsGenericType &&
                                        type.GetGenericTypeDefinition() == typeof (IRuleTemplate<>));

            if (templateInterface != null)
            {
                typeToGetParametersFrom = templateInterface.GetGenericArguments().First();
            }

            var parameters = typeToGetParametersFrom.GetProperties()
                .Select(p => p.GetCustomAttributes<RuleParameterAttribute>().SingleOrDefault());

            foreach (var ruleParameter in parameters
                .Where(attribute => attribute != null))
            {
                ruleDetail.Parameters.Add(
                    new RuleParameter
                    {
                        DefaultValue = ruleParameter.DefaultValue,
                        Description = ruleParameter.Description,
                        Key = ruleParameter.Key,
                        Type = ruleParameter.Type.ToSonarQubeString()
                    });
            }
        }
 private static void GetTags(Type analyzerType, RuleDetail ruleDetail)
 {
     var tags = analyzerType.GetCustomAttributes<TagsAttribute>().FirstOrDefault();
     if (tags != null)
     {
         ruleDetail.Tags.AddRange(tags.Tags);
     }
 }
        private static void GetCodeFixNames(Type analyzerType, RuleDetail ruleDetail)
        {
            var codeFixProvider = GetCodeFixProviderType(analyzerType);
            if (codeFixProvider == null)
            {
                return;
            }

            var titles = GetCodeFixTitles(codeFixProvider);

            ruleDetail.CodeFixTitles.AddRange(titles);
        }