Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-a committed Jun 9, 2021
2 parents 5b82863 + ce0285d commit 062b1ea
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 22 deletions.
4 changes: 0 additions & 4 deletions src/Cake.ESLint.Tests/Cake.ESLint.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Shouldly" Version="4.0.3" />
<PackageReference Include="Verify.Xunit" Version="11.18.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
]
},
Process: {
Arguments: [
{}
],
WorkingDirectory: {
FullPath: /Working,
Separator: "/",
Expand All @@ -17,5 +20,5 @@
]
}
},
Args:
Args: "**/*"
}
1 change: 1 addition & 0 deletions src/Cake.ESLint.Tests/ESLintAliasesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public async Task Runs_tool_with_given_settings()
[Fact]
public async Task Runs_tool_with_given_action()
{
fixture.Settings = null;
fixture.Action = x => x.Files = new[] {new FilePath("**/*")};
var result = fixture.Run();

Expand Down
126 changes: 126 additions & 0 deletions src/Cake.ESLint.Tests/ESLintRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public void Should_Throw_If_Settings_Are_Null()
result.ShouldThrow<ArgumentException>();
}

[Fact]
public void Should_Throw_If_Log_Is_Null()
{
fixture.Log = null;

Action result = () => fixture.Run();

result.ShouldThrow<ArgumentException>();
}

[Fact]
public void Should_Throw_If_ESLint_Executable_Was_Not_Found()
{
Expand All @@ -84,6 +94,18 @@ public void Should_use_local_eslint_from_nodeModules_if_exists()
actual.Path.FullPath.ShouldBe(expected.Path.FullPath);
}

[Fact]
public void Should_use_eslint_cmd_on_windows()
{
fixture.GivenDefaultToolDoNotExist();
var expected = fixture.GivenFileExists("/some/project/node_modules/.bin/eslint");
fixture.Settings.WorkingDirectory = "/some/project";

var actual = fixture.Run();

actual.Path.FullPath.ShouldBe(expected.Path.FullPath);
}

[Fact]
public void Should_use_default_eslint_when_workingDirectory_contains_no_nodeModules()
{
Expand Down Expand Up @@ -290,6 +312,17 @@ public void Should_add_rulesdir_arg_when_rulesDirs_is_set()
actual.Args.ShouldContain("--rulesdir \"my-rules\" --rulesdir \"my-other-rules\"");
}

[Fact]
public void Should_add_rulesdir_arg_when_rulesDirs_is_set_multiple_times()
{
fixture.Settings.AddRulesDir("my-rules");
fixture.Settings.AddRulesDir("my-other-rules");

var actual = fixture.Run();

actual.Args.ShouldContain("--rulesdir \"my-rules\" --rulesdir \"my-other-rules\"");
}

[Fact]
public void Should_add_plugin_arg_when_plugins_is_set()
{
Expand All @@ -300,6 +333,17 @@ public void Should_add_plugin_arg_when_plugins_is_set()
actual.Args.ShouldContain("--plugin jquery --plugin eslint-plugin-mocha");
}

[Fact]
public void Should_add_plugin_arg_when_plugins_is_set_multiple_times()
{
fixture.Settings.AddPlugin("jquery");
fixture.Settings.AddPlugin("eslint-plugin-mocha");

var actual = fixture.Run();

actual.Args.ShouldContain("--plugin jquery --plugin eslint-plugin-mocha");
}

[Fact]
public void Should_add_rule_arg_when_Rules_is_set()
{
Expand All @@ -310,6 +354,88 @@ public void Should_add_rule_arg_when_Rules_is_set()
actual.Args.ShouldContain("--rule \"guard-for-in: 2\" --rule \"brace-style: [2, 1tbs]\"");
}

[Fact]
public void Should_add_rule_arg_when_Rules_is_set_multiple_times()
{
fixture.Settings.AddRule("guard-for-in: 2");
fixture.Settings.AddRule("brace-style: [2, 1tbs]");

var actual = fixture.Run();

actual.Args.ShouldContain("--rule \"guard-for-in: 2\" --rule \"brace-style: [2, 1tbs]\"");
}

[Fact]
public void Should_add_fix_arg_when_Fix_is_set()
{
fixture.Settings.Fix = true;

var actual = fixture.Run();

actual.Args.ShouldContain("--fix");
}

[Fact]
public void Should_add_fix_dry_run_arg_when_FixDryRun_is_set()
{
fixture.Settings.FixDryRun = true;

var actual = fixture.Run();

actual.Args.ShouldContain("--fix-dry-run");
}

[Fact]
public void Should_add_fix_type_arg_when_FixType_is_set()
{
fixture.Settings.AddFixType(ESLintFixType.Layout);

var actual = fixture.Run();

actual.Args.ShouldContain("--fix-type layout");
}

[Fact]
public void Should_add_fix_type_arg_when_FixType_is_set_with_multiple_flags()
{
fixture.Settings.AddFixType(ESLintFixType.Problem, ESLintFixType.Suggestion);

var actual = fixture.Run();

actual.Args.ShouldContain("--fix-type problem --fix-type suggestion");
}

