Example #1
0
        public static void WriteUsedAnalyzers(
            ImmutableArray <DiagnosticAnalyzer> analyzers,
            Project project,
            CodeAnalysisOptions options,
            ConsoleColor color,
            Verbosity verbosity)
        {
            if (!analyzers.Any())
            {
                return;
            }

            if (!ShouldWrite(verbosity))
            {
                return;
            }

            foreach (IGrouping <DiagnosticDescriptor, (DiagnosticDescriptor descriptor, string severity)> grouping in analyzers
                     .SelectMany(f => f.SupportedDiagnostics)
                     .Distinct(DiagnosticDescriptorComparer.Id)
                     .Select(f => (descriptor: f, reportDiagnostic: options.GetEffectiveSeverity(f, project.CompilationOptions)))
                     .Where(f => f.reportDiagnostic != ReportDiagnostic.Suppress)
                     .Select(f => (f.descriptor, severity: f.reportDiagnostic.ToDiagnosticSeverity().ToString()))
                     .OrderBy(f => f.descriptor.Id)
                     .GroupBy(f => f.descriptor, DiagnosticDescriptorComparer.IdPrefix))
            {
                int    count  = grouping.Count();
                string prefix = DiagnosticIdPrefix.GetPrefix(grouping.Key.Id);

                Write($"  {count} supported {((count == 1) ? "diagnostic" : "diagnostics")} with prefix '{prefix}'", color, verbosity);

                using (IEnumerator <(DiagnosticDescriptor descriptor, string severity)> en = grouping.GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        Write(" (", color, verbosity);

                        while (true)
                        {
                            Write(en.Current.descriptor.Id, color, verbosity);
                            Write(" ", color, verbosity);
                            Write(en.Current.severity, color, verbosity);

                            if (en.MoveNext())
                            {
                                Write(", ", color, verbosity);
                            }
                            else
                            {
                                break;
                            }
                        }

                        Write(")", color, verbosity);
                    }
                }

                WriteLine("", color, verbosity);
            }
        }
            public override int GetHashCode(string obj)
            {
                if (obj == null)
                {
                    throw new ArgumentNullException(nameof(obj));
                }

                int length = DiagnosticIdPrefix.GetPrefixLength(obj);

                return(StringComparer.Ordinal.GetHashCode(obj.Substring(0, length)));
            }
Example #3
0
        public static void WriteUsedFixers(
            ImmutableArray <CodeFixProvider> fixers,
            CodeAnalysisOptions options,
            ConsoleColor color,
            Verbosity verbosity)
        {
            if (!ShouldWrite(verbosity))
            {
                return;
            }

            foreach (IGrouping <string, string> grouping in fixers
                     .SelectMany(f => f.FixableDiagnosticIds)
                     .Distinct()
                     .Where(f => options.IsSupportedDiagnosticId(f))
                     .GroupBy(f => f, DiagnosticIdComparer.Prefix)
                     .OrderBy(f => f.Key, DiagnosticIdComparer.Prefix))
            {
                int    count  = grouping.Count();
                string prefix = DiagnosticIdPrefix.GetPrefix(grouping.Key);

                Write($"  {count} fixable {((count == 1) ? "diagnostic" : "diagnostics")} with ", color, verbosity);
                Write((string.IsNullOrEmpty(prefix)) ? "no prefix" : $"prefix '{prefix}'", color, verbosity);

                using (IEnumerator <string> en = grouping
                                                 .OrderBy(f => f)
                                                 .GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        Write(" (", color, verbosity);

                        while (true)
                        {
                            Write(en.Current, color, verbosity);

                            if (en.MoveNext())
                            {
                                Write(", ", color, verbosity);
                            }
                            else
                            {
                                break;
                            }
                        }

                        Write(")", color, verbosity);
                    }
                }

                WriteLine("", color, verbosity);
            }
        }
Example #4
0
        public static void WriteUsedFixers(ImmutableArray <CodeFixProvider> fixers, ConsoleColor color, Verbosity verbosity)
        {
            if (!ShouldWrite(verbosity))
            {
                return;
            }

            WriteLine($"  Use {fixers.Length} {((fixers.Length == 1) ? "fixer" : "fixers")}", color, verbosity);

            foreach ((string prefix, int count) in DiagnosticIdPrefix.CountPrefixes(fixers.SelectMany(f => f.FixableDiagnosticIds)))
            {
                WriteLine($"    {count} fixable {((count == 1) ? "diagnostic" : "diagnostics")} with prefix '{prefix}'", color, verbosity);
            }
        }
