/// <inheritdoc />
        public override IEnumerable <IIssue> ReadIssues(
            EsLintIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            EsLintIssuesSettings esLintsettings)
        {
            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            esLintsettings.NotNull(nameof(esLintsettings));

            IEnumerable <LogFile> logFileEntries = null;

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

            if (logFileEntries != null)
            {
                return
                    (from file in logFileEntries
                     from message in file.messages
                     select
                     GetIssue(file, message, issueProvider, repositorySettings));
            }

            return(new List <IIssue>());
        }
        /// <inheritdoc />
        public override IEnumerable <IIssue> ReadIssues(
            EsLintIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            EsLintIssuesSettings esLintsettings)
        {
            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            esLintsettings.NotNull(nameof(esLintsettings));

            IEnumerable <LogFile> logFileEntries = null;

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

            if (logFileEntries != null)
            {
                return
                    (from file in logFileEntries
                     from message in file.messages
                     let
                     rule = message.ruleId
                            select
                            IssueBuilder
                            .NewIssue(message.message, issueProvider)
                            .InFile(GetRelativeFilePath(file.filePath, repositorySettings), message.line, message.column)
                            .OfRule(rule, EsLintRuleUrlResolver.Instance.ResolveRuleUrl(rule))
                            .WithPriority(GetPriority(message.severity))
                            .Create());
            }

            return(new List <IIssue>());
        }
        /// <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));

            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());
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Make path relative to repository root.
        /// </summary>
        /// <param name="filePath">Full file path.</param>
        /// <param name="repositorySettings">Repository settings.</param>
        /// <returns>File path relative to the repository root.</returns>
        protected string MakeFilePathRelativeToRepositoryRoot(string filePath, IRepositorySettings repositorySettings)
        {
            filePath.NotNullOrWhiteSpace(nameof(filePath));
            repositorySettings.NotNull(nameof(repositorySettings));

            return(filePath.Substring(repositorySettings.RepositoryRoot.FullPath.Length));
        }
        /// <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());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Checks if a file is part of the repository.
        /// </summary>
        /// <param name="filePath">Full file path.</param>
        /// <param name="repositorySettings">Repository settings.</param>
        /// <returns>True if file is in repository, false otherwise.</returns>
        protected bool CheckIfFileIsInRepository(string filePath, IRepositorySettings repositorySettings)
        {
            filePath.NotNullOrWhiteSpace(nameof(filePath));
            repositorySettings.NotNull(nameof(repositorySettings));

            if (!filePath.IsSubpathOf(repositorySettings.RepositoryRoot.FullPath))
            {
                this.Log.Warning(
                    "Ignored issue for file '{0}' since it is outside the repository folder at {1}.",
                    filePath,
                    repositorySettings.RepositoryRoot);

                return(false);
            }

            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Validates a file path.
        /// </summary>
        /// <param name="filePath">Full file path.</param>
        /// <param name="repositorySettings">Repository settings.</param>
        /// <returns>Tuple containing a value if validation was successful, and file path relative to repository root.</returns>
        protected (bool Valid, string FilePath) ValidateFilePath(string filePath, IRepositorySettings repositorySettings)
        {
            filePath.NotNullOrWhiteSpace(nameof(filePath));
            repositorySettings.NotNull(nameof(repositorySettings));

            // Ignore files from outside the repository.
            if (!this.CheckIfFileIsInRepository(filePath, repositorySettings))
            {
                return(false, string.Empty);
            }

            // Make path relative to repository root.
            filePath = this.MakeFilePathRelativeToRepositoryRoot(filePath, repositorySettings);

            // Remove leading directory separator.
            filePath = this.RemoveLeadingDirectorySeparator(filePath);

            return(true, filePath);
        }
Ejemplo n.º 9
0
        /// <inheritdoc/>
        public override IEnumerable <IIssue> ReadIssues(
            MsBuildIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            MsBuildIssuesSettings issueProviderSettings)
        {
#pragma warning disable SA1123 // Do not place regions within elements
            #region DupFinder Exclusion
#pragma warning restore SA1123 // Do not place regions within elements

            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            issueProviderSettings.NotNull(nameof(issueProviderSettings));

            #endregion

            var result = new List <IIssue>();

            var binLogReader = new BinLogReader();
            foreach (var record in binLogReader.ReadRecords(issueProviderSettings.LogFileContent))
            {
                var buildEventArgs = record.Args;

                IIssue issue = null;
                if (buildEventArgs is BuildErrorEventArgs buildError)
                {
                    issue = this.GetIssue(buildError, issueProvider, repositorySettings);
                }
                else if (buildEventArgs is BuildWarningEventArgs buildWarning)
                {
                    issue = this.GetIssue(buildWarning, issueProvider, repositorySettings);
                }

                if (issue == null)
                {
                    continue;
                }

                result.Add(issue);
            }

            return(result);
        }
        /// <inheritdoc/>
        public override IEnumerable <IIssue> ReadIssues(
            MsBuildIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            MsBuildIssuesSettings issueProviderSettings)
        {
#pragma warning disable SA1123 // Do not place regions within elements
            #region DupFinder Exclusion
#pragma warning restore SA1123 // Do not place regions within elements

            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            issueProviderSettings.NotNull(nameof(issueProviderSettings));

            #endregion

            var result = new List <IIssue>();

            // Read log file.
            var raw         = issueProviderSettings.LogFileContent.ToStringUsingEncoding(true);
            var filtered    = string.Concat(raw.Where(c => !char.IsControl(c)));
            var logDocument = XDocument.Parse(filtered);

            // Loop through all warning and error tags.
            var elements = new List <XElement>(logDocument.Descendants("warning"));
            elements.AddRange(logDocument.Descendants("error"));

            foreach (var element in elements)
            {
                // Ignore warnings or errors without a message.
                if (string.IsNullOrWhiteSpace(element.Value))
                {
                    continue;
                }

                // Read affected project from the warning or error.
                if (!this.TryGetProject(element, repositorySettings, out string projectFileRelativePath))
                {
                    continue;
                }

                // Read affected file from the warning or error.
                if (!this.TryGetFile(element, repositorySettings, out string fileName))
                {
                    continue;
                }

                // Read affected line from the warning or error.
                if (!TryGetLine(element, out var line))
                {
                    continue;
                }

                // Read affected column from the warning or error.
                if (!TryGetColumn(element, out var column))
                {
                    continue;
                }

                // Read rule code from the warning or error.
                if (!TryGetRule(element, out string rule))
                {
                    continue;
                }

                // Determine rule URL.
                Uri ruleUrl = null;
                if (!string.IsNullOrWhiteSpace(rule))
                {
                    ruleUrl = MsBuildRuleUrlResolver.Instance.ResolveRuleUrl(rule);
                }

                var priority = element.Name.LocalName == "error" ? IssuePriority.Error : IssuePriority.Warning;

                // Build issue.
                result.Add(
                    IssueBuilder
                    .NewIssue(element.Value, issueProvider)
                    .WithPriority(priority)
                    .InProject(projectFileRelativePath, System.IO.Path.GetFileNameWithoutExtension(projectFileRelativePath))
                    .InFile(fileName, line, column)
                    .OfRule(rule, ruleUrl)
                    .Create());
            }

            return(result);
        }
        /// <inheritdoc/>
        public override IEnumerable <IIssue> ReadIssues(
            MsBuildIssuesProvider issueProvider,
            IRepositorySettings repositorySettings,
            MsBuildIssuesSettings issueProviderSettings)
        {
#pragma warning disable SA1123 // Do not place regions within elements
            #region DupFinder Exclusion
#pragma warning restore SA1123 // Do not place regions within elements

            issueProvider.NotNull(nameof(issueProvider));
            repositorySettings.NotNull(nameof(repositorySettings));
            issueProviderSettings.NotNull(nameof(issueProviderSettings));

            #endregion

            var result = new List <IIssue>();

            var binLogReader = new BinLogReader();
            foreach (var record in binLogReader.ReadRecords(issueProviderSettings.LogFileContent))
            {
                var buildEventArgs = record.Args;

                if (buildEventArgs is BuildWarningEventArgs buildWarning)
                {
                    // Ignore warnings without a message.
                    if (string.IsNullOrWhiteSpace(buildWarning.Message))
                    {
                        continue;
                    }

                    var projectFileRelativePath = this.GetProject(buildWarning, repositorySettings);

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

                    var line      = GetLine(buildWarning);
                    var endLine   = GetEndLine(buildWarning);
                    var column    = GetColumn(buildWarning);
                    var endColumn = GetEndColumn(buildWarning);
                    var rule      = buildWarning.Code;

                    // Determine rule URL.
                    Uri ruleUrl = null;
                    if (!string.IsNullOrWhiteSpace(rule))
                    {
                        ruleUrl = MsBuildRuleUrlResolver.Instance.ResolveRuleUrl(rule);
                    }

                    // Build issue.
                    result.Add(
                        IssueBuilder
                        .NewIssue(buildWarning.Message, issueProvider)
                        .WithPriority(IssuePriority.Warning)
                        .InProject(projectFileRelativePath, System.IO.Path.GetFileNameWithoutExtension(projectFileRelativePath))
                        .InFile(fileName, line, endLine, column, endColumn)
                        .OfRule(rule, ruleUrl)
                        .Create());
                }
            }

            return(result);
        }