diff --git a/lib/steep/rake_task.rb b/lib/steep/rake_task.rb index c08242d29..75bafb495 100644 --- a/lib/steep/rake_task.rb +++ b/lib/steep/rake_task.rb @@ -1,5 +1,6 @@ require "rake" require "rake/tasklib" +require "steep/cli" module Steep # Provides Rake tasks for running Steep commands. @@ -8,16 +9,13 @@ module Steep # Steep::RakeTask.new do |t| # t.check.severity_level = :error # t.watch.verbose + # t.stats << "--format=table" # end - class RakeTask < Rake::TaskLib + class RakeTask < Rake::TaskLib # steep:ignore UnknownConstant attr_accessor :name def self.available_commands - require "steep/cli" - - skipped_commands = %i[langserver checkfile] - - Steep::CLI.available_commands - skipped_commands + %i(init check stats binstub project watch) end def initialize(name = :steep, cli_runner = default_cli_runner) @@ -64,14 +62,21 @@ def initialize end def method_missing(name, value = nil) - @options << "--#{name.to_s.gsub(/_/, '-').gsub(/=/, '')}" - @options << value.to_s unless value.nil? + option = "--#{name.to_s.gsub(/_/, '-').gsub(/=/, '')}" + option << "=#{value}" if value + + self << option end def respond_to_missing?(_name) true end + def <<(value) + @options << value + self + end + def to_a @options end @@ -120,7 +125,7 @@ def define_tasks(configuration, cli_runner) end # Default steep task to steep:check - desc "Run steep check" unless ::Rake.application.last_description + desc "Run steep check" unless ::Rake.application.last_description # steep:ignore UnknownConstant task name => ["#{name}:check"] end end diff --git a/sig/steep/rake_task.rbs b/sig/steep/rake_task.rbs new file mode 100644 index 000000000..02b52b660 --- /dev/null +++ b/sig/steep/rake_task.rbs @@ -0,0 +1,53 @@ +module Steep + class RakeTask + + attr_accessor name: Symbol + + def self.available_commands: () -> Array[Symbol] + + def initialize: (?::Symbol name, ?cli_runner) ?{ (TaskConfiguration) -> void } -> void + + private + + class TaskConfiguration + @commands: Hash[Symbol, CommandConfiguration] + + def initialize: () -> void + + def method_missing: (Symbol command) -> void + + def respond_to_missing?: (Symbol name, ?bool include_private) -> boolish + + def options: (Symbol command) -> Array[String] + end + + class CommandConfiguration + @options: Array[String] + + def initialize: () -> void + + def method_missing: (Symbol name, ?untyped value) -> void + + def respond_to_missing?: (Symbol _name) -> true + + def <<: (String) -> self + + def to_a: () -> Array[String] + end + + type cli_runner = ^(Array[String]) -> Integer + + def default_cli_runner: () -> cli_runner + + def define_tasks: (TaskConfiguration configuration, cli_runner) -> void + + # Methods that is defined in Rake::Task + + def namespace: (Symbol) { (?) -> void } -> void + + def desc: (String) -> void + + def task: (Symbol | String name) { (?) -> void } -> void + | (Hash[Symbol, Array[String]]) ?{ (?) -> void } -> void + end +end diff --git a/test/rake_task_test.rb b/test/rake_task_test.rb index bc0aa2839..39ffc2273 100644 --- a/test/rake_task_test.rb +++ b/test/rake_task_test.rb @@ -10,18 +10,20 @@ def test_task_configuration configuration.check.severity_level = :error configuration.watch.verbose + configuration.stats << "--format=table" assert_raises(NoMethodError) do configuration.missing_command.verbose end - assert_equal ["--severity-level", "error"], configuration.options(:check) + assert_equal ["--severity-level=error"], configuration.options(:check) assert_equal ["--verbose"], configuration.options(:watch) - assert_equal [], configuration.options(:stats) + assert_equal ["--format=table"], configuration.options(:stats) + assert_equal [], configuration.options(:project) end def test_define_task_with_options - cli = mock_cli(expecting: %w[check --severity-level error]) + cli = mock_cli(expecting: %w[check --severity-level=error]) setup_rake_tasks!(cli) do |task| task.check.severity_level = :error @@ -31,11 +33,11 @@ def test_define_task_with_options end def test_rake_arguments - cli = mock_cli(expecting: %w[check --severity-level error]) + cli = mock_cli(expecting: %w[check --severity-level=error]) setup_rake_tasks!(cli) - Rake::Task["steep:check"].invoke("--severity-level", "error") + Rake::Task["steep:check"].invoke("--severity-level=error") end def test_help_task