This repository has been archived by the owner on Dec 28, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from cake-contrib/feature/GH-1
(GH-1) Basic implementation
- Loading branch information
Showing
26 changed files
with
1,742 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | ||
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> | ||
<id>Cake.Prca.Issues.EsLint</id> | ||
<title>Cake.Prca.Issues.EsLint</title> | ||
<version>0.0.0</version> | ||
<authors>BBT Software AG</authors> | ||
<owners>bbtsoftware, pascalberger, cake-contrib</owners> | ||
<summary>ESLint support for the Pull Request Code Analysis Addin for Cake Build Automation System</summary> | ||
<description>The ESLint support for the Pull Request Code Analysis Addin for Cake allows you to write any issues logged by ESLint as comments to a pull request.</description> | ||
<licenseUrl>https://github.com/cake-contrib/Cake.Prca.Issues.EsLint/blob/develop/LICENSE</licenseUrl> | ||
<projectUrl>https://github.com/cake-contrib/Cake.Prca.Issues.EsLint</projectUrl> | ||
<iconUrl>https://raw.githubusercontent.com/cake-build/graphics/aba74fb4cb5fe9454381af2cc70c870088229d5c/png/cake-medium.png</iconUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<copyright>Copyright © 2017 BBT Software AG, Root/Zermatt, Switzerland</copyright> | ||
<tags>Cake Script PullRequest CodeAnalysis Cake-Prca-IssueProvider JavaScript Linting ESLint</tags> | ||
</metadata> | ||
<files> | ||
<file src="Cake.Prca.Issues.EsLint.dll" target="lib\net45" /> | ||
<file src="Cake.Prca.Issues.EsLint.pdb" target="lib\net45" /> | ||
<file src="Cake.Prca.Issues.EsLint.xml" target="lib\net45" /> | ||
</files> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<RuleSet Name="Ruleset for Cake.Prca.Issues.ESLint test cases" Description="Rules valid for Cake.Prca.Issues.ESLint test cases" ToolsVersion="14.0"> | ||
<Include Path="Cake.Prca.Issues.EsLint.ruleset" Action="Default" /> | ||
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers"> | ||
<Rule Id="SA1118" Action="None" /> | ||
<Rule Id="SA1652" Action="None" /> | ||
</Rules> | ||
</RuleSet> |
120 changes: 120 additions & 0 deletions
120
src/Cake.Prca.Issues.EsLint.Tests/Cake.Prca.Issues.EsLint.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{B1625322-FDA2-4E90-A403-8CE8C0748D09}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Cake.Prca.Issues.EsLint.Tests</RootNamespace> | ||
<AssemblyName>Cake.Prca.Issues.EsLint.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<CodeAnalysisRuleSet>..\Cake.Prca.Issues.EsLint.Tests.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<CodeAnalysisRuleSet>..\Cake.Prca.Issues.EsLint.Tests.ruleset</CodeAnalysisRuleSet> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Cake.Core, Version=0.16.2.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Cake.Core.0.16.2\lib\net45\Cake.Core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Cake.Prca, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Cake.Prca.0.3.0\lib\net45\Cake.Prca.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Cake.Testing, Version=0.16.2.0, Culture=neutral, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Cake.Testing.0.16.2\lib\net45\Cake.Testing.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Shouldly, Version=2.8.2.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Shouldly.2.8.2\lib\net451\Shouldly.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="ExceptionAssertExtensions.cs" /> | ||
<Compile Include="EsLintProviderFixture.cs" /> | ||
<Compile Include="EsLintProviderTests.cs" /> | ||
<Compile Include="EsLintRuleUrlResolverTests.cs" /> | ||
<Compile Include="EsLintSettingsTests.cs" /> | ||
<Compile Include="JsonFormatTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Cake.Prca.Issues.EsLint\Cake.Prca.Issues.EsLint.csproj"> | ||
<Project>{c6e0bc8d-6bd8-475e-a69f-ced3ffb86362}</Project> | ||
<Name>Cake.Prca.Issues.EsLint</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
<EmbeddedResource Include="Testfiles\jsonFormatWindows.json" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0\analyzers\dotnet\cs\Newtonsoft.Json.dll" /> | ||
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" /> | ||
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.0\analyzers\dotnet\cs\StyleCop.Analyzers.dll" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.2.0\build\net20\xunit.runner.visualstudio.props'))" /> | ||
</Target> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
48 changes: 48 additions & 0 deletions
48
src/Cake.Prca.Issues.EsLint.Tests/EsLintProviderFixture.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace Cake.Prca.Issues.EsLint.Tests | ||
{ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Core.Diagnostics; | ||
using Testing; | ||
|
||
public class EsLintProviderFixture | ||
{ | ||
public EsLintProviderFixture(string fileResourceName) | ||
{ | ||
this.Log = new FakeLog { Verbosity = Verbosity.Normal }; | ||
|
||
using (var stream = this.GetType().Assembly.GetManifestResourceStream("Cake.Prca.Issues.EsLint.Tests.Testfiles." + fileResourceName)) | ||
{ | ||
using (var sr = new StreamReader(stream)) | ||
{ | ||
this.Settings = | ||
EsLintSettings.FromContent( | ||
sr.ReadToEnd(), | ||
new JsonFormat(this.Log)); | ||
} | ||
} | ||
|
||
this.PrcaSettings = | ||
new ReportCodeAnalysisIssuesToPullRequestSettings(@"c:\Source\Cake.Prca"); | ||
} | ||
|
||
public FakeLog Log { get; set; } | ||
|
||
public EsLintSettings Settings { get; set; } | ||
|
||
public ReportCodeAnalysisIssuesToPullRequestSettings PrcaSettings { get; set; } | ||
|
||
internal EsLintProvider Create() | ||
{ | ||
var provider = new EsLintProvider(this.Log, this.Settings); | ||
provider.Initialize(this.PrcaSettings); | ||
return provider; | ||
} | ||
|
||
internal IEnumerable<ICodeAnalysisIssue> ReadIssues() | ||
{ | ||
var codeAnalysisProvider = this.Create(); | ||
return codeAnalysisProvider.ReadIssues(PrcaCommentFormat.PlainText); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace Cake.Prca.Issues.EsLint.Tests | ||
{ | ||
using System.Linq; | ||
using Core.IO; | ||
using Shouldly; | ||
using Testing; | ||
using Xunit; | ||
|
||
public class EsLintProviderTests | ||
{ | ||
public sealed class TheMsBuildCodeAnalysisProviderCtor | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Log_Is_Null() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => | ||
new EsLintProvider( | ||
null, | ||
EsLintSettings.FromContent( | ||
"Foo", | ||
new JsonFormat(new FakeLog())))); | ||
|
||
// Then | ||
result.IsArgumentNullException("log"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
var result = Record.Exception(() => | ||
new EsLintProvider( | ||
new FakeLog(), | ||
null)); | ||
|
||
// Then | ||
result.IsArgumentNullException("settings"); | ||
} | ||
} | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
src/Cake.Prca.Issues.EsLint.Tests/EsLintRuleUrlResolverTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
namespace Cake.Prca.Issues.EsLint.Tests | ||
{ | ||
using System; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
public class EsLintRuleUrlResolverTests | ||
{ | ||
public sealed class TheResolveRuleUrlMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Rule_Is_Null() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => EsLintRuleUrlResolver.Instance.ResolveRuleUrl(null)); | ||
|
||
// Then | ||
result.IsArgumentNullException("rule"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Rule_Is_Empty() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => EsLintRuleUrlResolver.Instance.ResolveRuleUrl(string.Empty)); | ||
|
||
// Then | ||
result.IsArgumentOutOfRangeException("rule"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_If_Rule_Is_WhiteSpace() | ||
{ | ||
// Given / When | ||
var result = Record.Exception(() => EsLintRuleUrlResolver.Instance.ResolveRuleUrl(" ")); | ||
|
||
// Then | ||
result.IsArgumentOutOfRangeException("rule"); | ||
} | ||
|
||
[Theory] | ||
[InlineData("no-unused-vars", "http://eslint.org/docs/rules/no-unused-vars")] | ||
[InlineData("no-await-in-loop", "http://eslint.org/docs/rules/no-await-in-loop")] | ||
public void Should_Resolve_Url(string rule, string expectedUrl) | ||
{ | ||
// Given | ||
var urlResolver = EsLintRuleUrlResolver.Instance; | ||
|
||
// When | ||
var ruleUrl = urlResolver.ResolveRuleUrl(rule); | ||
|
||
// Then | ||
ruleUrl.ToString().ShouldBe(expectedUrl); | ||
} | ||
|
||
[Fact] | ||
public void Should_Resolve_Url_From_Custom_Resolvers() | ||
{ | ||
// Given | ||
const string foo = "FOO123"; | ||
const string fooUrl = "http://foo.com/"; | ||
const string bar = "BAR123"; | ||
const string barUrl = "http://bar.com/"; | ||
var urlResolver = EsLintRuleUrlResolver.Instance; | ||
urlResolver.AddUrlResolver(x => x.Rule == foo ? new Uri(fooUrl) : null, 1); | ||
urlResolver.AddUrlResolver(x => x.Rule == bar ? new Uri(barUrl) : null, 1); | ||
|
||
// When | ||
var fooRuleUrl = urlResolver.ResolveRuleUrl(foo); | ||
var barRuleUrl = urlResolver.ResolveRuleUrl(bar); | ||
|
||
// Then | ||
fooRuleUrl.ToString().ShouldBe(fooUrl); | ||
barRuleUrl.ToString().ShouldBe(barUrl); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.