Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforcing file normalization #2116

Merged
merged 9 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 5 additions & 3 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ tab_width = 4

# New line preferences
end_of_line = crlf
insert_final_newline = false
insert_final_newline = true

#### .NET Coding Conventions ####

# Organize usings
dotnet_separate_import_directive_groups = true:error
dotnet_sort_system_directives_first = true:error
dotnet_separate_import_directive_groups = true
dotnet_sort_system_directives_first = true

# this. and Me. preferences
dotnet_style_qualification_for_field = true:silent
Expand Down Expand Up @@ -203,3 +203,5 @@ dotnet_diagnostic.CS1574.severity = silent
dotnet_diagnostic.CS1591.severity = silent
dotnet_diagnostic.CS1712.severity = silent
dotnet_diagnostic.CS1734.severity = silent

file_header_template = Copyright (c) Microsoft. All rights reserved.\nLicensed under the MIT license. See LICENSE file in the project root for full license information.
3 changes: 3 additions & 0 deletions src/Samples/Sarif.Sdk.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
using System.Collections.Generic;
using System.IO;
using System.Text;

using CommandLine;

using Microsoft.CodeAnalysis.Sarif;
using Microsoft.CodeAnalysis.Sarif.Writers;

using Newtonsoft.Json;

namespace Sarif.Sdk.Sample
Expand Down
2 changes: 2 additions & 0 deletions src/Samples/Sarif.WorkItems.Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;

using Microsoft.CodeAnalysis.Sarif;
using Microsoft.CodeAnalysis.Sarif.Baseline;
using Microsoft.CodeAnalysis.Sarif.WorkItemFiling;

using Newtonsoft.Json;

namespace Sarif.WorkItems.Sample
Expand Down
14 changes: 8 additions & 6 deletions src/Samples/SarifDeferredSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Microsoft.CodeAnalysis.Sarif;
using Microsoft.CodeAnalysis.Sarif.Readers;
using Newtonsoft.Json;
using System;
using System;
using System.Diagnostics;
using System.IO;

using Microsoft.CodeAnalysis.Sarif;
using Microsoft.CodeAnalysis.Sarif.Readers;

using Newtonsoft.Json;

namespace SarifDeferredSample
{
/// <summary>
Expand All @@ -18,7 +20,7 @@ private static void Main(string[] args)
{
bool deferred = bool.Parse(args[0]);
string filePath = args[1];

SarifLog log = null;

Console.WriteLine($"Loading {filePath}{(deferred ? " (deferred)" : "")}...");
Expand Down Expand Up @@ -85,7 +87,7 @@ private static void Main(string[] args)
// uriLengthTotal += file?.ArtifactLocation?.Uri?.OriginalString?.Length ?? 0;
// fileCount++;
//}
}
}

return $"Enumerated {fileCount:n0} Files, URI total {uriLengthTotal / BytesPerMB:n0}MB.";
});
Expand Down
2 changes: 1 addition & 1 deletion src/Samples/SarifToCsv/CsvWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,4 @@ public void Dispose()
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Samples/SarifToCsv/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ private static string ValueOrDefault(string value, string defaultValue)
return String.IsNullOrEmpty(value) ? defaultValue : value;
}
}
}
}
3 changes: 2 additions & 1 deletion src/Samples/SarifToCsv/SarifCsvColumnWriters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;

using Microsoft.CodeAnalysis.Sarif;

using Newtonsoft.Json;

namespace SarifToCsv
Expand Down Expand Up @@ -67,7 +68,7 @@ public static Action<WriteContext> GetWriter(string columnName)
{
value = "";
}

c.Writer.Write(value);
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/Samples/SarifToCsv/SdkExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ public static string FileUri(this ArtifactLocation artifactLocation, Run run)
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Sarif.Converters/AndroidStudioConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,4 @@ private static bool RemoveBadRoot(string path, out Uri uri)
return removedBadRoot;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Sarif.Converters/ClangAnalyzerConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,4 @@ private static class ClangSchemaStrings
public const string VersionName = "version";
}
}
}
}
4 changes: 3 additions & 1 deletion src/Sarif.Converters/ContrastSecurityConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;

using Microsoft.CodeAnalysis.Sarif.Writers;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

Expand Down Expand Up @@ -1684,4 +1686,4 @@ private void ReadProps(SparseReader reader, object parent)
_readingProps = false;
}
}
}
}
5 changes: 3 additions & 2 deletions src/Sarif.Converters/FlawFinderCsvConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.IO;
using System.Linq;

using CsvHelper;

