Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nils-a committed Jun 5, 2021
2 parents 62c6e9c + b15af61 commit 5b82863
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![standard-readme compliant][]][standard-readme]
[![All Contributors][all-contributorsimage]](#contributors)
[![Appveyor build][appveyorimage]][appveyor]
[![Build][githubimage]][githubbuild]
[![Codecov Report][codecovimage]][codecov]
[![NuGet package][nugetimage]][nuget]

Expand Down Expand Up @@ -81,8 +81,8 @@ Thanks goes to these wonderful people ([emoji key][emoji-key]):

[all-contributors]: https://github.com/all-contributors/all-contributors
[all-contributorsimage]: https://img.shields.io/github/all-contributors/cake-contrib/Cake.ESLint.svg?color=orange&style=flat-square
[appveyor]: https://ci.appveyor.com/project/nilsa/cake-eslint
[appveyorimage]: https://img.shields.io/appveyor/ci/nilsa/cake-eslint.svg?logo=appveyor&style=flat-square
[githubbuild]: https://github.com/cake-contrib/Cake.ESLint/actions/workflows/build.yml?query=branch%3Adevelop
[githubimage]: https://github.com/cake-contrib/Cake.ESLint/actions/workflows/build.yml/badge.svg?branch=develop
[codecov]: https://codecov.io/gh/cake-contrib/Cake.ESLint
[codecovimage]: https://img.shields.io/codecov/c/github/cake-contrib/Cake.ESLint.svg?logo=codecov&style=flat-square
[contrib-covenant]: https://www.contributor-covenant.org/version/1/4/code-of-conduct
Expand Down
2 changes: 1 addition & 1 deletion demo/frosting/src2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "7.27.0"
"eslint": "7.28.0"
}
}
2 changes: 1 addition & 1 deletion demo/script/src2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"eslint": "7.27.0"
"eslint": "7.28.0"
}
}
32 changes: 31 additions & 1 deletion src/Cake.ESLint.Tests/ESLintRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void Should_add_global_args_when_globals_is_set()

var actual = fixture.Run();

actual.Args.ShouldContain("--global require --global exports:true");
actual.Args.ShouldContain("--global \"require\" --global \"exports:true\"");
}

[Fact]
Expand Down Expand Up @@ -280,6 +280,36 @@ public void Should_add_resolve_plugins_relative_to_arg_when_resolvePluginsRelati
actual.Args.ShouldContain("--resolve-plugins-relative-to \"../plugins\"");
}

[Fact]
public void Should_add_rulesdir_arg_when_rulesDirs_is_set()
{
fixture.Settings.AddRulesDir("my-rules", "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()
{
fixture.Settings.AddPlugin("jquery", "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()
{
fixture.Settings.AddRule("guard-for-in: 2", "brace-style: [2, 1tbs]");

var actual = fixture.Run();

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

// ReSharper disable once ClassNeverInstantiated.Local
private class OutputFormatDataGenerator : IEnumerable<object[]>
{
Expand Down
17 changes: 16 additions & 1 deletion src/Cake.ESLint/ESLintRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private ProcessArgumentBuilder GetArguments(ESLintSettings settings)

foreach (var global in settings.Globals.EnsureNotNull())
{
builder.AppendSwitch("--global", global);
builder.AppendSwitchQuoted("--global", global);
}

if (settings.Parser != null)
Expand All @@ -178,6 +178,21 @@ private ProcessArgumentBuilder GetArguments(ESLintSettings settings)
settings.ResolvePluginsRelativeTo.FullPath);
}

foreach (var dir in settings.RulesDirs.EnsureNotNull())
{
builder.AppendSwitchQuoted("--rulesdir", dir.FullPath);
}

foreach (var plugin in settings.Plugins.EnsureNotNull())
{
builder.AppendSwitch("--plugin", plugin);
}

foreach (var rule in settings.Rules.EnsureNotNull())
{
builder.AppendSwitchQuoted("--rule", rule);
}

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

/// <summary>
/// Gets or sets a folder where additional rules are located.
/// <para>Option: <c>--rulesdir</c>.</para>
/// </summary>
public IEnumerable<DirectoryPath> RulesDirs { get; set; }

/// <summary>
/// Gets or sets the plugins to use.
/// <para>Option: <c>--plugin</c>.</para>
/// </summary>
public IEnumerable<string> Plugins { get; set; }

/// <summary>
/// Gets or sets the Rule(s).
/// <para>Option: <c>--rule</c>.</para>
/// </summary>
public IEnumerable<string> Rules { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to continue on lint errors.
/// <para>
Expand Down
36 changes: 36 additions & 0 deletions src/Cake.ESLint/ESLintSettingsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,41 @@ public static void AddFile(this ESLintSettings @this, params FilePath[] filePath
paths.AddRange(filePaths);
@this.Files = paths;
}

/// <summary>
/// adds to <see cref="ESLintSettings.RulesDirs"/>.
/// </summary>
/// <param name="this">The <see cref="ESLintSettings"/>.</param>
/// <param name="rulesDir">The paths to add.</param>
public static void AddRulesDir(this ESLintSettings @this, params DirectoryPath[] rulesDir)
{
var paths = @this.RulesDirs?.ToList() ?? new List<DirectoryPath>();
paths.AddRange(rulesDir);
@this.RulesDirs = paths;
}

/// <summary>
/// adds to <see cref="ESLintSettings.Plugins"/>.
/// </summary>
/// <param name="this">The <see cref="ESLintSettings"/>.</param>
/// <param name="plugin">The plugins to add.</param>
public static void AddPlugin(this ESLintSettings @this, params string[] plugin)
{
var plugins = @this.Plugins?.ToList() ?? new List<string>();
plugins.AddRange(plugin);
@this.Plugins = plugins;
}

/// <summary>
/// adds to <see cref="ESLintSettings.Rules"/>.
/// </summary>
/// <param name="this">The <see cref="ESLintSettings"/>.</param>
/// <param name="rule">The plugins to add.</param>
public static void AddRule(this ESLintSettings @this, params string[] rule)
{
var plugins = @this.Rules?.ToList() ?? new List<string>();
plugins.AddRange(rule);
@this.Rules = plugins;
}
}
}

0 comments on commit 5b82863

Please sign in to comment.