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

Adds does not apply to support to vs code extension. #290

Merged
merged 9 commits into from
Jun 8, 2021
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="Blazored.LocalStorage" Version="4.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.6" PrivateAssets="all" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.0.63" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.1.1" />
<PackageReference Include="morelinq" Version="3.3.2" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Tewr.Blazor.FileReader" Version="3.0.0.20340" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.4" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.4" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.0.63" />
<PackageReference Include="Microsoft.CST.RecursiveExtractor" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Sarif.Sdk" Version="2.4.8" />
<PackageReference Include="Sarif.Sdk" Version="2.4.9" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 2 additions & 4 deletions DevSkim-DotNet/Microsoft.DevSkim.CLI/Tester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,8 @@ private bool TestFile(string fileName)

// See if file name is a valid rule ID and preload default values
string defaultId = Path.GetFileNameWithoutExtension(fileName);
string[]? languages = null;
Rule fileRule = _rules.Select(x => x.DevSkimRule).FirstOrDefault(x => x.Id == defaultId);
if (fileRule != null)
languages = fileRule.AppliesTo;
Rule ?fileRule = _rules.Select(x => x.DevSkimRule).FirstOrDefault(x => x.Id == defaultId);
var languages = fileRule?.AppliesTo.ToArray() ?? Array.Empty<string>(); ;

// Load file header and content
string fileHeader = string.Empty;
Expand Down
8 changes: 4 additions & 4 deletions DevSkim-DotNet/Microsoft.DevSkim.CLI/Verifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ private void CheckIntegrity()
else
{
// Check for same ID
Rule sameRule = _rules.Select(x => x.DevSkimRule).FirstOrDefault(x => x.Id == rule.Id);
if (_rules.Count(x => x.DevSkimRule.Id == rule.Id) > 1)
Rule? sameRule = _rules.Select(x => x.DevSkimRule).FirstOrDefault(x => x.Id == rule.Id);
if (sameRule is { } && _rules.Count(x => x.DevSkimRule.Id == rule.Id) > 1)
{
_messages.Add(new ErrorMessage(Message: "Two or more rules have a same ID", RuleID: sameRule.Id, File: sameRule.Source, Warning: true));

_messages.Add(new ErrorMessage(Message: "Two or more rules have a same ID", RuleID: rule.Id, File: rule.Source, Warning: true));
}

}

