/// <summary> /// Remove the default values that we don't actually need /// </summary> public void RemoveDefaultValues() { const FieldStorage defaultStorage = FieldStorage.No; foreach (var toRemove in Stores.Where(x => x.Value == defaultStorage).ToArray()) { Stores.Remove(toRemove); } foreach (var toRemove in Indexes.Where(x => x.Value == FieldIndexing.Default).ToArray()) { Indexes.Remove(toRemove); } foreach (var toRemove in SortOptions.Where(x => x.Value == Indexing.SortOptions.None).ToArray()) { SortOptions.Remove(toRemove); } foreach (var toRemove in Analyzers.Where(x => string.IsNullOrEmpty(x.Value)).ToArray()) { Analyzers.Remove(toRemove); } foreach (var toRemove in TermVectors.Where(x => x.Value == FieldTermVector.No).ToArray()) { TermVectors.Remove(toRemove); } }
/// <summary> /// Remove the default values that we don't actually need /// </summary> public void RemoveDefaultValues() { var defaultStorage = IsMapReduce ? FieldStorage.Yes : FieldStorage.No; foreach (var toRemove in Stores.Where(x => x.Value == defaultStorage).ToArray()) { Stores.Remove(toRemove); } foreach (var toRemove in Indexes.Where(x => x.Value == FieldIndexing.Default).ToArray()) { Indexes.Remove(toRemove); } foreach (var toRemove in SortOptions.Where(x => x.Value == Indexing.SortOptions.None).ToArray()) { SortOptions.Remove(toRemove); } foreach (var toRemove in Analyzers.Where(x => string.IsNullOrEmpty(x.Value)).ToArray()) { Analyzers.Remove(toRemove); } foreach (var toRemove in Suggestions.Where(x => x.Value.Distance == StringDistanceTypes.None).ToArray()) { Suggestions.Remove(toRemove); } foreach (var toRemove in TermVectors.Where(x => x.Value == FieldTermVector.No).ToArray()) { TermVectors.Remove(toRemove); } }
public void Generate() { WriteAllText( @"Analyzers\README.md", MarkdownGenerator.CreateAnalyzersReadMe(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"Analyzers\AnalyzersByCategory.md", MarkdownGenerator.CreateAnalyzersByCategoryMarkDown(Analyzers.Where(f => !f.IsObsolete), Comparer)); foreach (AnalyzerDescriptor analyzer in Analyzers) { WriteAllText( $@"..\docs\analyzers\{analyzer.Id}.md", MarkdownGenerator.CreateAnalyzerMarkDown(analyzer), fileMustExists: false); } WriteAllText( @"..\docs\refactorings\Refactorings.md", MarkdownGenerator.CreateRefactoringsMarkDown(Refactorings, Comparer)); WriteAllText( @"Refactorings\README.md", MarkdownGenerator.CreateRefactoringsReadMe(Refactorings, Comparer)); foreach (RefactoringDescriptor refactoring in Refactorings) { WriteAllText( $@"..\docs\refactorings\{refactoring.Id}.md", MarkdownGenerator.CreateRefactoringMarkDown(refactoring), fileMustExists: false); } WriteAllText( @"CodeFixes\README.md", MarkdownGenerator.CreateCodeFixesReadMe(CodeFixes, CompilerDiagnostics, Comparer)); WriteAllText( @"CodeFixes\CodeFixesByDiagnosticId.md", MarkdownGenerator.CreateCodeFixesByDiagnosticId(CodeFixes, CompilerDiagnostics)); WriteAllText( @"..\README.md", File.ReadAllText(@"..\text\ReadMe.txt", Encoding.UTF8)); WriteAllText( "DefaultConfigFile.xml", XmlGenerator.CreateDefaultConfigFile(Refactorings, CodeFixes)); WriteAllText( @"VisualStudio\description.txt", File.ReadAllText(@"..\text\RoslynatorDescription.txt", Encoding.UTF8)); WriteAllText( @"VisualStudio.Refactorings\description.txt", File.ReadAllText(@"..\text\RoslynatorRefactoringsDescription.txt", Encoding.UTF8)); }
public void Generate() { WriteAllText( @"Analyzers\README.md", MarkdownGenerator.CreateAnalyzersReadMe(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"Analyzers\AnalyzersByCategory.md", MarkdownGenerator.CreateAnalyzersByCategoryMarkdown(Analyzers.Where(f => !f.IsObsolete), Comparer)); foreach (AnalyzerDescriptor analyzer in Analyzers) { WriteAllText( $@"..\docs\analyzers\{analyzer.Id}.md", MarkdownGenerator.CreateAnalyzerMarkdown(analyzer), fileMustExists: false); } WriteAllText( @"..\docs\refactorings\Refactorings.md", MarkdownGenerator.CreateRefactoringsMarkdown(Refactorings, Comparer)); WriteAllText( @"Refactorings\README.md", MarkdownGenerator.CreateRefactoringsReadMe(Refactorings.Where(f => !f.IsObsolete), Comparer)); foreach (RefactoringDescriptor refactoring in Refactorings) { WriteAllText( $@"..\docs\refactorings\{refactoring.Id}.md", MarkdownGenerator.CreateRefactoringMarkdown(refactoring), fileMustExists: false); } WriteAllText( @"CodeFixes\README.md", MarkdownGenerator.CreateCodeFixesReadMe(CompilerDiagnostics, Comparer)); foreach (CompilerDiagnosticDescriptor diagnostic in CompilerDiagnostics) { WriteAllText( $@"..\docs\cs\{diagnostic.Id}.md", MarkdownGenerator.CreateCompilerDiagnosticMarkdown(diagnostic, CodeFixes, Comparer), fileMustExists: false); } WriteAllText( "DefaultConfigFile.xml", XmlGenerator.CreateDefaultConfigFile(Refactorings, CodeFixes)); WriteAllText( "DefaultRuleSet.ruleset", XmlGenerator.CreateDefaultRuleSet(Analyzers)); }
private void AnalyzeNode(SyntaxNodeAnalysisContext context, SyntaxKind kind) { var analyzersForKind = Analyzers.Where(p => ((ISyntaxNodeAnalyzer)p).Kind == kind); foreach (ISyntaxNodeAnalyzer syntaxNodeAnalyzer in analyzersForKind) { var diagnosticInfo = syntaxNodeAnalyzer.GetDiagnosticInfo(context); foreach (var info in diagnosticInfo) { var supportedDiagnostic = GetSupportedDiagnosticAttribute(syntaxNodeAnalyzer); var diagnostic = DiagnosticFactory.Create(supportedDiagnostic.GetDescriptor(), info); context.ReportDiagnostic(diagnostic); } } }
private static string CreateStub(DiagnosticDescriptor descriptor) { var stub = $@"# {descriptor.Id} ## {descriptor.Title.ToString(CultureInfo.InvariantCulture)} | Topic | Value | :-- | :-- | Id | {descriptor.Id} | Severity | {descriptor.DefaultSeverity} | Enabled | {(descriptor.IsEnabledByDefault ? "True" : "False")} | Category | {descriptor.Category} | Code | [<TYPENAME>](<URL>) ## Description {descriptor.Description.ToString(CultureInfo.InvariantCulture)} ## Motivation ADD MOTIVATION HERE ## How to fix violations ADD HOW TO FIX VIOLATIONS HERE <!-- start generated config severity --> ## Configure severity ### Via ruleset file. Configure the severity per project, for more info see [MSDN](https://msdn.microsoft.com/en-us/library/dd264949.aspx). ### Via #pragma directive. ```C# #pragma warning disable {descriptor.Id} // {descriptor.Title.ToString(CultureInfo.InvariantCulture)} Code violating the rule here #pragma warning restore {descriptor.Id} // {descriptor.Title.ToString(CultureInfo.InvariantCulture)} ``` Or put this at the top of the file to disable all instances. ```C# #pragma warning disable {descriptor.Id} // {descriptor.Title.ToString(CultureInfo.InvariantCulture)} ``` ### Via attribute `[SuppressMessage]`. ```C# [System.Diagnostics.CodeAnalysis.SuppressMessage(""{descriptor.Category}"", ""{descriptor.Id}:{descriptor.Title.ToString(CultureInfo.InvariantCulture)}"", Justification = ""Reason..."")] ``` <!-- end generated config severity -->"; var builder = StringBuilderPool.Borrow(); foreach (var analyzer in Analyzers.Where(x => x.SupportedDiagnostics.Any(d => d.Id == descriptor.Id))) { _ = builder.Append($"|{(builder.Length == 0 ? " Code " : " ")}| ") .AppendLine($"[{analyzer.GetType().Name}]({CodeFile.Find(analyzer.GetType()).Uri})"); } var text = builder.Return(); return(stub.Replace("| Code | [<TYPENAME>](<URL>)\r\n", text, StringComparison.Ordinal) .Replace("| Code | [<TYPENAME>](<URL>)\n", text, StringComparison.Ordinal)); }
public void Generate() { WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Generated.cs", RefactoringIdentifiersGenerator.Generate(Refactorings, obsolete: false, comparer: Comparer)); WriteCompilationUnit( @"Refactorings\CSharp\RefactoringIdentifiers.Deprecated.Generated.cs", RefactoringIdentifiersGenerator.Generate(Refactorings, obsolete: true, comparer: Comparer)); WriteCompilationUnit( @"VisualStudio.Common\RefactoringsOptionsPage.Generated.cs", RefactoringsOptionsPageGenerator.Generate(Refactorings.Where(f => !f.IsObsolete), Comparer)); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticDescriptors.Generated.cs", DiagnosticDescriptorsGenerator.Generate(Analyzers, obsolete: false, comparer: Comparer), normalizeWhitespace: false); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticDescriptors.Deprecated.Generated.cs", DiagnosticDescriptorsGenerator.Generate(Analyzers, obsolete: true, comparer: Comparer), normalizeWhitespace: false); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticIdentifiers.Generated.cs", DiagnosticIdentifiersGenerator.Generate(Analyzers, obsolete: false, comparer: Comparer)); WriteCompilationUnit( @"Analyzers\CSharp\DiagnosticIdentifiers.Deprecated.Generated.cs", DiagnosticIdentifiersGenerator.Generate(Analyzers, obsolete: true, comparer: Comparer)); WriteCompilationUnit( @"CodeFixes\CSharp\CodeFixIdentifiers.Generated.cs", CodeFixIdentifiersGenerator.Generate(CodeFixes, Comparer)); WriteCompilationUnit( @"VisualStudio.Common\CodeFixesOptionsPage.Generated.cs", CodeFixesOptionsPageGenerator.Generate(CodeFixes, Comparer)); WriteCompilationUnit( @"VisualStudio.Common\GlobalSuppressionsOptionsPage.Generated.cs", GlobalSuppressionsOptionsPageGenerator.Generate(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteCompilationUnit( @"CSharp\CSharp\CompilerDiagnosticIdentifiers.Generated.cs", CompilerDiagnosticIdentifiersGenerator.Generate(CompilerDiagnostics, Comparer)); WriteCompilationUnit( @"Tools\CodeGeneration\CSharp\Symbols.Generated.cs", SymbolsGetKindsGenerator.Generate()); WriteCompilationUnit( @"CSharp\CSharp\SyntaxWalkers\CSharpSyntaxNodeWalker.cs", CSharpSyntaxNodeWalkerGenerator.Generate()); foreach (AnalyzerDescriptor analyzer in Analyzers.Where(f => f.IsDevelopment)) { string className = $"{analyzer.Id}{analyzer.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Analyzers.Tests\{className}.cs", AnalyzerTestGenerator.Generate(analyzer, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } foreach (RefactoringDescriptor refactoring in Refactorings.Where(f => f.IsDevelopment)) { string className = $"{refactoring.Id}{refactoring.Identifier}Tests"; WriteCompilationUnit( $@"Tests\Refactorings.Tests\{className}.cs", RefactoringTestGenerator.Generate(refactoring, className), autoGenerated: false, normalizeWhitespace: false, fileMustExist: false, overwrite: false); } }
public async Task GenerateAsync() { WriteAllText( @"Analyzers\README.md", MarkdownGenerator.CreateAnalyzersReadMe(Analyzers.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"Analyzers\AnalyzersByCategory.md", MarkdownGenerator.CreateAnalyzersByCategoryMarkdown(Analyzers.Where(f => !f.IsObsolete), Comparer)); VisualStudioInstance instance = MSBuildLocator.QueryVisualStudioInstances().Single(); MSBuildLocator.RegisterInstance(instance); using (MSBuildWorkspace workspace = MSBuildWorkspace.Create()) { workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message); string solutionPath = Path.Combine(RootPath, "Roslynator.sln"); Console.WriteLine($"Loading solution '{solutionPath}'"); Solution solution = await workspace.OpenSolutionAsync(solutionPath).ConfigureAwait(false); Console.WriteLine($"Finished loading solution '{solutionPath}'"); RoslynatorInfo roslynatorInfo = await RoslynatorInfo.Create(solution).ConfigureAwait(false); IOrderedEnumerable <SourceFile> sourceFiles = Analyzers .Select(f => new SourceFile(f.Id, roslynatorInfo.GetAnalyzerFilesAsync(f.Identifier).Result)) .Concat(Refactorings .Select(f => new SourceFile(f.Id, roslynatorInfo.GetRefactoringFilesAsync(f.Identifier).Result))) .OrderBy(f => f.Id); MetadataFile.SaveSourceFiles(sourceFiles, @"..\SourceFiles.xml"); foreach (AnalyzerDescriptor analyzer in Analyzers) { //IEnumerable<string> filePaths = await roslynatorInfo.GetAnalyzerFilesAsync(analyzer.Identifier).ConfigureAwait(false); WriteAllText( $@"..\docs\analyzers\{analyzer.Id}.md", MarkdownGenerator.CreateAnalyzerMarkdown(analyzer, Array.Empty <string>()), fileMustExists: false); } foreach (RefactoringDescriptor refactoring in Refactorings) { //IEnumerable<string> filePaths = await roslynatorInfo.GetRefactoringFilesAsync(refactoring.Identifier).ConfigureAwait(false); WriteAllText( $@"..\docs\refactorings\{refactoring.Id}.md", MarkdownGenerator.CreateRefactoringMarkdown(refactoring, Array.Empty <string>()), fileMustExists: false); } foreach (CompilerDiagnosticDescriptor diagnostic in CompilerDiagnostics) { //IEnumerable<string> filePaths = await roslynatorInfo.GetCompilerDiagnosticFilesAsync(diagnostic.Identifier).ConfigureAwait(false); WriteAllText( $@"..\docs\cs\{diagnostic.Id}.md", MarkdownGenerator.CreateCompilerDiagnosticMarkdown(diagnostic, CodeFixes, Comparer, Array.Empty <string>()), fileMustExists: false); } } WriteAllText( @"..\docs\refactorings\Refactorings.md", MarkdownGenerator.CreateRefactoringsMarkdown(Refactorings, Comparer)); WriteAllText( @"Refactorings\README.md", MarkdownGenerator.CreateRefactoringsReadMe(Refactorings.Where(f => !f.IsObsolete), Comparer)); WriteAllText( @"CodeFixes\README.md", MarkdownGenerator.CreateCodeFixesReadMe(CompilerDiagnostics, Comparer)); WriteAllText( "DefaultConfigFile.xml", XmlGenerator.CreateDefaultConfigFile(Refactorings, CodeFixes)); WriteAllText( "DefaultRuleSet.ruleset", XmlGenerator.CreateDefaultRuleSet(Analyzers)); }