diff --git a/src/ReleaseHistory.md b/src/ReleaseHistory.md index e0c9cd7ab..792bc9fd1 100644 --- a/src/ReleaseHistory.md +++ b/src/ReleaseHistory.md @@ -1,5 +1,7 @@ # SARIF Package Release History (SDK, Driver, Converters, and Multitool) +* FEATURE: Add Clang-Tidy converter. [#2367](https://github.com/microsoft/sarif-sdk/pull/2367) + ## **v2.4.9** [Sdk](https://www.nuget.org/packages/Sarif.Sdk/2.4.9) | [Driver](https://www.nuget.org/packages/Sarif.Driver/2.4.9) | [Converters](https://www.nuget.org/packages/Sarif.Converters/2.4.9) | [Multitool](https://www.nuget.org/packages/Sarif.Multitool/2.4.9) | [Multitool Library](https://www.nuget.org/packages/Sarif.Multitool.Library/2.4.9) * FEATURE: Report inner exception details if available. [#2357](https://github.com/microsoft/sarif-sdk/pull/2357) * FEATURE: Add support for git blame. [#2358](https://github.com/microsoft/sarif-sdk/pull/2358) diff --git a/src/Sarif.Converters/BuiltInConverterFactory.cs b/src/Sarif.Converters/BuiltInConverterFactory.cs index 110602c93..8b1b1838d 100644 --- a/src/Sarif.Converters/BuiltInConverterFactory.cs +++ b/src/Sarif.Converters/BuiltInConverterFactory.cs @@ -27,6 +27,7 @@ private static Dictionary> CreateBuiltInConv CreateConverterRecord(result, ToolFormat.AndroidStudio); CreateConverterRecord(result, ToolFormat.CppCheck); CreateConverterRecord(result, ToolFormat.ClangAnalyzer); + CreateConverterRecord(result, ToolFormat.ClangTidy); CreateConverterRecord(result, ToolFormat.ContrastSecurity); CreateConverterRecord(result, ToolFormat.Fortify); CreateConverterRecord(result, ToolFormat.FortifyFpr); diff --git a/src/Sarif.Converters/ClangTidyConverter.cs b/src/Sarif.Converters/ClangTidyConverter.cs new file mode 100644 index 000000000..2b7f0fbdc --- /dev/null +++ b/src/Sarif.Converters/ClangTidyConverter.cs @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +using Microsoft.CodeAnalysis.Sarif.Converters.ClangTidyObjectModel; + +using YamlDotNet.Serialization; + +namespace Microsoft.CodeAnalysis.Sarif.Converters +{ + public class ClangTidyConverter : ToolFileConverterBase + { + private const string ToolInformationUri = "https://clang.llvm.org/extra/clang-tidy/"; + + public override string ToolName => "Clang-Tidy"; + + public override void Convert(Stream input, IResultLogWriter output, OptionallyEmittedData dataToInsert) + { + input = input ?? throw new ArgumentNullException(nameof(input)); + output = output ?? throw new ArgumentNullException(nameof(output)); + + IDeserializer deserializer = new DeserializerBuilder().Build(); + using var textReader = new StreamReader(input); + ClangTidyLog log = deserializer.Deserialize(textReader); + + (List, List) rulesAndResults = ExtractRulesAndResults(log); + + var run = new Run + { + Tool = new Tool + { + Driver = new ToolComponent + { + Name = ToolName, + InformationUri = new Uri(ToolInformationUri), + Rules = rulesAndResults.Item1, + } + }, + Results = rulesAndResults.Item2, + }; + + PersistResults(output, rulesAndResults.Item2, run); + } + + internal static Result CreateResult(ClangTidyDiagnostic entry) + { + entry = entry ?? throw new ArgumentNullException(nameof(entry)); + + Result result = new Result() + { + RuleId = entry.DiagnosticName, + Message = new Message { Text = entry.DiagnosticMessage.Message }, + Kind = ResultKind.Fail + }; + + // no level infomation in Clang-Tidy report + result.Level = FailureLevel.Warning; + + Region region = new Region() + { + CharOffset = entry.DiagnosticMessage.FileOffset, + }; + + Uri analysisTargetUri = new Uri(entry.DiagnosticMessage.FilePath, UriKind.RelativeOrAbsolute); + + var physicalLocation = new PhysicalLocation + { + ArtifactLocation = new ArtifactLocation + { + Uri = analysisTargetUri + }, + Region = region + }; + + Location location = new Location() + { + PhysicalLocation = physicalLocation + }; + + result.Locations = new List() + { + location + }; + + if (entry.DiagnosticMessage.Replacements.Count > 0) + { + IList replacements = new List(); + + foreach (ClangTidyReplacement fix in entry.DiagnosticMessage.Replacements) + { + Replacement replacement = new Replacement(); + + replacement.DeletedRegion = new Region + { + CharLength = fix.Length, + CharOffset = fix.Offset, + }; + + if (!string.IsNullOrEmpty(fix.ReplacementText)) + { + replacement.InsertedContent = new ArtifactContent + { + Text = fix.ReplacementText + }; + } + + replacements.Add(replacement); + } + + var sarifFileChange = new ArtifactChange + { + ArtifactLocation = new ArtifactLocation + { + Uri = analysisTargetUri + }, + Replacements = replacements + }; + + Fix sarifFix = new Fix(description: null, artifactChanges: new List() { sarifFileChange }, properties: null); + result.Fixes = new List { sarifFix }; + } + + return result; + } + + private static (List, List) ExtractRulesAndResults(ClangTidyLog log) + { + var rules = new Dictionary(StringComparer.OrdinalIgnoreCase); + var results = new List(); + + foreach (ClangTidyDiagnostic diagnostic in log.Diagnostics) + { + string ruleId = diagnostic.DiagnosticName; + (ReportingDescriptor, Result) ruleAndResult = SarifRuleAndResultFromClangTidyDiagnostic(diagnostic); + if (!rules.ContainsKey(ruleId)) + { + rules.Add(ruleId, ruleAndResult.Item1); + } + + results.Add(ruleAndResult.Item2); + } + + return (rules.Values.ToList(), results); + } + + private static (ReportingDescriptor, Result) SarifRuleAndResultFromClangTidyDiagnostic(ClangTidyDiagnostic diagnostic) + { + var reportingDescriptor = new ReportingDescriptor + { + Id = diagnostic.DiagnosticName, + HelpUri = diagnostic.DiagnosticName.Equals("clang-diagnostic-error", StringComparison.OrdinalIgnoreCase) + ? null + : new Uri($"https://clang.llvm.org/extra/clang-tidy/checks/{diagnostic.DiagnosticName}.html") + }; + + Result result = CreateResult(diagnostic); + + return (reportingDescriptor, result); + } + } +} diff --git a/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyDiagnostic.cs b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyDiagnostic.cs new file mode 100644 index 000000000..c667793e7 --- /dev/null +++ b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyDiagnostic.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.CodeAnalysis.Sarif.Converters.ClangTidyObjectModel +{ + public class ClangTidyDiagnostic + { + public string DiagnosticName { get; set; } + public ClangTidyDiagnosticMessage DiagnosticMessage { get; set; } + } +} diff --git a/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyDiagnosticMessage.cs b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyDiagnosticMessage.cs new file mode 100644 index 000000000..e8d09ef84 --- /dev/null +++ b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyDiagnosticMessage.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Generic; + +namespace Microsoft.CodeAnalysis.Sarif.Converters.ClangTidyObjectModel +{ + public class ClangTidyDiagnosticMessage + { + public string Message { get; set; } + public string FilePath { get; set; } + public int FileOffset { get; set; } + public List Replacements { get; set; } + } +} diff --git a/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyLog.cs b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyLog.cs new file mode 100644 index 000000000..b605921bf --- /dev/null +++ b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyLog.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Collections.Generic; + +namespace Microsoft.CodeAnalysis.Sarif.Converters.ClangTidyObjectModel +{ + public class ClangTidyLog + { + public string MainSourceFile { get; set; } + public List Diagnostics { get; set; } + } +} diff --git a/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyReplacement.cs b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyReplacement.cs new file mode 100644 index 000000000..74fb1221c --- /dev/null +++ b/src/Sarif.Converters/ClangTidyObjectModel/ClangTidyReplacement.cs @@ -0,0 +1,13 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.CodeAnalysis.Sarif.Converters.ClangTidyObjectModel +{ + public class ClangTidyReplacement + { + public string FilePath { get; set; } + public int Offset { get; set; } + public int Length { get; set; } + public string ReplacementText { get; set; } + } +} diff --git a/src/Sarif.Converters/Sarif.Converters.csproj b/src/Sarif.Converters/Sarif.Converters.csproj index eafdaaeee..744059919 100644 --- a/src/Sarif.Converters/Sarif.Converters.csproj +++ b/src/Sarif.Converters/Sarif.Converters.csproj @@ -41,7 +41,8 @@ - + + diff --git a/src/Sarif.Converters/ToolFormat.cs b/src/Sarif.Converters/ToolFormat.cs index 4e61594e5..562e1cd9b 100644 --- a/src/Sarif.Converters/ToolFormat.cs +++ b/src/Sarif.Converters/ToolFormat.cs @@ -15,6 +15,9 @@ public static class ToolFormat /// Clang analyzer's file format. public const string ClangAnalyzer = nameof(ClangAnalyzer); + /// Clang analyzer's file format. + public const string ClangTidy = nameof(ClangTidy); + /// Contrast Security's file format. public const string ContrastSecurity = nameof(ContrastSecurity); diff --git a/src/Sarif.Multitool.Library/ConvertOptions.cs b/src/Sarif.Multitool.Library/ConvertOptions.cs index e32e72de8..cbc869926 100644 --- a/src/Sarif.Multitool.Library/ConvertOptions.cs +++ b/src/Sarif.Multitool.Library/ConvertOptions.cs @@ -13,7 +13,7 @@ public class ConvertOptions : SingleFileOptionsBase [Option( 't', "tool", - HelpText = "The tool format of the input file. Must be one of: AndroidStudio, ClangAnalyzer, CppCheck, ContrastSecurity, FlawFinder, Fortify, FortifyFpr, FxCop, Hdf, PREfast, Pylint, SemmleQL, StaticDriverVerifier, TSLint, or a tool format for which a plugin assembly provides the converter.", + HelpText = "The tool format of the input file. Must be one of: AndroidStudio, ClangAnalyzer, ClangTidy, CppCheck, ContrastSecurity, FlawFinder, Fortify, FortifyFpr, FxCop, Hdf, PREfast, Pylint, SemmleQL, StaticDriverVerifier, TSLint, or a tool format for which a plugin assembly provides the converter.", Required = true)] public string ToolFormat { get; set; } diff --git a/src/Test.UnitTests.Sarif.Converters/ClangTidyConverterTests.cs b/src/Test.UnitTests.Sarif.Converters/ClangTidyConverterTests.cs new file mode 100644 index 000000000..5bc41d16c --- /dev/null +++ b/src/Test.UnitTests.Sarif.Converters/ClangTidyConverterTests.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.IO; + +using FluentAssertions; + +using Microsoft.CodeAnalysis.Sarif.Writers; + +using Xunit; + +using YamlDotNet.Core; + +namespace Microsoft.CodeAnalysis.Sarif.Converters +{ + public class ClangTidyConverterTests : ConverterTestsBase + { + private static readonly string NoOutputExpected = string.Empty; + + [Fact] + public void Converter_RequiresInputStream() + { + var converter = new ClangTidyConverter(); + Action action = () => converter.Convert(input: null, output: new ResultLogObjectWriter(), dataToInsert: OptionallyEmittedData.None); + action.Should().Throw(); + } + + [Fact] + public void Converter_RequiresResultLogWriter() + { + var converter = new ClangTidyConverter(); + Action action = () => converter.Convert(input: new MemoryStream(), output: null, dataToInsert: OptionallyEmittedData.None); + action.Should().Throw(); + } + + [Fact] + public void Converter_WhenInputIsEmpty_ReturnsNoResults() + { + string input = GetResourceText("Inputs.Empty.yaml"); + string expectedOutput = GetResourceText("ExpectedOutputs.NoResults.sarif"); + RunTestCase(input, expectedOutput); + } + + [Fact] + public void Converter_WhenResultRowIsInvalid_ThrowsExpectedException() + { + string input = GetResourceText("Inputs.InvalidResult.yaml"); + Action action = () => RunTestCase(input, NoOutputExpected); + action.Should().Throw(); + } + + [Fact] + public void Converter_WhenInputContainsValidResults_ReturnsExpectedOutput() + { + string input = GetResourceText("Inputs.ValidResults.yaml"); + string expectedOutput = GetResourceText("ExpectedOutputs.ValidResults.sarif"); + RunTestCase(input, expectedOutput); + } + + private static readonly ResourceExtractor s_extractor = new ResourceExtractor(typeof(ClangTidyConverterTests)); + private const string ResourceNamePrefix = ToolFormat.ClangTidy; + + private static string GetResourceText(string resourceNameSuffix) => + s_extractor.GetResourceText($"TestData.{ResourceNamePrefix}.{resourceNameSuffix}"); + } +} diff --git a/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj b/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj index 67a2c6aa6..c436c752e 100644 --- a/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj +++ b/src/Test.UnitTests.Sarif.Converters/Test.UnitTests.Sarif.Converters.csproj @@ -14,6 +14,11 @@ + + + + + @@ -48,6 +53,11 @@ + + + + + diff --git a/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/ExpectedOutputs/NoResults.sarif b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/ExpectedOutputs/NoResults.sarif new file mode 100644 index 000000000..42a382f10 --- /dev/null +++ b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/ExpectedOutputs/NoResults.sarif @@ -0,0 +1,16 @@ +{ + "$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json", + "version": "2.1.0", + "runs": [ + { + "results": [], + "tool": { + "driver": { + "name": "Clang-Tidy", + "informationUri": "https://clang.llvm.org/extra/clang-tidy/" + } + }, + "columnKind": "utf16CodeUnits" + } + ] +} \ No newline at end of file diff --git a/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/ExpectedOutputs/ValidResults.sarif b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/ExpectedOutputs/ValidResults.sarif new file mode 100644 index 000000000..d574f0b61 --- /dev/null +++ b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/ExpectedOutputs/ValidResults.sarif @@ -0,0 +1,289 @@ +{ + "$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.5.json", + "version": "2.1.0", + "runs": [ + { + "results": [ + { + "ruleId": "clang-diagnostic-error", + "message": { + "text": "too many errors emitted, stopping now" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "", + "index": 0 + }, + "region": { + "charOffset": 0 + } + } + } + ] + }, + { + "ruleId": "readability-convert-member-functions-to-static", + "message": { + "text": "method 'print' can be made static" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/Hello.cpp", + "index": 1 + }, + "region": { + "charOffset": 60 + } + } + } + ], + "fixes": [ + { + "artifactChanges": [ + { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/Hello.cpp", + "index": 1 + }, + "replacements": [ + { + "deletedRegion": { + "charOffset": 67 + }, + "insertedContent": { + "text": "static " + } + } + ] + } + ] + } + ] + }, + { + "ruleId": "clang-diagnostic-error", + "message": { + "text": "non-ASCII characters are not allowed outside of literals and identifiers" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/README.adoc", + "index": 2 + }, + "region": { + "charOffset": 385 + } + } + } + ], + "fixes": [ + { + "artifactChanges": [ + { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/README.adoc", + "index": 2 + }, + "replacements": [ + { + "deletedRegion": { + "charOffset": 385, + "charLength": 3 + } + } + ] + } + ] + } + ] + }, + { + "ruleId": "modernize-use-trailing-return-type", + "message": { + "text": "use a trailing return type for this function" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/main.cpp", + "index": 3 + }, + "region": { + "charOffset": 31 + } + } + } + ], + "fixes": [ + { + "artifactChanges": [ + { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/main.cpp", + "index": 3 + }, + "replacements": [ + { + "deletedRegion": { + "charOffset": 27, + "charLength": 3 + }, + "insertedContent": { + "text": "auto" + } + }, + { + "deletedRegion": { + "charOffset": 59 + }, + "insertedContent": { + "text": " -> int" + } + } + ] + } + ] + } + ] + }, + { + "ruleId": "misc-unused-parameters", + "message": { + "text": "parameter 'argc' is unused" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/main.cpp", + "index": 3 + }, + "region": { + "charOffset": 40 + } + } + } + ], + "fixes": [ + { + "artifactChanges": [ + { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/main.cpp", + "index": 3 + }, + "replacements": [ + { + "deletedRegion": { + "charOffset": 40, + "charLength": 4 + }, + "insertedContent": { + "text": " /*argc*/" + } + } + ] + } + ] + } + ] + }, + { + "ruleId": "misc-unused-parameters", + "message": { + "text": "parameter 'argv' is unused" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/main.cpp", + "index": 3 + }, + "region": { + "charOffset": 52 + } + } + } + ], + "fixes": [ + { + "artifactChanges": [ + { + "artifactLocation": { + "uri": "/home/lsp/projects/staticlib/src/main.cpp", + "index": 3 + }, + "replacements": [ + { + "deletedRegion": { + "charOffset": 52, + "charLength": 4 + }, + "insertedContent": { + "text": " /*argv*/" + } + } + ] + } + ] + } + ] + } + ], + "tool": { + "driver": { + "name": "Clang-Tidy", + "informationUri": "https://clang.llvm.org/extra/clang-tidy/", + "rules": [ + { + "id": "clang-diagnostic-error" + }, + { + "id": "readability-convert-member-functions-to-static", + "helpUri": "https://clang.llvm.org/extra/clang-tidy/checks/readability-convert-member-functions-to-static.html" + }, + { + "id": "modernize-use-trailing-return-type", + "helpUri": "https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-trailing-return-type.html" + }, + { + "id": "misc-unused-parameters", + "helpUri": "https://clang.llvm.org/extra/clang-tidy/checks/misc-unused-parameters.html" + } + ] + } + }, + "artifacts": [ + { + "location": { + "uri": "" + } + }, + { + "location": { + "uri": "/home/lsp/projects/staticlib/src/Hello.cpp" + } + }, + { + "location": { + "uri": "/home/lsp/projects/staticlib/src/README.adoc" + } + }, + { + "location": { + "uri": "/home/lsp/projects/staticlib/src/main.cpp" + } + } + ], + "columnKind": "utf16CodeUnits" + } + ] +} \ No newline at end of file diff --git a/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/Empty.yaml b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/Empty.yaml new file mode 100644 index 000000000..0e618913e --- /dev/null +++ b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/Empty.yaml @@ -0,0 +1,4 @@ +--- +MainSourceFile: '/home/lsp/projects/staticlib/src/Hello.cpp' +Diagnostics: [] +... diff --git a/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/InvalidResult.yaml b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/InvalidResult.yaml new file mode 100644 index 000000000..6e25c01f9 --- /dev/null +++ b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/InvalidResult.yaml @@ -0,0 +1,4 @@ +File,Line,Column,DefaultLevel,Level,Category,Name,Warning,Suggestion,Note,CWEs,Context,Fingerprint,ToolVersion,RuleId,HelpUri +test1.cpp,32,13,4,4,buffer,strcpy,Does not check for buffer overflows when copying to destination [MS-banned] (CWE-120),"Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)",,CWE-120," strcpy(tim, argv[0]);",2db56aa048ca3a81aaf1e24e9caeffab66b8ee8325382d5d92f0332be3045c46,2.0.15,FF1001,https://dwheeler.com/flawfinder#FF1001 +test2.cpp,31,17,2,2,buffer,char,"Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120)","Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length",,CWE-119!/CWE-120, char tim[256];,84c75bcb5ee170bf920db84570e2c58abee39ac26e0893e96dd88392b7e8f33a,2.0.15,FF1002,https://dwheeler.com/flawfinder#FF1002 +test3.cpp,56,21,4,4,buffer,strcpy,Does not check for buffer overflows when copying to destination [MS-banned] (CWE-120),"Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused)",,CWE-120," strcpy(tim, argv[0]);",2db56aa048ca3a81aaf1e24e9caeffab66b8ee8325382d5d92f0332be3045c46,2.0.15,FF1001,https://dwheeler.com/flawfinder#FF1001 diff --git a/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/ValidResults.yaml b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/ValidResults.yaml new file mode 100644 index 000000000..7fe44bbfe --- /dev/null +++ b/src/Test.UnitTests.Sarif.Converters/TestData/ClangTidy/Inputs/ValidResults.yaml @@ -0,0 +1,64 @@ +--- +MainSourceFile: '/home/lsp/projects/staticlib/src/Hello.cpp' +Diagnostics: + - DiagnosticName: clang-diagnostic-error + DiagnosticMessage: + Message: too many errors emitted, stopping now + FilePath: '' + FileOffset: 0 + Replacements: [] + - DiagnosticName: readability-convert-member-functions-to-static + DiagnosticMessage: + Message: 'method ''print'' can be made static' + FilePath: '/home/lsp/projects/staticlib/src/Hello.cpp' + FileOffset: 60 + Replacements: + - FilePath: '/home/lsp/projects/staticlib/include/static/Hello.h' + Offset: 67 + Length: 0 + ReplacementText: 'static ' + - DiagnosticName: clang-diagnostic-error + DiagnosticMessage: + Message: non-ASCII characters are not allowed outside of literals and identifiers + FilePath: '/home/lsp/projects/staticlib/src/README.adoc' + FileOffset: 385 + Replacements: + - FilePath: '/home/lsp/projects/staticlib/src/README.adoc' + Offset: 385 + Length: 3 + ReplacementText: '' + - DiagnosticName: modernize-use-trailing-return-type + DiagnosticMessage: + Message: use a trailing return type for this function + FilePath: '/home/lsp/projects/staticlib/src/main.cpp' + FileOffset: 31 + Replacements: + - FilePath: '/home/lsp/projects/staticlib/src/main.cpp' + Offset: 27 + Length: 3 + ReplacementText: auto + - FilePath: '/home/lsp/projects/staticlib/src/main.cpp' + Offset: 59 + Length: 0 + ReplacementText: ' -> int' + - DiagnosticName: misc-unused-parameters + DiagnosticMessage: + Message: 'parameter ''argc'' is unused' + FilePath: '/home/lsp/projects/staticlib/src/main.cpp' + FileOffset: 40 + Replacements: + - FilePath: '/home/lsp/projects/staticlib/src/main.cpp' + Offset: 40 + Length: 4 + ReplacementText: ' /*argc*/' + - DiagnosticName: misc-unused-parameters + DiagnosticMessage: + Message: 'parameter ''argv'' is unused' + FilePath: '/home/lsp/projects/staticlib/src/main.cpp' + FileOffset: 52 + Replacements: + - FilePath: '/home/lsp/projects/staticlib/src/main.cpp' + Offset: 52 + Length: 4 + ReplacementText: ' /*argv*/' +...