if (rule.AppliesTo != null)
Expand Down Expand Up @@ -148,7 +148,7 @@ private bool LoadFile(string file)
{
RuleSet rules = new RuleSet();
bool noProblem = true;
rules.OnDeserializationError += delegate (object? sender, Newtonsoft.Json.Serialization.ErrorEventArgs e)
rules.OnDeserializationErrorEventHandler += delegate (object? sender, Newtonsoft.Json.Serialization.ErrorEventArgs e)
{
ErrorMessage message = new ErrorMessage(File: file,
Message: e.ErrorContext.Error.Message,
Expand Down
2 changes: 1 addition & 1 deletion DevSkim-DotNet/Microsoft.DevSkim.CLI/Writers/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void WriteIssue(IssueRecord issue)
if (_formatString.Contains("%m"))
item.Add("match", issue.TextSample);
if (_formatString.Contains("%T"))
item.Add("tags", issue.Issue.Rule.Tags ?? Array.Empty<string>());
item.Add("tags", issue.Issue.Rule.Tags);

// Store the result in the result list
jsonResult.Push(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void MapRuleToResult(Rule rule, ref Result resultItem)

resultItem.RuleId = rule.Id;
resultItem.Message = new Message() { Text = rule.Name };
foreach (string tag in rule.Tags ?? Array.Empty<string>())
foreach (string tag in rule.Tags)
{
resultItem.Tags.Add(tag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override void WriteIssue(IssueRecord issue)
output = output.Replace("%S", issue.Issue.Rule.Severity.ToString());
output = output.Replace("%D", issue.Issue.Rule.Description);
output = output.Replace("%m", issue.TextSample);
output = output.Replace("%T", string.Join(",", issue.Issue.Rule.Tags ?? Array.Empty<string>()));
output = output.Replace("%T", string.Join(",", issue.Issue.Rule.Tags));

TextWriter.WriteLine(output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.4" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.4" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 16 additions & 0 deletions DevSkim-DotNet/Microsoft.DevSkim.Tests/RuleProcessorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ namespace Microsoft.DevSkim.Tests
[ExcludeFromCodeCoverage]
public class RuleProcessorTest
{
[TestMethod]
public void BasicPass()
{
var rules = RuleSet.FromFile(Path.Combine("rules", "valid", "devskim-rules.json"));
RuleProcessor processor = new RuleProcessor(rules);
string testString = " sprintf(";

// Normal functionality test
Issue[] issues = processor.Analyze(testString, "c");
Assert.AreEqual(1, issues.Length);

// Non existent langugage
issues = processor.Analyze(testString, "");
Assert.AreEqual(0, issues.Length, "Match.Success should be false, when no language is passed");
}

[TestMethod]
public void IsMatch_FalseTest()
{
Expand Down
6 changes: 3 additions & 3 deletions DevSkim-DotNet/Microsoft.DevSkim.Tests/UseCaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public void UseCase_ManualReview_Test()
Assert.AreEqual(2, issues[0].Boundary.Index, "QUICKFIX invalid index");
Assert.AreEqual(8, issues[0].Boundary.Length, "QUICKFIX invalid length ");
Assert.AreEqual("DS276209", issues[0].Rule.Id, "QUICKFIX invalid rule");
Assert.AreEqual(0, issues[0].Rule.Fixes.Length, "QUICKFIX invalid Fixes");
Assert.AreEqual(0, issues[0].Rule.Fixes.Count, "QUICKFIX invalid Fixes");
Assert.AreEqual("my rules", issues[0].Rule.RuntimeTag, "QUICKFIX invalid tag");
}

Expand All @@ -289,7 +289,7 @@ public void UseCase_Normal_Test()
Assert.AreEqual("DS185832", issues[0].Rule.Id, "strcpy invalid rule");

// Fix it test
Assert.AreNotEqual(issues[0].Rule.Fixes.Length, 0, "strcpy invalid Fixes");
Assert.AreNotEqual(issues[0].Rule.Fixes.Count, 0, "strcpy invalid Fixes");
CodeFix fix = issues[0].Rule.Fixes[0];
string fixedCode = RuleProcessor.Fix(testString, fix);
Assert.AreEqual("strcpy_s(dest, <size of dest>, src);", fixedCode, "strcpy invalid code fix");
Expand All @@ -302,7 +302,7 @@ public void UseCase_OnError_Test()
bool error = false;

RuleSet rules = new RuleSet();
rules.OnDeserializationError += delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
rules.OnDeserializationErrorEventHandler += delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
{
error = true;
args.ErrorContext.Handled = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform">
<Version>16.9.4</Version>
<Version>16.10.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.CoreUtility">
<Version>16.10.44</Version>
<Version>16.10.230</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
<Version>12.0.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Threading;

namespace Microsoft.DevSkim.VSExtension
Expand Down Expand Up @@ -62,7 +63,7 @@ internal void AddTagger(DevSkimTagger tagger)

_provider.AddSkimChecker(this);

this.KickUpdate();
KickUpdate();
}
}

Expand Down Expand Up @@ -181,7 +182,7 @@ private void KickUpdate()
{
_isUpdating = true;
// TODO: Improve this
_uiThreadDispatcher.BeginInvoke(new Action(() => this.DoUpdate()), DispatcherPriority.Background);
_uiThreadDispatcher.BeginInvoke(new Action(() => this.DoUpdate()), DispatcherPriority.Background);
}
}

Expand Down Expand Up @@ -226,7 +227,7 @@ private void OnBufferChange(object sender, TextContentChangedEventArgs e)
// Start processing the dirty spans (which no-ops if we're already doing it).
if (_dirtySpans.Count != 0)
{
this.KickUpdate();
KickUpdate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,19 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.ComponentModelHost">
<Version>16.9.227</Version>
<Version>16.10.230</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.CoreUtility">
<Version>16.10.44</Version>
<Version>16.10.230</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Imaging">
<Version>16.9.31024.71</Version>
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Language.Intellisense">
<Version>16.9.227</Version>
<Version>16.10.230</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Language.StandardClassification">
<Version>16.9.227</Version>
<Version>16.10.230</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.RemoteControl">
<Version>16.3.32</Version>
Expand All @@ -209,48 +209,48 @@
<Version>15.0.36</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0">
<Version>16.9.31025.104</Version>
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Framework">
<Version>16.9.31024.71</Version>
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.10.0">
<Version>16.9.31024.71</Version>
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.11.0">
<Version>16.9.31024.71</Version>
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.12.0">
<Version>16.9.31024.71</Version>
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Immutable.14.0">
<Version>16.9.31024.71</Version>
<Version>16.10.31321.278</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.12.0">
<Version>16.9.31023.347</Version>
<Version>16.10.31320.204</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.9.0">
<Version>16.9.31023.347</Version>
<Version>16.10.31320.204</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Telemetry">
<Version>16.3.176</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Text.Data">
<Version>16.9.227</Version>
<Version>16.10.230</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf">
<Version>16.9.227</Version>
<Version>16.10.230</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading">
<Version>16.9.60</Version>
<Version>16.10.56</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers">
<Version>16.9.60</Version>
<Version>16.10.56</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>16.9.1050</Version>
<Version>17.0.1600</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -261,10 +261,10 @@
<Version>2.7.74</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="StreamJsonRpc">
<Version>2.7.76</Version>
<Version>2.8.21</Version>
</PackageReference>
<PackageReference Include="System.Collections.Immutable">
<Version>5.0.0</Version>
Expand Down
4 changes: 2 additions & 2 deletions DevSkim-DotNet/Microsoft.DevSkim/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace Microsoft.DevSkim
{
public class Location
{
public int Column { get; set; } = 0;
public int Line { get; set; } = 0;
public int Column { get; set; }
public int Line { get; set; }
}
}
10 changes: 3 additions & 7 deletions DevSkim-DotNet/Microsoft.DevSkim/Microsoft.DevSkim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CST.OAT" Version="1.0.84" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.CST.OAT" Version="1.0.88" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup>
Expand All @@ -48,7 +44,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.4.194" />
<PackageReference Update="Nerdbank.GitVersioning" Version="3.4.205" />
</ItemGroup>

</Project>
Loading