public MainForm() { InitializeComponent(); AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; styleCopAnalyzerAssembly = AssembliesHelper.GetAnalyzersAssembly(); styleCopFixersAssembly = AssembliesHelper.GetCodeFixAssembly(); SeedCheckList(); var autoCompleteSource = new AutoCompleteStringCollection(); autoCompleteSource.AddRange(analyzers.SelectMany(x => x.SupportedDiagnostics).Select(x => $"{x.Id}: {x.Title}") .ToArray()); autoCompleteTextBox.AutoCompleteSource = AutoCompleteSource.CustomSource; autoCompleteTextBox.AutoCompleteCustomSource = autoCompleteSource; autoCompleteTextBox.TextChanged += AutoCompleteTextBox_TextChanged; Text += $" {ApplicationVersionUtility.GetVersion()}"; DoubleBuffered = true; }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.LiterateConsole() .CreateLogger(); if (args.Length == 0) { Console.WriteLine(Args.Usage); return; } try { AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve; var options = new Args(args); if (options.ShowVersion) { Log.Information($"Saritasa Prettify - {GetVersionOfExecutionAssembly()}"); } var styleCopAnalyzerAssembly = AssembliesHelper.GetAnalyzersAssembly(); var styleCopFixersAssembly = AssembliesHelper.GetCodeFixAssembly(); var analyzers = DiagnosticHelper.GetAnalyzersFromAssemblies(new[] { styleCopAnalyzerAssembly, styleCopFixersAssembly }); var codeFixes = CodeFixProviderHelper.GetFixProviders(new[] { styleCopAnalyzerAssembly, styleCopFixersAssembly }) .Where(x => options.Rules == null || options.Rules.Contains(x.Key)) .ToList(); var workspace = MSBuildWorkspace.Create(); var solution = workspace.OpenSolutionAsync(options.SolutionPath).Result; foreach (var solutionProject in solution.Projects) { var diagnostics = ProjectHelper.GetProjectAnalyzerDiagnosticsAsync(analyzers, solutionProject, true).Result .Where(x => options.Rules == null || options.Rules.Contains(x.Id)) .ToList(); Log.Information("<======= Project: {project} =======>", solutionProject.Name); if (!diagnostics.Any()) { Log.Information("Can't find any diagnostic issues for {@rules}", options.Rules); continue; } foreach (var projectAnalyzer in diagnostics) { Log.Information("DiagnosticId {@id} - {message} in file {path}({row},{column})", projectAnalyzer.Id, projectAnalyzer.GetMessage(), GetFormattedFileName(projectAnalyzer.Location.GetLineSpan().Path), projectAnalyzer.Location.GetLineSpan().StartLinePosition.Line, projectAnalyzer.Location.GetLineSpan().StartLinePosition.Character); } if (options.Rules == null && options.Mode == Args.RunningMode.Fix) { Log.Warning("Please specify rules for fix"); break; } if (options.Mode == Args.RunningMode.Fix) { var diagnistics = DiagnosticHelper.GetAnalyzerDiagnosticsAsync(solution, analyzers, true).Result; foreach (var keyValuePair in codeFixes) { var equivalenceGroups = new List <CodeFixEquivalenceGroup>(); keyValuePair.Value.ForEach(x => { equivalenceGroups.AddRange(CodeFixEquivalenceGroup.CreateAsync(x, diagnistics, solution).Result); }); if (!equivalenceGroups.Any()) { continue; } var fix = equivalenceGroups[0]; if (equivalenceGroups.Count() > 1) { Log.Warning("Allowed only one equivalence group for fix"); continue; } var operations = fix.GetOperationsAsync().Result; if (operations.Length == 0) { Log.Information("No changes was found for this fixer"); } else { operations[0].Apply(workspace, default(CancellationToken)); Log.Information("Fixer with DiagnosticId {@id} was applied ", keyValuePair.Key); } } } } } catch (Exception ex) { Log.Fatal(ex, string.Empty); } }