Ejemplo n.º 1
0
 public void Reset()
 {
     defectCountBeforeCheck = 0;
     Defects.Clear();
     SeverityBitmask.SetAll();
     ConfidenceBitmask.SetAll();
 }
Ejemplo n.º 2
0
 private bool Filter(Severity severity, Confidence confidence, IMetadataTokenProvider location)
 {
     if (!SeverityBitmask.Get(severity) || !ConfidenceBitmask.Get(confidence))
     {
         return(false);
     }
     // for Assembly | Type | Methods we can ignore before executing the rule
     // but for others (e.g. Parameters, Fields...) we can only ignore the results
     return(!IgnoreList.IsIgnored(currentRule, location));
 }
        byte Parse(string [] args)
        {
            bool severity   = false;
            bool confidence = false;

            // if supplied, use the user limit on defects (otherwise 2^31 is used)
            DefectsLimit = Int32.MaxValue;

            var p = new OptionSet()
            {
                { "config=", v => config_file = ValidateInputFile("config", v) },
                { "set=", v => rule_set = ValidateRuleSet(v) },
                { "log=", v => log_file = ValidateOutputFile("log", v) },
                { "xml=", v => xml_file = ValidateOutputFile("xml", v) },
                { "html=", v => html_file = ValidateOutputFile("html", v) },
                { "ignore=", v => ignore_file = ValidateInputFile("ignore", v) },
                { "limit=", v => DefectsLimit = ValidateLimit(v) },
                { "severity=", v => severity = ParseSeverity(v) },
                { "confidence=", v => confidence = ParseConfidence(v) },
                { "v|verbose", v => ++ VerbosityLevel },
                { "console", v => console = v != null },
                { "quiet", v => quiet = v != null },
                { "version", v => version = v != null },
                { "h|?|help", v => help = v != null },
            };

            try
            {
                assembly_names = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine("Error parsing option '{0}' : {1}", e.OptionName, e.Message);
                Console.WriteLine();
                return(1);
            }

            // by default the runner will ignore Audit and Low severity defects
            if (!severity)
            {
                SeverityBitmask.SetAll();
                SeverityBitmask.Clear(Severity.Audit);
                SeverityBitmask.Clear(Severity.Low);
            }

            // by default the runner will ignore Low confidence defects
            if (!confidence)
            {
                ConfidenceBitmask.SetAll();
                ConfidenceBitmask.Clear(Confidence.Low);
            }

            return((byte)((assembly_names.Count > 0) ? 0 : 1));
        }
Ejemplo n.º 4
0
        // parse severity filter
        // e.g. Audit,High+ == Audit, High and Critical
        bool ParseSeverity(string filter)
        {
            SeverityBitmask.ClearAll();
            foreach (string option in SplitOptions(filter))
            {
                Severity severity;

                switch (option)
                {
                case "AUDIT":
                case "AUDIT+":
                case "AUDIT-":
                    severity = Severity.Audit;
                    break;

                case "LOW":
                case "LOW+":
                case "LOW-":
                    severity = Severity.Low;
                    break;

                case "MEDIUM":
                case "MEDIUM+":
                case "MEDIUM-":
                    severity = Severity.Medium;
                    break;

                case "HIGH":
                case "HIGH+":
                case "HIGH-":
                    severity = Severity.High;
                    break;

                case "CRITICAL":
                case "CRITICAL+":
                case "CRITICAL-":
                    severity = Severity.Critical;
                    break;

                case "ALL":
                case "*":
                    SeverityBitmask.SetAll();
                    continue;

                default:
                    string msg = String.Format(CultureInfo.CurrentCulture, "Unknown severity level '{0}'", option);
                    throw new OptionException(msg, "severity");
                }

                char end = option [option.Length - 1];
                if (end == '+')
                {
                    SeverityBitmask.SetDown(severity);
                }
                else if (end == '-')
                {
                    SeverityBitmask.SetUp(severity);
                }
                else
                {
                    SeverityBitmask.Set(severity);
                }
            }
            return(true);
        }