예제 #1
0
파일: Verifier.cs 프로젝트: kannans/DevSkim
        private bool LoadFile(string file)
        {
            RuleSet rules     = new RuleSet();
            bool    noProblem = true;

            rules.OnDeserializationError += delegate(object?sender, Newtonsoft.Json.Serialization.ErrorEventArgs e)
            {
                ErrorMessage message = new ErrorMessage(File: file,
                                                        Message: e.ErrorContext.Error.Message,
                                                        Path: e.ErrorContext.Path);

                if (e.ErrorContext.OriginalObject is Rule r && !string.IsNullOrEmpty(r.Id))
                {
                    message.RuleID = r.Id;
                }

                // Newtonsoft json throws some errors twice
                if (_messages.FirstOrDefault(x => (x.Message == message.Message && x.File == file)) == null)
                {
                    _messages.Add(message);
                }

                noProblem = false;
                e.ErrorContext.Handled = true;
            };

            rules.AddFile(file, null);

            if (noProblem)
            {
                _rules.AddRange(rules.AsEnumerable());
            }

            return(noProblem);
        }
        private void LoadFile(string file)
        {
            RuleSet rules = new RuleSet();

            try
            {
                rules.AddFile(file, null);
            }
            catch (Exception e)
            {
                Debug.Write(e.Message);//Ensure console message indicates problem for Build process
                WriteOnce.SafeLog(e.Message, NLog.LogLevel.Error);
                throw new Exception(ErrMsg.FormatString(ErrMsg.ID.VERIFY_RULE_FAILED, file));
            }

            _rules.AddRange(rules.AsEnumerable());
        }
예제 #3
0
        private bool LoadFile(string file)
        {
            RuleSet rules     = new RuleSet();
            bool    noProblem = true;

            rules.OnDeserializationError += delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs e)
            {
                throw new Exception(String.Format("Error packing rule file: {0}", file));
            };

            rules.AddFile(file, null);

            if (noProblem)
            {
                _rules.AddRange(rules.AsEnumerable());
            }

            return(noProblem);
        }
예제 #4
0
        private void CheckIntegrity()
        {
            string[] languages = Language.GetNames();

            foreach (Rule rule in _rules.AsEnumerable())
            {
                // Check for null Id
                if (rule.Id == null)
                {
                    _messages.Add(new ErrorMessage(Message: "Rule has empty ID", Path: rule.Name, File: rule.Source, Warning: true));
                }
                else
                {
                    // Check for same ID
                    Rule sameRule = _rules.FirstOrDefault(x => x.Id == rule.Id);
                    if (sameRule != null && sameRule != rule)
                    {
                        _messages.Add(new ErrorMessage(Message: "Two or more rules have a same ID", RuleID: sameRule.Id, File: sameRule.Source, Warning: true));

                        _messages.Add(new ErrorMessage(Message: "Two or more rules have a same ID", RuleID: rule.Id, File: rule.Source, Warning: true));
                    }
                }

                if (rule.AppliesTo != null)
                {
                    // Check for unknown language
                    foreach (string lang in rule.AppliesTo)
                    {
                        if (!languages.Contains(lang))
                        {
                            _messages.Add(new ErrorMessage(Message: string.Format("Unknown language '{0}'", lang),
                                                           RuleID: rule.Id ?? string.Empty,
                                                           Path: "applies_to",
                                                           File: rule.Source,
                                                           Warning: true));
                        }
                    }
                }
            }
        }
예제 #5
0
        private void CheckIntegrity()
        {
            _verified = true;

            foreach (Rule rule in _rules?.AsEnumerable() ?? Array.Empty <Rule>())
            {
                bool ruleVerified = CheckIntegrity(rule);
                _ruleStatuses?.Add(new RuleStatus()
                {
                    RulesId   = rule.Id,
                    RulesName = rule.Name,
                    Verified  = ruleVerified
                });

                _verified = ruleVerified && _verified;

                if (_failFast && !ruleVerified)
                {
                    return;
                }
            }
        }