From b602a694018b88e94679774ae1f6b4ec3f68367d Mon Sep 17 00:00:00 2001 From: Tim Riley Date: Mon, 7 Aug 2023 21:50:01 +1000 Subject: [PATCH] Fix RuboCop issues --- lib/dry/cli/command.rb | 6 +----- lib/dry/cli/command_registry.rb | 5 +++-- lib/dry/cli/parser.rb | 6 +++--- spec/support/files.rb | 2 +- spec/support/fixtures/based | 2 +- spec/support/fixtures/baz | 2 +- spec/support/fixtures/foo | 2 +- spec/support/fixtures/infinites | 2 +- spec/support/fixtures/inline | 2 +- spec/support/fixtures/shared_commands.rb | 3 +-- spec/support/fixtures/with_block.rb | 2 +- spec/support/fixtures/with_registry.rb | 4 ++-- spec/support/fixtures/with_zero_arity_block.rb | 2 +- spec/support/path.rb | 2 +- spec/support/shared_examples/commands.rb | 6 ++---- spec/support/shared_examples/subcommands.rb | 10 +++++----- 16 files changed, 26 insertions(+), 32 deletions(-) diff --git a/lib/dry/cli/command.rb b/lib/dry/cli/command.rb index 4fbbaf69..3e6a6010 100644 --- a/lib/dry/cli/command.rb +++ b/lib/dry/cli/command.rb @@ -45,11 +45,7 @@ module ClassMethods # @since 0.7.0 # @api private - attr_reader :subcommands - - # @since 0.7.0 - # @api private - attr_writer :subcommands + attr_accessor :subcommands end # Set the description of the command diff --git a/lib/dry/cli/command_registry.rb b/lib/dry/cli/command_registry.rb index 3152830b..eb08c75c 100644 --- a/lib/dry/cli/command_registry.rb +++ b/lib/dry/cli/command_registry.rb @@ -37,7 +37,7 @@ def set(name, command, aliases) # @since 0.1.0 # @api private - # + # rubocop:disable Metrics/AbcSize def get(arguments) @_mutex.synchronize do node = @root @@ -56,7 +56,7 @@ def get(arguments) result = LookupResult.new(node, args, names, false) break elsif tmp.leaf? - args = arguments[i + 1..-1] + args = arguments[i + 1..] names = arguments[0..i] node = tmp result = LookupResult.new(node, args, names, true) @@ -72,6 +72,7 @@ def get(arguments) result end end + # rubocop:enable Metrics/AbcSize # Node of the registry # diff --git a/lib/dry/cli/parser.rb b/lib/dry/cli/parser.rb index b7801bd4..6eb82914 100644 --- a/lib/dry/cli/parser.rb +++ b/lib/dry/cli/parser.rb @@ -38,7 +38,7 @@ def self.call(command, arguments, prog_name) # @since 0.1.0 # @api private # - # rubocop:disable Metrics/AbcSize + # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity def self.parse_required_params(command, arguments, prog_name, parsed_options) parsed_params = match_arguments(command.arguments, arguments) parsed_required_params = match_arguments(command.required_arguments, arguments) @@ -67,14 +67,14 @@ def self.parse_required_params(command, arguments, prog_name, parsed_options) parsed_options = parsed_options.merge(args: unused_arguments) if unused_arguments.any? Result.success(parsed_options) end - # rubocop:enable Metrics/AbcSize + # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity def self.match_arguments(command_arguments, arguments) result = {} command_arguments.each_with_index do |cmd_arg, index| if cmd_arg.array? - result[cmd_arg.name] = arguments[index..-1] + result[cmd_arg.name] = arguments[index..] break else result[cmd_arg.name] = arguments.at(index) diff --git a/spec/support/files.rb b/spec/support/files.rb index 214a7e57..0abfc7c1 100644 --- a/spec/support/files.rb +++ b/spec/support/files.rb @@ -8,6 +8,6 @@ end failure_message do |actual| - "expected that `#{actual}' would be have content '#{expected}', but it has '#{File.read(actual)}'" # rubocop:disable Metrics/LineLength + "expected that `#{actual}' would be have content '#{expected}', but it has '#{File.read(actual)}'" end end diff --git a/spec/support/fixtures/based b/spec/support/fixtures/based index 7105725e..03b4cce2 100755 --- a/spec/support/fixtures/based +++ b/spec/support/fixtures/based @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift __dir__ + "/../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../lib" require "dry/cli" require_relative "../../../lib/dry/cli/command" diff --git a/spec/support/fixtures/baz b/spec/support/fixtures/baz index 1432f977..14deb968 100755 --- a/spec/support/fixtures/baz +++ b/spec/support/fixtures/baz @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift __dir__ + "/../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../lib" require "dry/cli" require_relative "baz_command" diff --git a/spec/support/fixtures/foo b/spec/support/fixtures/foo index 175b1bd7..4f1dc449 100755 --- a/spec/support/fixtures/foo +++ b/spec/support/fixtures/foo @@ -2,7 +2,7 @@ # frozen_string_literal: true # rubocop:disable Layout/LineLength -$LOAD_PATH.unshift __dir__ + "/../../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../../lib" require "dry/cli" module Foo diff --git a/spec/support/fixtures/infinites b/spec/support/fixtures/infinites index 00aa7923..4126574b 100755 --- a/spec/support/fixtures/infinites +++ b/spec/support/fixtures/infinites @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift __dir__ + "/../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../lib" require "dry/cli" module Infinites diff --git a/spec/support/fixtures/inline b/spec/support/fixtures/inline index 67ce8e4b..2517c020 100755 --- a/spec/support/fixtures/inline +++ b/spec/support/fixtures/inline @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift __dir__ + "/../../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../../lib" require "dry/cli" require_relative "../../../lib/dry/cli/inline" diff --git a/spec/support/fixtures/shared_commands.rb b/spec/support/fixtures/shared_commands.rb index 9b83be65..4cbbc06e 100644 --- a/spec/support/fixtures/shared_commands.rb +++ b/spec/support/fixtures/shared_commands.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# rubocop:disable Metrics/LineLength module Commands class Command < Dry::CLI::Command end @@ -442,6 +441,7 @@ class InitializedCommand < Dry::CLI::Command attr_reader :prop def initialize(prop:) + super() @prop = prop end @@ -593,4 +593,3 @@ class Addons < Base ] end end -# rubocop:enable Metrics/LineLength diff --git a/spec/support/fixtures/with_block.rb b/spec/support/fixtures/with_block.rb index f84d6345..04bae70a 100755 --- a/spec/support/fixtures/with_block.rb +++ b/spec/support/fixtures/with_block.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift __dir__ + "/../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../lib" require "dry/cli" require_relative "shared_commands" diff --git a/spec/support/fixtures/with_registry.rb b/spec/support/fixtures/with_registry.rb index 5040e116..9aac8053 100644 --- a/spec/support/fixtures/with_registry.rb +++ b/spec/support/fixtures/with_registry.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -$LOAD_PATH.unshift __dir__ + "/../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../lib" require "dry/cli" require_relative "shared_commands" @@ -62,7 +62,7 @@ module Commands register "options-with-aliases", ::Commands::OptionsWithAliases register "variadic default", ::Commands::VariadicArguments register "variadic with-mandatory", ::Commands::MandatoryAndVariadicArguments - register "variadic with-mandatory-and-options", ::Commands::MandatoryOptionsAndVariadicArguments # rubocop:disable Metrics/LineLength + register "variadic with-mandatory-and-options", ::Commands::MandatoryOptionsAndVariadicArguments register "generate webpack", ::Webpack::CLI::Generate register "hello", ::Webpack::CLI::Hello diff --git a/spec/support/fixtures/with_zero_arity_block.rb b/spec/support/fixtures/with_zero_arity_block.rb index 30aa2f26..2b5bcdf8 100755 --- a/spec/support/fixtures/with_zero_arity_block.rb +++ b/spec/support/fixtures/with_zero_arity_block.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift __dir__ + "/../../lib" +$LOAD_PATH.unshift "#{__dir__}/../../lib" require "dry/cli" require_relative "shared_commands" diff --git a/spec/support/path.rb b/spec/support/path.rb index 7a8775a6..4d2b64d1 100644 --- a/spec/support/path.rb +++ b/spec/support/path.rb @@ -7,7 +7,7 @@ def self.included(base) base.class_eval do before do @original_path = ENV["PATH"] - ENV["PATH"] = __dir__ + "/fixtures:" + ENV["PATH"] + ENV["PATH"] = "#{__dir__}/fixtures:#{ENV["PATH"]}" end after do diff --git a/spec/support/shared_examples/commands.rb b/spec/support/shared_examples/commands.rb index 67a99b2e..9a90d9aa 100644 --- a/spec/support/shared_examples/commands.rb +++ b/spec/support/shared_examples/commands.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -# rubocop:disable Metrics/LineLength RSpec.shared_examples "Commands" do |cli| let(:cli) { cli } @@ -96,7 +95,7 @@ context "and with an unknown value passed" do it "prints error" do error = capture_error { cli.call(arguments: %w[console --engine=unknown]) } - expect(error).to eq("ERROR: \"rspec console\" was called with arguments \"--engine=unknown\"\n") # rubocop:disable Metrics/LineLength + expect(error).to eq("ERROR: \"rspec console\" was called with arguments \"--engine=unknown\"\n") end end end @@ -145,7 +144,7 @@ it "with unknown param" do error = capture_error { cli.call(arguments: %w[new bookshelf --unknown 1234]) } - expect(error).to eq("ERROR: \"rspec new\" was called with arguments \"bookshelf --unknown 1234\"\n") # rubocop:disable Metrics/LineLength + expect(error).to eq("ERROR: \"rspec new\" was called with arguments \"bookshelf --unknown 1234\"\n") end it "no required" do @@ -297,4 +296,3 @@ end end end -# rubocop:enable Metrics/LineLength diff --git a/spec/support/shared_examples/subcommands.rb b/spec/support/shared_examples/subcommands.rb index b0a0b7c6..36aac8c8 100644 --- a/spec/support/shared_examples/subcommands.rb +++ b/spec/support/shared_examples/subcommands.rb @@ -87,17 +87,17 @@ end it "more than one param and with optional params" do - output = capture_output { cli.call(arguments: %w[generate action web users#index --url=/signin]) } # rubocop:disable Metrics/LineLength - expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>false, :url=>\"/signin\"}\n") # rubocop:disable Metrics/LineLength + output = capture_output { cli.call(arguments: %w[generate action web users#index --url=/signin]) } + expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>false, :url=>\"/signin\"}\n") end it "more than one param and with boolean params" do - output = capture_output { cli.call(arguments: %w[generate action web users#index --skip-view --url=/signin]) } # rubocop:disable Metrics/LineLength - expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>true, :url=>\"/signin\"}\n") # rubocop:disable Metrics/LineLength + output = capture_output { cli.call(arguments: %w[generate action web users#index --skip-view --url=/signin]) } + expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>true, :url=>\"/signin\"}\n") end it "more than required params" do - output = capture_output { cli.call(arguments: %w[destroy action web users#index unexpected_param]) } # rubocop:disable Metrics/LineLength + output = capture_output { cli.call(arguments: %w[destroy action web users#index unexpected_param]) } expect(output).to eq("destroy action - app: web, action: users#index\n") end