public static IEnumerable <DiagnosticAnalyzer> GetNonTemplateAnalyzers(AnalyzerLanguage language) { return (new RuleFinder().GetAnalyzerTypes(language) .Where(type => !RuleFinder.IsRuleTemplate(type)) .Select(type => (DiagnosticAnalyzer)Activator.CreateInstance(type))); }
private void AddMissingEntries(AnalysisOutput output, AnalyzerLanguage language) { var foundKeys = output.Issues.Select(i => i.RuleId).ToList(); var notFoundKeys = RuleFinder.GetAnalyzerTypes(language) .Select(t => new { Type = t, RuleAttribute = t.GetCustomAttribute <RuleAttribute>() }) .Select(rule => RuleFinder.IsRuleTemplate(rule.Type) ? string.Format(TemplateRuleIdPattern, rule.RuleAttribute.Key) : rule.RuleAttribute.Key) .Where(s => !foundKeys.Contains(s)); foreach (var notFoundKey in notFoundKeys) { output.Issues.Add(new Issue { RuleId = notFoundKey }); } }
public void VisualStudio_AllParameterlessRulesNotRuleTemplate() { var analyzers = GetDiagnosticAnalyzerTypes(new[] { RuleFinder.GetExtraRuleAssembly() }); foreach (var analyzer in analyzers.Where(type => !RuleFinder.IsRuleTemplate(type))) { var hasParameter = analyzer.GetProperties().Any(p => p.GetCustomAttributes <RuleParameterAttribute>().Any()); if (!hasParameter) { Assert.Fail( "DiagnosticAnalyzer '{0}' should be moved to the assembly that implements Visual Studio rules.", analyzer.Name); } } }
public void IsRuleTemplate() { Assert.IsTrue(RuleFinder.IsRuleTemplate(typeof(CommentRegularExpression))); Assert.IsFalse(RuleFinder.IsRuleTemplate(typeof(AsyncAwaitIdentifier))); }