private void AnalyzeToolDriver(ToolComponent toolComponent, string toolDriverPointer)
        {
            if (!string.IsNullOrEmpty(toolComponent.Name))
            {
                const int MaxWords  = 3;
                int       wordCount = toolComponent.Name.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length;
                if (wordCount > MaxWords)
                {
                    string driverNamePointer = toolDriverPointer.AtProperty(SarifPropertyName.Name);

                    // {0}: The tool name '{1}' contains {2} words, which is more than the recommended
                    // maximum of {3} words. A short tool name is easy to remember and fits into a
                    // narrow column when displaying a list of results. If you need to provide more
                    // information about your tool, use the 'fullName' property.
                    LogResult(
                        driverNamePointer,
                        nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_ProvideConciseToolName_Text),
                        toolComponent.Name,
                        wordCount.ToString(),
                        MaxWords.ToString());
                }
            }

            bool informationUriRequired = this.Context.Policy.GetProperty(InformationUriRequired);

            if (informationUriRequired && toolComponent.InformationUri == null)
            {
                // {0}: The tool '{1}' does not provide 'informationUri'. This property helps the
                // developer responsible for addessing a result by providing a way to learn more
                // about the tool.
                LogResult(
                    toolDriverPointer,
                    nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_ProvideToolnformationUri_Text),
                    toolComponent.Name);
            }

            StringSet acceptableVersionProperties = this.Context.Policy.GetProperty(AcceptableVersionProperties);
            bool      toolDriverProvidesVersion   = false;

            toolDriverProvidesVersion |= acceptableVersionProperties.Contains(nameof(toolComponent.Version)) && !string.IsNullOrWhiteSpace(toolComponent.Version);
            toolDriverProvidesVersion |= acceptableVersionProperties.Contains(nameof(toolComponent.SemanticVersion)) && !string.IsNullOrWhiteSpace(toolComponent.SemanticVersion);
            toolDriverProvidesVersion |= acceptableVersionProperties.Contains(nameof(toolComponent.DottedQuadFileVersion)) && !string.IsNullOrWhiteSpace(toolComponent.DottedQuadFileVersion);

            if (!toolDriverProvidesVersion)
            {
                // {0}: The tool '{1}' does not provide any of the version-related properties {2}.
                // Providing version information enables the log file consumer to determine whether
                // the file was produced by an up to date version, and to avoid accidentally
                // comparing log files produced by different tool versions.
                LogResult(
                    toolDriverPointer,
                    nameof(RuleResources.SARIF2005_ProvideToolProperties_Warning_ProvideToolVersion_Text),
                    toolComponent.Name,
                    $"'{string.Join("', '", acceptableVersionProperties.Select(ToCamelCase))}'");
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(toolComponent.Version))
                {
                    AnalyzeVersion(toolComponent.Name, toolComponent.Version, toolDriverPointer.AtProperty(SarifPropertyName.Version));
                }
            }
        }
Exemple #2
0
 public IEnumerable <Adapter <T> > AllAdapters(Func <string, T> func, string setupType = "sql")
 {
     return(validAdapters.Select(name => Adapter(name, func(name), setupType)).SuccessfulValue());
 }