-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-5) added warning CCG0005 for not referencing StyleCop.Analyzers
- Loading branch information
Showing
21 changed files
with
400 additions
and
39 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,42 @@ | ||
--- | ||
Order: 3 | ||
Title: Recommended References | ||
--- | ||
|
||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
## Table of Contents | ||
|
||
- [Goals](#goals) | ||
- [Related rules](#related-rules) | ||
- [Usage](#usage) | ||
- [Settings](#settings) | ||
- [Opt-Out](#opt-out) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
## Goals | ||
|
||
To have consistency in code-style among the different tools/plugins the use of Analysers is recommended, especially the use of [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). | ||
|
||
## Related rules | ||
|
||
* [CCG0005](../rules/ccg0005) | ||
|
||
## Usage | ||
|
||
Using this package automatically enables this guideline. | ||
|
||
## Settings | ||
|
||
### Opt-Out | ||
|
||
It it possible to opt-out of the check for StyleCop using the following setting: | ||
|
||
(*Keep in mind, though that it is not recommended to opt-out of this feature*) | ||
|
||
```xml | ||
<ItemGroup> | ||
<CakeContribGuidelinesOmitRecommendedReference Include="StyleCop.Analyzers" /> | ||
</ItemGroup> | ||
``` |
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,35 @@ | ||
--- | ||
Order: 5 | ||
Title: CCG0005 | ||
Description: Usage of analysers is recommended | ||
--- | ||
|
||
> No reference to `StyleCop.Analyzers` found. Usage of `StyleCop.Analyzers` is strongly recommended. | ||
<!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | ||
## Table of Contents | ||
|
||
- [Cause](#cause) | ||
- [Description](#description) | ||
- [How to fix violations](#how-to-fix-violations) | ||
- [Related guidelines](#related-guidelines) | ||
|
||
<!-- END doctoc generated TOC please keep comment here to allow auto update --> | ||
|
||
## Cause | ||
|
||
This warning is raised, when the recommended analyser [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers) is not referenced. | ||
|
||
## Description | ||
|
||
Usage of [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers) is recommended. | ||
|
||
## How to fix violations | ||
|
||
Add a reference to [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers). | ||
(Or opt-out of this rule, by setting `CakeContribGuidelinesOmitRecommendedReference`) | ||
|
||
## Related guidelines | ||
|
||
* [Usage of Analysers](../guidelines/Analysers) |
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
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
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
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
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
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
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,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageIcon>$(CakeContribGuidelinesIconDestinationLocation)</PackageIcon> | ||
<PackageIconUrl>https://project/path/to/icon</PackageIconUrl> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,6 @@ | ||
{ | ||
"description": "not referencing StyleCop.Analyzers yields a warning", | ||
"exitCode": 0, | ||
"errors": [], | ||
"warnings": [ "CCG0005" ] | ||
} |
12 changes: 12 additions & 0 deletions
12
e2e-tests/CCG0005/OmittingStyleCop/OmittingStyleCop.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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<PackageIcon>$(CakeContribGuidelinesIconDestinationLocation)</PackageIcon> | ||
<PackageIconUrl>https://project/path/to/icon</PackageIconUrl> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<CakeContribGuidelinesOmitRecommendedReference Include="StyleCop.Analyzers" /> | ||
</ItemGroup> | ||
</Project> |
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,6 @@ | ||
{ | ||
"description": "omitting StyleCop.Analyzers yields no warning", | ||
"exitCode": 0, | ||
"errors": [], | ||
"warnings": [ ] | ||
} |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
<!-- | ||
This file is automatically imported by NuGet into a user's project | ||
when it targets a single framework, or in classic (pre 2017) csproj projects. | ||
See https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#include-msbuild-props-and-targets-in-a-package | ||
--> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildThisFileDirectory)Icon.targets" /> | ||
<Import Project="$(MSBuildThisFileDirectory)CakeReference.targets" /> | ||
</Project> | ||
<Import Project="$(MSBuildThisFileDirectory)PrivateAssets.targets" /> | ||
<Import Project="$(MSBuildThisFileDirectory)RequiredReferences.targets" /> | ||
</Project> |
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
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,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<UsingTask | ||
TaskName="$(CakeContribGuidelinesCustomTasksNamespace).RequiredReferences" | ||
AssemblyFile="$(CakeContribGuidelinesCustomTasksAssembly)" /> | ||
|
||
<Target | ||
Name="_CheckRequiredReferences" | ||
AfterTargets="BeforeBuild" | ||
BeforeTargets="CoreBuild"> | ||
<ItemGroup> | ||
<CakeContribGuidelinesRequiredReference Include="StyleCop.Analyzers" /> | ||
</ItemGroup> | ||
|
||
<RequiredReferences | ||
Required="@(CakeContribGuidelinesRequiredReference)" | ||
Omitted="@(CakeContribGuidelinesOmitRecommendedReference)" | ||
References="@(PackageReference)" | ||
ProjectFile="$(MSBuildProjectFullPath)" /> | ||
</Target> | ||
</Project> |
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,26 @@ | ||
using Microsoft.Build.Utilities; | ||
|
||
namespace CakeContrib.Guidelines.Tasks.Tests.Fixtures | ||
{ | ||
public class BaseBuildFixture<T> | ||
where T : Task, new() | ||
{ | ||
public MockBuildEngine BuildEngine { get; } | ||
|
||
protected T Task { get; } | ||
|
||
public BaseBuildFixture() | ||
{ | ||
BuildEngine = new MockBuildEngine(); | ||
Task = new T | ||
{ | ||
BuildEngine = BuildEngine | ||
}; | ||
} | ||
|
||
public virtual bool Execute() | ||
{ | ||
return Task.Execute(); | ||
} | ||
} | ||
} |
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
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,57 @@ | ||
using System.Collections.Generic; | ||
|
||
using Microsoft.Build.Framework; | ||
|
||
using Moq; | ||
|
||
namespace CakeContrib.Guidelines.Tasks.Tests.Fixtures | ||
{ | ||
public class RequiredReferencesFixture : BaseBuildFixture<RequiredReferences> | ||
{ | ||
private readonly List<ITaskItem> requiredReferences; | ||
private readonly List<ITaskItem> omittedReferences; | ||
private readonly List<ITaskItem> references; | ||
|
||
public RequiredReferencesFixture() | ||
{ | ||
references = new List<ITaskItem>(); | ||
requiredReferences = new List<ITaskItem>(); | ||
omittedReferences = new List<ITaskItem>(); | ||
} | ||
|
||
public override bool Execute() | ||
{ | ||
Task.References = references.ToArray(); | ||
Task.Required = requiredReferences.ToArray(); | ||
Task.Omitted = omittedReferences.ToArray(); | ||
return base.Execute(); | ||
} | ||
|
||
public void WithRequiredReferences(string packageName) | ||
{ | ||
var reference = new Mock<ITaskItem>(); | ||
reference.Setup(x => x.ToString()).Returns(packageName); | ||
requiredReferences.Add(reference.Object); | ||
} | ||
|
||
public void WithOmittedReferences(string packageName) | ||
{ | ||
var reference = new Mock<ITaskItem>(); | ||
reference.Setup(x => x.ToString()).Returns(packageName); | ||
omittedReferences.Add(reference.Object); | ||
} | ||
|
||
public void WithProjectFile(string fileName) | ||
{ | ||
Task.ProjectFile = fileName; | ||
} | ||
|
||
public void WithReferencedPackage(string packageName, string privateAssets = "") | ||
{ | ||
var referencedPackage = new Mock<ITaskItem>(); | ||
referencedPackage.Setup(x => x.ToString()).Returns(packageName); | ||
referencedPackage.Setup(x => x.GetMetadata("PrivateAssets")).Returns(privateAssets); | ||
references.Add(referencedPackage.Object); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.