Skip to content

Commit

Permalink
Switch match references to camelCase. (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
scovetta authored Jun 22, 2022
1 parent 08a67bb commit 9f33c68
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 96 deletions.
30 changes: 15 additions & 15 deletions AppInspector.CLI/html/resources/js/appinspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ class TemplateInsertion {
}
});

$('#s_pi_application_name').html(this.mt.applicationName);
$('#s_pi_version').html(this.mt.sourceVersion);
$('#s_pi_description').html(this.mt.description || 'No description available.');
$('#s_pi_source_path').html(this.mt.sourcePath);
$('#s_pi_author').html(this.mt.authors || 'No author found.');
$('#s_pi_date_scanned').html(this.mt.dateScanned);
$('#s_pi_application_name').text(this.mt.applicationName);
$('#s_pi_version').text(this.mt.sourceVersion);
$('#s_pi_description').text(this.mt.description || 'No description available.');
$('#s_pi_source_path').text(this.mt.sourcePath);
$('#s_pi_author').text(this.mt.authors || 'No author found.');
$('#s_pi_date_scanned').text(this.mt.dateScanned);
}

combineConfidence(a, b) {
Expand Down Expand Up @@ -170,23 +170,23 @@ class TemplateInsertion {
};

for (let match of $this.md) {
let excerpt = (match.Excerpt || '') || match.Sample;
if (match.RuleId === ruleId || match.RuleName === ruleId) {
let excerpt = (match.excerpt || '') || match.sample;
if (match.ruleId === ruleId || match.ruleName === ruleId) {
let $li = $('<li>');
let $a = $('<a>');
let $l = match.StartLocationLine;
let $e = match.EndLocationLine;
let $l = match.startLocationLine;
let $e = match.endLocationLine;
if ($l <= 0) $l = 1; //fix #183
$a.addClass('content-link')
.attr('href', '#')
.data('excerpt', excerpt)
.data('startLocationLine', $l)
.data('endLocationLine', $e)
.text(removePrefix(match.FileName));
.text(removePrefix(match.fileName));
$li.append($a);
$('#file_listing_modal ul').append($li);

$('#match-line-number').text('Line number: ' + match.StartLocationLine.toString());
$('#match-line-number').text('Line number: ' + match.startLocationLine.toString());
}
}
$('#file_listing_modal').on('shown.bs.modal', function (e) {
Expand Down Expand Up @@ -229,7 +229,7 @@ class TemplateInsertion {
// a tag that matches what we're looking for, we'll keep that icon visible.
search_loop:
for (let match of this.md) {
for (let tag of match.Tags) {
for (let tag of match.tags) {
if (targetRegex.exec(tag)) {
foundTag = true; // We have at least one match for this icon
break search_loop;
Expand Down Expand Up @@ -290,9 +290,9 @@ class TemplateInsertion {
const targetRegex = new RegExp(targetRegexValue, 'i');
let identifiedRules = {};
for (let match of this.md) {
for (let tag of match.Tags) {
for (let tag of match.tags) {
if (targetRegex.exec(tag)) {
identifiedRules[match.RuleName] = this.combineConfidence(identifiedRules[match.RuleName], match.Confidence);
identifiedRules[match.ruleName] = this.combineConfidence(identifiedRules[match.ruleName], match.confidence);
break; // Only break out of inner loop, we only need one match per tag set
}
}
Expand Down
4 changes: 2 additions & 2 deletions AppInspector.Tests/Commands/TestExportTagsCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class TestExportTagsCmd
private LogOptions logOptions = new();
private ILoggerFactory factory = new NullLoggerFactory();

[TestInitialize]
[ClassInitialize]
public void InitOutput()
{
factory = logOptions.GetLoggerFactory();
Expand All @@ -27,7 +27,7 @@ public void InitOutput()
File.WriteAllText(testRulesPath, findWindows);
}

[TestCleanup]
[ClassCleanup]
public void CleanUp()
{
Directory.Delete(TestHelpers.GetPath(TestHelpers.AppPath.testOutput), true);
Expand Down
2 changes: 1 addition & 1 deletion AppInspector.Tests/Commands/TestTagDiffCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void InitOutput()
File.WriteAllText(testRulesPath, findWindows);
}

[TestCleanup]
[ClassCleanup]
public void CleanUp()
{
Directory.Delete(TestHelpers.GetPath(TestHelpers.AppPath.testOutput), true);
Expand Down
4 changes: 2 additions & 2 deletions AppInspector.Tests/Commands/TestVerifyRulesCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class TestVerifyRulesCmd
private string _validRulesPath = string.Empty;
private LogOptions _logOptions = new();
private ILoggerFactory _factory = new NullLoggerFactory();
[TestInitialize]
[ClassCleanup]
public void InitOutput()
{
_factory = _logOptions.GetLoggerFactory();
Expand All @@ -28,7 +28,7 @@ public void InitOutput()
File.WriteAllText(_validRulesPath, _validRules);
}

[TestCleanup]
[ClassCleanup]
public void CleanUp()
{
Directory.Delete(TestHelpers.GetPath(TestHelpers.AppPath.testOutput), true);
Expand Down
7 changes: 4 additions & 3 deletions AppInspector.Tests/Languages/LanguagesTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Text.Json;

using Microsoft.ApplicationInspector.Logging;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Serilog.Events;

namespace AppInspector.Tests.Languages
Expand Down Expand Up @@ -72,8 +73,8 @@ public void DetectCustomLanguage()
[TestMethod]
public void EmptyLanguagesOnInvalidCommentsAndLanguages()
{
Assert.ThrowsException<JsonException>(() => Microsoft.ApplicationInspector.RulesEngine.Languages.FromConfigurationFiles(_factory, invalidTestCommentsPath, null));
Assert.ThrowsException<JsonException>(() => Microsoft.ApplicationInspector.RulesEngine.Languages.FromConfigurationFiles(_factory, null, invalidTestLanguagesPath));
Assert.ThrowsException<JsonSerializationException>(() => Microsoft.ApplicationInspector.RulesEngine.Languages.FromConfigurationFiles(_factory, invalidTestCommentsPath, null));
Assert.ThrowsException<JsonSerializationException>(() => Microsoft.ApplicationInspector.RulesEngine.Languages.FromConfigurationFiles(_factory, null, invalidTestLanguagesPath));
}

[TestMethod]
Expand Down
1 change: 0 additions & 1 deletion AppInspector/AppInspector.Commands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<PackageReference Include="ShellProgressBar" Version="5.2.0" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="6.0.1" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />

</ItemGroup>

Expand Down
11 changes: 6 additions & 5 deletions AppInspector/Commands/VerifyRulesCommand.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using System.Text.Json.Serialization;
using Microsoft.ApplicationInspector.RulesEngine.OatExtensions;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Microsoft.ApplicationInspector.Commands
{
Expand All @@ -11,7 +12,7 @@ namespace Microsoft.ApplicationInspector.Commands
using Microsoft.CST.OAT;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using System.Text.Json;

using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -36,18 +37,18 @@ public class RuleStatus

public class VerifyRulesResult : Result
{
[Newtonsoft.Json.JsonConverter(typeof(JsonStringEnumConverter))]
[Newtonsoft.Json.JsonConverter(typeof(StringEnumConverter))]
public enum ExitCode
{
Verified = 0,
NotVerified = 1,
CriticalError = Utils.ExitCode.CriticalError
}

[JsonPropertyName("resultCode")]
[JsonProperty(PropertyName ="resultCode")]
public ExitCode ResultCode { get; set; }

[JsonPropertyName("ruleStatusList")]
[JsonProperty(PropertyName ="ruleStatusList")]
public List<RuleStatus> RuleStatusList { get; set; }

public VerifyRulesResult()
Expand Down
2 changes: 1 addition & 1 deletion RulesEngine/AppInspector.RulesEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageReference Include="Microsoft.CST.OAT" Version="1.2.15" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.1.11" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
<PackageReference Include="System.Text.Json" Version="6.0.5" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />

</ItemGroup>

Expand Down
10 changes: 5 additions & 5 deletions RulesEngine/Comment.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright(C) Microsoft.All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using System.Text.Json.Serialization;
using Newtonsoft.Json;

namespace Microsoft.ApplicationInspector.RulesEngine
{
Expand All @@ -10,16 +10,16 @@ namespace Microsoft.ApplicationInspector.RulesEngine
/// </summary>
internal class Comment
{
[JsonPropertyName("language")]
[JsonProperty(PropertyName ="language")]
public string[]? Languages { get; set; }

[JsonPropertyName("inline")]
[JsonProperty(PropertyName ="inline")]
public string? Inline { get; set; }

[JsonPropertyName("prefix")]
[JsonProperty(PropertyName ="prefix")]
public string? Prefix { get; set; }

[JsonPropertyName("suffix")]
[JsonProperty(PropertyName ="suffix")]
public string? Suffix { get; set; }
}
}
5 changes: 3 additions & 2 deletions RulesEngine/Confidence.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Microsoft.ApplicationInspector.RulesEngine
{
using System;

[Flags]
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonConverter(typeof(StringEnumConverter))]
public enum Confidence { Unspecified = 0, Low = 1, Medium = 2, High = 4 }
}
13 changes: 7 additions & 6 deletions RulesEngine/LanguageInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright(C) Microsoft.All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.

using System.Text.Json.Serialization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Microsoft.ApplicationInspector.RulesEngine
{
Expand All @@ -12,17 +13,17 @@ public class LanguageInfo
{
public enum LangFileType { Code, Build };

[JsonPropertyName("name")]
[JsonProperty(PropertyName ="name")]
public string Name { get; set; } = "";

[JsonPropertyName("extensions")]
[JsonProperty(PropertyName ="extensions")]
public string[]? Extensions { get; set; }

[JsonPropertyName("file-names")]
[JsonProperty(PropertyName ="file-names")]
public string[]? FileNames { get; set; }

[JsonPropertyName("type")]
[JsonConverter(typeof(JsonStringEnumConverter))]
[JsonProperty(PropertyName ="type")]
[JsonConverter(typeof(StringEnumConverter))]
public LangFileType Type { get; set; } = LangFileType.Code;
}
}
15 changes: 12 additions & 3 deletions RulesEngine/Languages.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (C) Microsoft. All rights reserved. Licensed under the MIT License.

using Newtonsoft.Json;

namespace Microsoft.ApplicationInspector.RulesEngine
{
using Microsoft.Extensions.Logging;
Expand All @@ -10,7 +12,7 @@ namespace Microsoft.ApplicationInspector.RulesEngine
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.Json;


/// <summary>
/// Helper class for language based commenting
Expand All @@ -28,14 +30,18 @@ public Languages(ILoggerFactory? loggerFactory = null, Stream? commentsStream =
_logger = loggerFactory?.CreateLogger<Languages>() ?? new NullLogger<Languages>();
Assembly assembly = typeof(Languages).Assembly;
Stream? commentResource = commentsStream ?? assembly.GetManifestResourceStream(CommentResourcePath);

if (commentResource is null)
{
_logger.LogError("Failed to load embedded comments configuration from {CommentResourcePath}", CommentResourcePath);
_comments = new List<Comment>();
}
else
{
_comments = JsonSerializer.Deserialize<List<Comment>>(commentResource) ?? new List<Comment>();
using StreamReader commentStreamReader = new(commentResource);
using JsonReader commentJsonReader = new JsonTextReader(commentStreamReader);
JsonSerializer jsonSerializer = new();
_comments = jsonSerializer.Deserialize<List<Comment>>(commentJsonReader) ?? new List<Comment>();
}

Stream? languagesResource = languagesStream ?? assembly.GetManifestResourceStream(LanguagesResourcePath);
Expand All @@ -46,7 +52,10 @@ public Languages(ILoggerFactory? loggerFactory = null, Stream? commentsStream =
}
else
{
_languageInfos = JsonSerializer.Deserialize<List<LanguageInfo>>(languagesResource) ?? new List<LanguageInfo>();
using StreamReader languagesStreamReader = new(languagesResource);
using JsonReader languagesJsonReader = new JsonTextReader(languagesStreamReader);
JsonSerializer jsonSerializer = new();
_languageInfos = jsonSerializer.Deserialize<List<LanguageInfo>>(languagesJsonReader) ?? new List<LanguageInfo>();
}
}

Expand Down
Loading

0 comments on commit 9f33c68

Please sign in to comment.