From 441164f3260ebe6e9be30b49866746834ef3b671 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Fri, 4 Jun 2021 16:06:19 +0200 Subject: [PATCH 1/3] (#28) removed the appveyor badge and added a GitHub badge --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9c2de0c0..230a21cf 100644 --- a/README.md +++ b/README.md @@ -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] @@ -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 From bef590bd7bab11621c30766d49cf6de88bdc500c Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 4 Jun 2021 23:26:00 +0000 Subject: [PATCH 2/3] (maint) Update dependency eslint to v7.28.0 --- demo/frosting/src2/package.json | 2 +- demo/script/src2/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/frosting/src2/package.json b/demo/frosting/src2/package.json index afadd233..e2aa51d3 100644 --- a/demo/frosting/src2/package.json +++ b/demo/frosting/src2/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "devDependencies": { - "eslint": "7.27.0" + "eslint": "7.28.0" } } diff --git a/demo/script/src2/package.json b/demo/script/src2/package.json index afadd233..e2aa51d3 100644 --- a/demo/script/src2/package.json +++ b/demo/script/src2/package.json @@ -9,6 +9,6 @@ "author": "", "license": "ISC", "devDependencies": { - "eslint": "7.27.0" + "eslint": "7.28.0" } } From 704828128100176818de645d3dc36055cbe478f8 Mon Sep 17 00:00:00 2001 From: Nils Andresen Date: Sat, 5 Jun 2021 23:20:11 +0200 Subject: [PATCH 3/3] (GH-19) added options for specifying rules and plugins. --rulesdir [path::String] --plugin [String] --rule Object --- src/Cake.ESLint.Tests/ESLintRunnerTests.cs | 32 +++++++++++++++++- src/Cake.ESLint/ESLintRunner.cs | 17 +++++++++- src/Cake.ESLint/ESLintSettings.cs | 18 +++++++++++ src/Cake.ESLint/ESLintSettingsExtensions.cs | 36 +++++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/Cake.ESLint.Tests/ESLintRunnerTests.cs b/src/Cake.ESLint.Tests/ESLintRunnerTests.cs index b7858646..c1f43ccd 100644 --- a/src/Cake.ESLint.Tests/ESLintRunnerTests.cs +++ b/src/Cake.ESLint.Tests/ESLintRunnerTests.cs @@ -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] @@ -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 { diff --git a/src/Cake.ESLint/ESLintRunner.cs b/src/Cake.ESLint/ESLintRunner.cs index 52cf72c4..5af4652f 100644 --- a/src/Cake.ESLint/ESLintRunner.cs +++ b/src/Cake.ESLint/ESLintRunner.cs @@ -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) @@ -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()) { diff --git a/src/Cake.ESLint/ESLintSettings.cs b/src/Cake.ESLint/ESLintSettings.cs index 2afeb15f..266e0e73 100644 --- a/src/Cake.ESLint/ESLintSettings.cs +++ b/src/Cake.ESLint/ESLintSettings.cs @@ -111,6 +111,24 @@ public ESLintSettings() /// public DirectoryPath ResolvePluginsRelativeTo { get; set; } + /// + /// Gets or sets a folder where additional rules are located. + /// Option: --rulesdir. + /// + public IEnumerable RulesDirs { get; set; } + + /// + /// Gets or sets the plugins to use. + /// Option: --plugin. + /// + public IEnumerable Plugins { get; set; } + + /// + /// Gets or sets the Rule(s). + /// Option: --rule. + /// + public IEnumerable Rules { get; set; } + /// /// Gets or sets a value indicating whether to continue on lint errors. /// diff --git a/src/Cake.ESLint/ESLintSettingsExtensions.cs b/src/Cake.ESLint/ESLintSettingsExtensions.cs index 86b18e24..acafa32f 100644 --- a/src/Cake.ESLint/ESLintSettingsExtensions.cs +++ b/src/Cake.ESLint/ESLintSettingsExtensions.cs @@ -67,5 +67,41 @@ public static void AddFile(this ESLintSettings @this, params FilePath[] filePath paths.AddRange(filePaths); @this.Files = paths; } + + /// + /// adds to . + /// + /// The . + /// The paths to add. + public static void AddRulesDir(this ESLintSettings @this, params DirectoryPath[] rulesDir) + { + var paths = @this.RulesDirs?.ToList() ?? new List(); + paths.AddRange(rulesDir); + @this.RulesDirs = paths; + } + + /// + /// adds to . + /// + /// The . + /// The plugins to add. + public static void AddPlugin(this ESLintSettings @this, params string[] plugin) + { + var plugins = @this.Plugins?.ToList() ?? new List(); + plugins.AddRange(plugin); + @this.Plugins = plugins; + } + + /// + /// adds to . + /// + /// The . + /// The plugins to add. + public static void AddRule(this ESLintSettings @this, params string[] rule) + { + var plugins = @this.Rules?.ToList() ?? new List(); + plugins.AddRange(rule); + @this.Rules = plugins; + } } }