/// <inheritdoc />
        public override IEnumerable <IIssue> ReadIssues(
            MarkdownlintIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            MarkdownlintIssuesSettings markdownlintIssuesSettings)
        {
            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            markdownlintIssuesSettings.NotNull(nameof(markdownlintIssuesSettings));

            var regex = new Regex(@"(?<filePath>.*[^:\d+]): ?(?<lineNumber>\d+):?(?<columnNumber>\d+)? (?<ruleId>MD\d+)/(?<ruleName>(?:\w*-*/*)*) (?<message>.*)");

            foreach (var line in markdownlintIssuesSettings.LogFileContent.ToStringUsingEncoding().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).ToList().Where(s => !string.IsNullOrEmpty(s)))
            {
                var groups = regex.Match(line).Groups;

                // Read affected file from the line.
                if (!this.TryGetFile(groups, repositorySettings, out string fileName))
                {
                    continue;
                }

                var lineNumber = int.Parse(groups["lineNumber"].Value);
                var ruleId     = groups["ruleId"].Value;
                var message    = groups["message"].Value;

                yield return
                    (IssueBuilder
                     .NewIssue(message, issueProvider)
                     .InFile(fileName, lineNumber)
                     .WithPriority(IssuePriority.Warning)
                     .OfRule(ruleId, MarkdownlintRuleUrlResolver.Instance.ResolveRuleUrl(ruleId))
                     .Create());
            }
        }
        /// <inheritdoc />
        public override IEnumerable <IIssue> ReadIssues(
            MarkdownlintIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            MarkdownlintIssuesSettings markdownlintIssuesSettings)
        {
            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            markdownlintIssuesSettings.NotNull(nameof(markdownlintIssuesSettings));

            if (!markdownlintIssuesSettings.LogFileContent.Any())
            {
                return(new List <IIssue>());
            }

            IEnumerable <LogFileEntry> logFileEntries = null;

            using (var ms = new MemoryStream(markdownlintIssuesSettings.LogFileContent.ToStringUsingEncoding(true).ToByteArray()))
            {
                var jsonSerializer = new DataContractJsonSerializer(typeof(LogFileEntry[]));
                logFileEntries = jsonSerializer.ReadObject(ms) as LogFileEntry[];
            }

            if (logFileEntries == null)
            {
                return(new List <IIssue>());
            }

            return(logFileEntries.Select(x => GetIssue(x, issueProvider, repositorySettings)));
        }
        /// <inheritdoc />
        public override IEnumerable <IIssue> ReadIssues(
            MarkdownlintIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            MarkdownlintIssuesSettings markdownlintIssuesSettings)
        {
            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            markdownlintIssuesSettings.NotNull(nameof(markdownlintIssuesSettings));

            Dictionary <string, IEnumerable <Issue> > logFileEntries;

            using (var ms = new MemoryStream(markdownlintIssuesSettings.LogFileContent.RemovePreamble()))
            {
                var jsonSerializer = new DataContractJsonSerializer(
                    typeof(Dictionary <string, IEnumerable <Issue> >),
                    settings: new DataContractJsonSerializerSettings {
                    UseSimpleDictionaryFormat = true
                });

                logFileEntries = jsonSerializer.ReadObject(ms) as Dictionary <string, IEnumerable <Issue> >;
            }

            return
                (from file in logFileEntries
                 from entry in file.Value
                 let
                 rule = entry.ruleName
                        select
                        IssueBuilder
                        .NewIssue(entry.ruleDescription, issueProvider)
                        .InFile(file.Key, entry.lineNumber)
                        .WithPriority(IssuePriority.Warning)
                        .OfRule(rule, MarkdownlintRuleUrlResolver.Instance.ResolveRuleUrl(rule))
                        .Create());
        }
        /// <inheritdoc />
        public override IEnumerable <IIssue> ReadIssues(
            MarkdownlintIssuesProvider issueProvider,
            IssueCommentFormat format,
            RepositorySettings repositorySettings,
            MarkdownlintIssuesSettings markdownlintIssuesSettings)
        {
            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            markdownlintIssuesSettings.NotNull(nameof(markdownlintIssuesSettings));

            var regex = new Regex(@"(.*): (\d*): (MD\d*)/((?:\w*-*/*)*) (.*)");

            foreach (var line in markdownlintIssuesSettings.LogFileContent.ToStringUsingEncoding().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None).ToList().Where(s => !string.IsNullOrEmpty(s)))
            {
                var groups = regex.Match(line).Groups;

                // Read affected file from the line.
                if (!this.TryGetFile(groups, repositorySettings, out string fileName))
                {
                    continue;
                }

                var lineNumber      = int.Parse(groups[2].Value);
                var rule            = groups[3].Value;
                var ruleDescription = groups[5].Value;

                yield return
                    (IssueBuilder
                     .NewIssue(ruleDescription, issueProvider)
                     .InFile(fileName, lineNumber)
                     .WithPriority(IssuePriority.Warning)
                     .OfRule(rule, MarkdownlintRuleUrlResolver.Instance.ResolveRuleUrl(rule))
                     .Create());
            }
        }
Esempio n. 5
0
            public void Should_Set_LogFileContent_If_Empty()
            {
                // Given
                byte[] logFileContent = Array.Empty <byte>();
                var    format         = new MarkdownlintLogFileFormat(new FakeLog());

                // When
                var settings = new MarkdownlintIssuesSettings(logFileContent, format);

                // Then
                settings.LogFileContent.ShouldBe(logFileContent);
            }
Esempio n. 6
0
            public void Should_Set_LogFileContent()
            {
                // Given
                var logFileContent = "Foo".ToByteArray();
                var format         = new MarkdownlintLogFileFormat(new FakeLog());

                // When
                var settings = new MarkdownlintIssuesSettings(logFileContent, format);

                // Then
                settings.LogFileContent.ShouldBe(logFileContent);
            }
Esempio n. 7
0
            public void Should_Set_LogFileContent_From_LogFilePath()
            {
                // Given
                var format = new MarkdownlintLogFileFormat(new FakeLog());

                using (var tempFile = new ResourceTempFile("Cake.Issues.Markdownlint.Tests.Testfiles.MarkdownlintLogFileFormat.markdownlint.json"))
                {
                    // When
                    var settings = new MarkdownlintIssuesSettings(tempFile.FileName, format);

                    // Then
                    settings.LogFileContent.ShouldBe(tempFile.Content);
                }
            }