namespace Microsoft.CodeAnalysis.Sarif.Converters
Expand All @@ -26,7 +27,7 @@ public override void Convert(Stream input, IResultLogWriter output, OptionallyEm

IList<FlawFinderCsvResult> flawFinderCsvResults = csvReader.GetRecords<FlawFinderCsvResult>().ToList();

IList <ReportingDescriptor> rules = ExtractRules(flawFinderCsvResults);
IList<ReportingDescriptor> rules = ExtractRules(flawFinderCsvResults);
IList<Result> results = ExtractResults(flawFinderCsvResults);

var run = new Run
Expand Down Expand Up @@ -134,6 +135,6 @@ private static Region RegionFromFlawFinderCsvResult(FlawFinderCsvResult flawFind
};

private static FailureLevel SarifLevelFromFlawFinderLevel(int flawFinderLevel) =>
flawFinderLevel< 4 ? FailureLevel.Warning : FailureLevel.Error;
flawFinderLevel < 4 ? FailureLevel.Warning : FailureLevel.Error;
}
}
18 changes: 9 additions & 9 deletions src/Sarif.Converters/FortifyFprConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Micro soft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand Down Expand Up @@ -32,7 +32,7 @@ internal class FortifyFprConverter : ToolFileConverterBase
"LastTraceLocation.file",
"LastTraceLocation.line",
"PrimaryCall.name",
"PrimaryLocation.file",
"PrimaryLocation.file",
"PrimaryLocation.line",
"PrimaryTransitionFunction.name",
"SinkFunction",
Expand Down Expand Up @@ -600,18 +600,18 @@ private string NormalizeGuid(string guid)

private static string RemoveSpaces(string ruleComponent)
{
Tuple<string, string>[] lowercasedTokens = new []
Tuple<string, string>[] lowercasedTokens = new[]
{
new Tuple<string, string>(" in ", " In "),
new Tuple<string, string>(" true ", " True "),
new Tuple<string, string>(" false ", " False "),
new Tuple<string, string>(" against ", " Against "),
};

foreach(Tuple<string, string> lowercasedToken in lowercasedTokens)
foreach (Tuple<string, string> lowercasedToken in lowercasedTokens)
{
ruleComponent = ruleComponent.Replace(lowercasedToken.Item1, lowercasedToken.Item2);
}
}
return ruleComponent.Replace(" ", "");
}

Expand Down Expand Up @@ -1009,7 +1009,7 @@ private void ParseRuleDescriptions()

private void ParseEngineVersion()
{
_engineVersion = _reader.ReadElementContentAsString();
_engineVersion = _reader.ReadElementContentAsString();
}

private void ParseNodes()
Expand Down Expand Up @@ -1195,7 +1195,7 @@ private void ParseCommandLine()
_invocation.CommandLine = sb.ToString();
}


private void ParseErrors()
{
// Despite being expressed as XML elements named <Error>, these messages
Expand Down Expand Up @@ -1326,7 +1326,7 @@ private void AddMessagesToResult(Result result)
else
{
// Replace the token with plain text.
messageText = messageText.Replace(string.Format(ReplacementTokenFormat, key), "'"+ value + "'");
messageText = messageText.Replace(string.Format(ReplacementTokenFormat, key), "'" + value + "'");
}
}
}
Expand Down Expand Up @@ -1417,4 +1417,4 @@ public Node(ThreadFlowLocation tfl, string snippetId)
}
}
}
}
}
4 changes: 2 additions & 2 deletions src/Sarif.Converters/FortifyUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ internal static string ParseFormattedContentText(string content)
content = Regex.Replace(content, pattern, FormattedTextReplacements[pattern], RegexOptions.Compiled);
}

foreach(Match match in s_replaceKeyRegex.Matches(content))
foreach (Match match in s_replaceKeyRegex.Matches(content))
{
string key = match.Groups[1].Value;
content = content.Replace(string.Format(ReplacementTokenFormat, key), "{"+ key + "}");
content = content.Replace(string.Format(ReplacementTokenFormat, key), "{" + key + "}");
}

return content.Trim(new[] { '\r', '\n', ' ' });
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Converters/FxCopConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,4 +1083,4 @@ internal static string MakeExceptionMessage(string kind, string checkId, string
}
}
}
}
}
7 changes: 5 additions & 2 deletions src/Sarif.Converters/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Diagnostics.CodeAnalysis;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

