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

Revise rake tasks #1156

Merged
merged 1 commit into from
Jun 7, 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
23 changes: 14 additions & 9 deletions lib/steep/rake_task.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "rake"
require "rake/tasklib"
require "steep/cli"

module Steep
# Provides Rake tasks for running Steep commands.
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions sig/steep/rake_task.rbs
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions test/rake_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down