private void ParseOtherLineSuppressions()

in DevSkim-DotNet/Microsoft.DevSkim.VSExtension/Shim/SuppressorEx.cs [20:119]


        private void ParseOtherLineSuppressions()
        {
            var settings = Settings.GetSettings();
            // If we have multiple lines to look at
            if (_text != null && settings.UsePreviousLineSuppression)
            {
                // If the line with the issue doesn't contain a suppression check the lines above it
                if (!_lineText.Contains(KeywordPrefix))
                {
                    if (_lineNumber > 1)
                    {
                        var content = _text.GetLineContent(--_lineNumber);
                        if (content.Contains(Language.GetCommentSuffix(_text.Language)))
                        {
                            while (_lineNumber >= 1)
                            {
                                if (reg.IsMatch(_text.GetLineContent(_lineNumber)))
                                {
                                    _lineText = _text.GetLineContent(_lineNumber);
                                    break;
                                }
                                else if (_text.GetLineContent(_lineNumber).Contains(Language.GetCommentPrefix(_text.Language)))
                                {
                                    break;
                                }
                                _lineNumber--;
                            }
                        }
                        else if (content.Contains(Language.GetCommentInline(_text.Language)))
                        {
                            _lineText = content;
                        }
                    }
                }
                Match match = reg.Match(_lineText);

                if (match.Success)
                {
                    _suppressStart = match.Index;
                    _suppressLength = match.Length;

                    string idString = match.Groups[1].Value.Trim();
                    IssuesListIndex = match.Groups[1].Index;

                    // Parse date
                    if (match.Groups.Count > 2)
                    {
                        string date = match.Groups[2].Value;
                        reg = new Regex(@"(\d{4}-\d{2}-\d{2})");
                        Match m = reg.Match(date);
                        if (m.Success)
                        {
                            try
                            {
                                _expirationDate = DateTime.ParseExact(m.Value, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
                            }
                            catch (FormatException)
                            {
                                _expirationDate = DateTime.MinValue;
                            }
                        }
                    }

                    // parse Ids.
                    if (idString == KeywordAll)
                    {
                        _issues.Add(new SuppressedIssue()
                        {
                            ID = KeywordAll,
                            Boundary = new Boundary()
                            {
                                Index = IssuesListIndex,
                                Length = KeywordAll.Length
                            }
                        });
                    }
                    else
                    {
                        string[] ids = idString.Split(',');
                        int index = IssuesListIndex;
                        foreach (string id in ids)
                        {
                            if (!_issues.Any(x => x.ID == id))
                            {
                                _issues.Add(new SuppressedIssue()
                                {
                                    ID = id,
                                    Boundary = new Boundary()
                                    {
                                        Index = index,
                                        Length = id.Length
                                    }
                                });
                            }
                            index += id.Length + 1;
                        }
                    }
                }
            }
        }