From 5e3874abb24c781415bbaaca232b283908a92f31 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Mon, 25 Nov 2024 02:00:26 +0100 Subject: [PATCH 1/3] Disable autocorrection when source is passed through `STDIN` --- src/ameba/cli/cmd.cr | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ameba/cli/cmd.cr b/src/ameba/cli/cmd.cr index 2a74330b2..3b57c7092 100644 --- a/src/ameba/cli/cmd.cr +++ b/src/ameba/cli/cmd.cr @@ -8,15 +8,20 @@ module Ameba::Cli def run(args = ARGV) : Nil opts = parse_args args location_to_explain = opts.location_to_explain + stdin_filename = opts.stdin_filename autocorrect = opts.autocorrect? if location_to_explain && autocorrect raise "Invalid usage: Cannot explain an issue and autocorrect at the same time." end + if stdin_filename && autocorrect + raise "Invalid usage: Cannot autocorrect from stdin." + end + config = Config.load opts.config, opts.colors?, opts.skip_reading_config? config.autocorrect = autocorrect - config.stdin_filename = opts.stdin_filename + config.stdin_filename = stdin_filename if globs = opts.globs config.globs = globs From 715328bcd61c69108127c6551c6dfde3b9cefac3 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Mon, 25 Nov 2024 02:07:08 +0100 Subject: [PATCH 2/3] Silence `Metrics/CyclomaticComplexity` issue This will be refactored anyway in v1.7.0 --- src/ameba/cli/cmd.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ameba/cli/cmd.cr b/src/ameba/cli/cmd.cr index 3b57c7092..6265f5b3b 100644 --- a/src/ameba/cli/cmd.cr +++ b/src/ameba/cli/cmd.cr @@ -5,6 +5,7 @@ require "option_parser" module Ameba::Cli extend self + # ameba:disable Metrics/CyclomaticComplexity def run(args = ARGV) : Nil opts = parse_args args location_to_explain = opts.location_to_explain From ea258c1896c9b7f598ab762169f238efe17b6575 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Mon, 25 Nov 2024 02:17:04 +0100 Subject: [PATCH 3/3] Add missing test case for `--stdin-filename` flag --- spec/ameba/cli/cmd_spec.cr | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/ameba/cli/cmd_spec.cr b/spec/ameba/cli/cmd_spec.cr index a5530baeb..5270133e3 100644 --- a/spec/ameba/cli/cmd_spec.cr +++ b/spec/ameba/cli/cmd_spec.cr @@ -32,6 +32,11 @@ module Ameba::Cli end end + it "accepts --stdin-filename flag" do + c = Cli.parse_args %w[--stdin-filename foo.cr] + c.stdin_filename.should eq "foo.cr" + end + it "accepts --only flag" do c = Cli.parse_args ["--only", "RULE1,RULE2"] c.only.should eq %w[RULE1 RULE2]