Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable autocorrection when source is passed through STDIN #515

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions spec/ameba/cli/cmd_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 7 additions & 1 deletion src/ameba/cli/cmd.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ 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
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
Expand Down