Example #1
0
        public static Result CreateResult(
            int startLine,
            int startColumn,
            string jsonPath,
            ErrorNumber errorNumber,
            params object[] args)
        {
            Rule rule = RuleFactory.GetRuleFromErrorNumber(errorNumber);

            var messageArguments = new List <string> {
                jsonPath
            };

            messageArguments.AddRange(args.Select(a => a.ToString()));

            var result = new Result
            {
                RuleId    = rule.Id,
                Level     = rule.Configuration.DefaultLevel.ToLevel(),
                Locations = new List <Location>
                {
                    new Location
                    {
                        PhysicalLocation = new PhysicalLocation
                        {
                            Region = new Region
                            {
                                StartLine   = startLine,
                                StartColumn = startColumn
                            }
                        }
                    }
                },

                Message = new Message
                {
                    MessageId = RuleFactory.DefaultRuleMessageId,
                    Arguments = messageArguments
                },
            };

            result.SetProperty("jsonPath", jsonPath);

            return(result);
        }
Example #2
0
        public static Result ToSarifResult(this JsonSyntaxException ex)
        {
            string fileName = ex.FileName;
            JsonReaderException jsonReaderException = ex.JsonReaderException;

            ReportingDescriptor rule = RuleFactory.GetRuleFromErrorNumber(ErrorNumber.SyntaxError);

            return(new Result
            {
                RuleId = rule.Id,
                Level = rule.DefaultConfiguration.Level,
                Locations = new List <Location>
                {
                    new Location
                    {
                        PhysicalLocation = new PhysicalLocation
                        {
                            ArtifactLocation = new ArtifactLocation
                            {
                                Uri = new Uri(fileName, UriKind.RelativeOrAbsolute)
                            },
                            Region = new Region
                            {
                                StartLine = jsonReaderException.LineNumber,
                                StartColumn = jsonReaderException.LinePosition
                            }
                        }
                    }
                },

                Message = new Message
                {
                    Id = RuleFactory.DefaultRuleMessageId,
                    Arguments = new List <string>
                    {
                        jsonReaderException.Path,
                        jsonReaderException.Message
                    }
                },
            });
        }