Example #5
0
        public static void WriteUsedAnalyzers(ImmutableArray <DiagnosticAnalyzer> analyzers, ConsoleColor color, Verbosity verbosity)
        {
            if (ShouldWrite(verbosity))
            {
                WriteLine($"  Use {analyzers.Length} {((analyzers.Length == 1) ? "analyzer" : "analyzers")}", color, verbosity);

                if (ShouldWrite(verbosity))
                {
                    foreach ((string prefix, int count) in DiagnosticIdPrefix.CountPrefixes(analyzers.SelectMany(f => f.SupportedDiagnostics).Select(f => f.Id)))
                    {
                        WriteLine($"    {count} supported {((count == 1) ? "diagnostic" : "diagnostics")} with prefix '{prefix}'", color, verbosity);
                    }
                }
            }
        }
            public override bool Equals(string x, string y)
            {
                if (object.ReferenceEquals(x, y))
                {
                    return(true);
                }

                if (x == null)
                {
                    return(false);
                }

                if (y == null)
                {
                    return(false);
                }

                int length1 = DiagnosticIdPrefix.GetPrefixLength(x);
                int length2 = DiagnosticIdPrefix.GetPrefixLength(y);

                return(length1 == length2 &&
                       string.Compare(x, 0, y, 0, length1, StringComparison.Ordinal) == 0);
            }
            public override int Compare(string x, string y)
            {
                if (object.ReferenceEquals(x, y))
                {
                    return(0);
                }

                if (x == null)
                {
                    return(-1);
                }

                if (y == null)
                {
                    return(1);
                }

                int length1 = DiagnosticIdPrefix.GetPrefixLength(x);
                int length2 = DiagnosticIdPrefix.GetPrefixLength(y);

                if (length1 == length2)
                {
                    return(string.Compare(x, 0, y, 0, length1, StringComparison.Ordinal));
                }

                int length = Math.Min(length1, length2);

                int result = string.Compare(x, 0, y, 0, length, StringComparison.Ordinal);

                if (result != 0)
                {
                    return(result);
                }

                return(length1.CompareTo(length2));
            }
Example #8
0
        public static void WriteUsedAnalyzers(
            ImmutableArray <DiagnosticAnalyzer> analyzers,
            Func <DiagnosticDescriptor, bool> predicate,
            CodeAnalysisOptions options,
            ConsoleColor color,
            Verbosity verbosity)
        {
            if (!analyzers.Any())
            {
                return;
            }

            if (!ShouldWrite(verbosity))
            {
                return;
            }

            IEnumerable <DiagnosticDescriptor> descriptors = analyzers
                                                             .SelectMany(f => f.SupportedDiagnostics)
                                                             .Distinct(DiagnosticDescriptorComparer.Id)
                                                             .Where(f => options.IsSupportedDiagnosticId(f.Id));

            if (predicate != null)
            {
                descriptors = descriptors.Where(predicate);
            }

            foreach (IGrouping <DiagnosticDescriptor, DiagnosticDescriptor> grouping in descriptors
                     .OrderBy(f => f.Id)
                     .GroupBy(f => f, DiagnosticDescriptorComparer.IdPrefix))
            {
                int    count  = grouping.Count();
                string prefix = DiagnosticIdPrefix.GetPrefix(grouping.Key.Id);

                Write($"  {count} supported {((count == 1) ? "diagnostic" : "diagnostics")} with prefix '{prefix}'", color, verbosity);

                using (IEnumerator <DiagnosticDescriptor> en = grouping.GetEnumerator())
                {
                    if (en.MoveNext())
                    {
                        Write(" (", color, verbosity);

                        while (true)
                        {
                            Write(en.Current.Id, color, verbosity);

                            if (en.MoveNext())
                            {
                                Write(", ", color, verbosity);
                            }
                            else
                            {
                                break;
                            }
                        }

                        Write(")", color, verbosity);
                    }
                }

                WriteLine("", color, verbosity);
            }
        }