[module: SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Scope = "member", Target = "Microsoft.CodeAnalysis.Sarif.Converters.AndroidStudioConverter.#Convert(System.IO.Stream,Microsoft.CodeAnalysis.Sarif.IResultLogWriter,Microsoft.CodeAnalysis.Sarif.Writers.LoggingOptions)")]
[module: SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Scope = "member", Target = "Microsoft.CodeAnalysis.Sarif.Converters.ClangAnalyzerConverter.#Convert(System.IO.Stream,Microsoft.CodeAnalysis.Sarif.IResultLogWriter,Microsoft.CodeAnalysis.Sarif.Writers.LoggingOptions)")]
Expand All @@ -7,4 +10,4 @@
[module: SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Scope = "member", Target = "Microsoft.CodeAnalysis.Sarif.Converters.FortifyFprConverter.#ParseAuditStream(System.IO.Stream)")]
[module: SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Scope = "member", Target = "Microsoft.CodeAnalysis.Sarif.Converters.FxCopLogReader.#Read(Microsoft.CodeAnalysis.Sarif.Converters.FxCopLogReader+Context,System.IO.Stream)")]
[module: SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Scope = "member", Target = "Microsoft.CodeAnalysis.Sarif.Converters.PREfastConverter.#Convert(System.IO.Stream,Microsoft.CodeAnalysis.Sarif.IResultLogWriter,Microsoft.CodeAnalysis.Sarif.Writers.LoggingOptions)")]
[module: SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Scope = "member", Target = "Microsoft.CodeAnalysis.Sarif.Converters.SparseReader.#CreateFromStream(Microsoft.CodeAnalysis.Sarif.Converters.SparseReaderDispatchTable,System.IO.Stream,System.Xml.Schema.XmlSchemaSet)")]
[module: SuppressMessage("Microsoft.Security.Xml", "CA3053:UseXmlSecureResolver", Scope = "member", Target = "Microsoft.CodeAnalysis.Sarif.Converters.SparseReader.#CreateFromStream(Microsoft.CodeAnalysis.Sarif.Converters.SparseReaderDispatchTable,System.IO.Stream,System.Xml.Schema.XmlSchemaSet)")]
2 changes: 1 addition & 1 deletion src/Sarif.Converters/LogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ public TLog ReadLog(string input, Encoding encoding)

public abstract TLog ReadLog(Stream input);
}
}
}
2 changes: 1 addition & 1 deletion src/Sarif.Converters/MSBuildConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,4 @@ private static Region GetRegionFrom(string regionString)
return region;
}
}
}
}
5 changes: 4 additions & 1 deletion src/Sarif.Converters/PREFastObjectModel/Defect.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Xml.Serialization;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Xml.Serialization;

namespace Microsoft.CodeAnalysis.Sarif.Converters.PREFastObjectModel
{
Expand Down
5 changes: 4 additions & 1 deletion src/Sarif.Converters/PREFastObjectModel/DefectList.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
// 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;
using System.Xml.Serialization;

namespace Microsoft.CodeAnalysis.Sarif.Converters.PREFastObjectModel
Expand Down
5 changes: 4 additions & 1 deletion src/Sarif.Converters/PREFastObjectModel/KeyEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Xml.Serialization;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Xml.Serialization;

namespace Microsoft.CodeAnalysis.Sarif.Converters.PREFastObjectModel
{
Expand Down
5 changes: 4 additions & 1 deletion src/Sarif.Converters/PREFastObjectModel/PREFastPath.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
// 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;
using System.Xml.Serialization;

namespace Microsoft.CodeAnalysis.Sarif.Converters.PREFastObjectModel
Expand Down
5 changes: 4 additions & 1 deletion src/Sarif.Converters/PREFastObjectModel/SFA.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Xml.Serialization;
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Xml.Serialization;

namespace Microsoft.CodeAnalysis.Sarif.Converters.PREFastObjectModel
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Converters/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
1 change: 1 addition & 0 deletions src/Sarif.Converters/PylintConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;

using Microsoft.CodeAnalysis.Sarif.Converters.PylintObjectModel;

namespace Microsoft.CodeAnalysis.Sarif.Converters
Expand Down
2 changes: 1 addition & 1 deletion src/Sarif.Converters/PylintObjectModel/PylintLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ namespace Microsoft.CodeAnalysis.Sarif.Converters.PylintObjectModel
public class PylintLog : List<PylintLogEntry>
{
}
}
}
3 changes: 2 additions & 1 deletion src/Sarif.Converters/PylintObjectModel/PylintLogReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.IO;

using Newtonsoft.Json;

namespace Microsoft.CodeAnalysis.Sarif.Converters.PylintObjectModel
Expand All @@ -20,4 +21,4 @@ public override PylintLog ReadLog(Stream input)
return JsonConvert.DeserializeObject<PylintLog>(pylintText);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Sarif.Converters/SparseReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,4 +342,4 @@ private void ReadEndElement(string expectedTagName)
_xmlReader.MoveToContent();
}
}
}
}
1 change: 1 addition & 0 deletions src/Sarif.Converters/TSLintConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.CodeAnalysis.Sarif.Converters.TSLintObjectModel;

namespace Microsoft.CodeAnalysis.Sarif.Converters
Expand Down
Loading