[Fact]
public void Should_add_ignore_path_arg_when_IgnorePath_is_set()
{
fixture.Settings.IgnorePath = "tmp/.eslintignore";

var actual = fixture.Run();

actual.Args.ShouldContain("--ignore-path \"tmp/.eslintignore\"");
}

[Fact]
public void Should_add_ignore_pattern_arg_when_IgnorePatterns_is_set()
{
fixture.Settings.AddIgnorePattern(new DirectoryPath("/lib/"));
fixture.Settings.AddIgnorePattern(new FilePath("/src/vendor/*"));

var actual = fixture.Run();

actual.Args.ShouldContain("--ignore-pattern \"/lib/\" --ignore-pattern \"/src/vendor/*\"");
}

[Fact]
public void Should_add_no_ignore_arg_when_NoIgnore_is_set()
{
fixture.Settings.NoIgnore = true;

var actual = fixture.Run();

actual.Args.ShouldContain("--no-ignore");
}

// ReSharper disable once ClassNeverInstantiated.Local
private class OutputFormatDataGenerator : IEnumerable<object[]>
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.ESLint.Tests/Fixtures/ESLintRunnerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ESLintRunnerFixture()
Log = new FakeLog();
}

internal FakeLog Log { get; }
internal FakeLog Log { get; set; }

protected override void RunTool()
{
Expand Down
4 changes: 3 additions & 1 deletion src/Cake.ESLint.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ES/@EntryIndexedValue">ES</s:String>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Codeframe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=eslintignore/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=NONINFRINGEMENT/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=npmjs/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=npmjs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=rulesdir/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
59 changes: 59 additions & 0 deletions src/Cake.ESLint/ESLintFixType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* MIT License
*
* Copyright (c) 2021 Nils Andresen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

using System;

namespace Cake.ESLint
{
/// <summary>
/// Options for <c>--fix-type</c>.
/// </summary>
public sealed class ESLintFixType
{
private ESLintFixType(string name)
{
this.Name = name;
}

/// <summary>
/// Gets the fix-type: Problem.
/// </summary>
public static ESLintFixType Problem { get; } = new ESLintFixType("problem");

/// <summary>
/// Gets the fix-type: Suggestion.
/// </summary>
public static ESLintFixType Suggestion { get; } = new ESLintFixType("suggestion");

/// <summary>
/// Gets the fix-type: Layout.
/// </summary>
public static ESLintFixType Layout { get; } = new ESLintFixType("layout");

/// <summary>
/// Gets the name of the problem.
/// </summary>
public string Name { get; }
}
}
30 changes: 30 additions & 0 deletions src/Cake.ESLint/ESLintRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,36 @@ private ProcessArgumentBuilder GetArguments(ESLintSettings settings)
builder.AppendSwitchQuoted("--rule", rule);
}

if (settings.Fix)
{
builder.Append("--fix");
}

if (settings.FixDryRun)
{
builder.Append("--fix-dry-run");
}

foreach (var type in settings.FixTypes.EnsureNotNull())
{
builder.AppendSwitch("--fix-type", type.Name);
}

if (settings.IgnorePath != null)
{
builder.AppendSwitchQuoted("--ignore-path", settings.IgnorePath.FullPath);
}

if (settings.NoIgnore)
{
builder.Append("--no-ignore");
}

foreach (var pattern in settings.IgnorePatterns.EnsureNotNull())
{
builder.AppendSwitchQuoted("--ignore-pattern", pattern);
}

// render arguments
foreach (var file in settings.Files.EnsureNotNull())
{
Expand Down
38 changes: 38 additions & 0 deletions src/Cake.ESLint/ESLintSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,44 @@ public ESLintSettings()
/// </summary>
public IEnumerable<string> Rules { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to fix problems.
/// <para>Option: <c>--fix</c>.</para>
/// </summary>
public bool Fix { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to fix problems without saving the changes to the file system.
/// <para>Option: <c>--fix-dry-run</c>.</para>
/// </summary>
public bool FixDryRun { get; set; }

/// <summary>
/// Gets or sets the types of fixes to apply.
/// <para>Option: <c>--fix-types</c>.</para>
/// </summary>
public IEnumerable<ESLintFixType> FixTypes { get; set; }

/// <summary>
/// Gets or sets the path to the ignoreFile.
/// <para>Option: <c>--ignore-path</c>.</para>
/// </summary>
public FilePath IgnorePath { get; set; }

/// <summary>
/// Gets or sets a value indicating whether
/// to disable use of ignore files and patterns.
/// <para>Option: <c>--no-ignore</c>.</para>
/// </summary>
public bool NoIgnore { get; set; }

/// <summary>
/// Gets or sets patterns of files to ignore
/// (in addition to those in .eslintignore).
/// <para>Option: <c>--ignore-pattern</c>.</para>
/// </summary>
public IEnumerable<string> IgnorePatterns { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to continue on lint errors.
/// <para>
Expand Down
Loading

0 comments on commit 062b1ea

Please sign in to comment.