static void Main()

in sarif_results_checker/Program.cs [33:114]


        static void Main(string[] args)
        {
            Parser.Default.ParseArguments<Options>(args)
                .WithParsed((options) =>
                {
                    // Print the options that we're running with
                    Console.WriteLine($"Running with options:");
                    Console.WriteLine($"  SarifPath: {options.SarifPath}");
                    Console.WriteLine($"  IgnorePaths: {options.IgnorePaths}");

                    // Enumerate all files in the folder
                    IEnumerable<string> files = Directory.EnumerateFiles(options.SarifPath, "*.sarif", SearchOption.AllDirectories);
                    bool errorsDetected = false;

                    // create an array with paths to be ignored
                    string[] pathsToIgnore = options.IgnorePaths.Split(';');

                    foreach (string file in files)
                    {
                        Console.WriteLine($"Looking at file {file}");
                        SarifLog log = SarifLog.Load(file);

                        // check and print errors
                        foreach (Result result in log.Runs[0].Results)
                        {
                            if ((result.Level == FailureLevel.Error) ||
                                (result.Level == FailureLevel.Warning))
                            {
                                // check if there are any suppressions for this error
                                bool isSuppressed = false;

                                if (!result.TryIsSuppressed(out isSuppressed))
                                {
                                    // could not get suppression status, assuming not suppressed
                                }

                                if (!isSuppressed)
                                {
                                    // check if all locations are ignored
                                    bool allLocationsIgnored = true;

                                    foreach (Location location in result.Locations)
                                    {
                                        // check if this location is ignored
                                        bool locationIsIgnored = false;
                                        foreach (string pathToIgnore in pathsToIgnore)
                                        {
                                            if (location.PhysicalLocation.ArtifactLocation.Uri.OriginalString.StartsWith(pathToIgnore))
                                            {
                                                locationIsIgnored = true;
                                                break;
                                            }
                                        }

                                        if (!locationIsIgnored)
                                        {
                                            allLocationsIgnored = false;
                                            break;
                                        }
                                    }

                                    if (allLocationsIgnored)
                                    {
                                        isSuppressed = true;
                                    }
                                }

                                if (!isSuppressed)
                                {
                                    Console.WriteLine($"Will fail check due to result: {resultInfoToString(result)}");
                                    errorsDetected = true;
                                }
                            }
                        }
                    }

                    if (errorsDetected)
                    {
                        throw new InvalidOperationException("Errors detected in SARIF files.");
                    }
                });
        }