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

Add type checking configuration to dsl #132

Merged
merged 2 commits into from
Apr 27, 2020
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
13 changes: 12 additions & 1 deletion lib/steep/drivers/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@ def run
status.type_check_sources.each do |source_file|
case source_file.status
when Project::SourceFile::TypeCheckStatus
source_file.errors.each do |error|
source_file.errors.reject do |error|
case
when error.is_a?(Errors::FallbackAny)
target.options.allow_fallback_any
when error.is_a?(Errors::MethodDefinitionMissing)
target.options.allow_missing_definitions
when error.is_a?(Errors::NoMethod)
target.options.allow_unknown_method_calls
when error.is_a?(Errors::UnknownConstantAssigned)
target.options.allow_unknown_constant_assignment
end
end.each do |error|
error.print_to stdout
end
when Project::SourceFile::TypeCheckErrorStatus
Expand Down
14 changes: 14 additions & 0 deletions lib/steep/project/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TargetDSL
attr_reader :ignored_sources
attr_reader :no_builtin
attr_reader :vendor_dir
attr_reader :strictness_level

def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources: [])
@name = name
Expand All @@ -17,6 +18,7 @@ def initialize(name, sources: [], libraries: [], signatures: [], ignored_sources
@signatures = signatures
@ignored_sources = ignored_sources
@vendor_dir = nil
@strictness_level = :default
end

def initialize_copy(other)
Expand All @@ -26,6 +28,7 @@ def initialize_copy(other)
@signatures = other.signatures.dup
@ignored_sources = other.ignored_sources.dup
@vendor_dir = other.vendor_dir
@strictness_level = other.strictness_level
end

def check(*args)
Expand All @@ -40,6 +43,10 @@ def library(*args)
libraries.push(*args)
end

def typing_options(level)
@strictness_level = level
end

def signature(*args)
signatures.push(*args)
end
Expand Down Expand Up @@ -114,6 +121,13 @@ def target(name, template: nil, &block)
options: Options.new.tap do |options|
options.libraries.push(*target.libraries)

case target.strictness_level
when :strict
options.apply_strict_typing_options!
when :lenient
options.apply_lenient_typing_options!
end

case target.vendor_dir
when Array
options.vendored_stdlib_path = target.vendor_dir[0]
Expand Down
8 changes: 0 additions & 8 deletions lib/steep/project/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ def errors
case status
when TypeCheckStatus
status.typing.errors
# errors.reject do |error|
# case
# when error.is_a?(Errors::FallbackAny)
# !options.fallback_any_is_error
# when error.is_a?(Errors::MethodDefinitionMissing)
# options.allow_missing_definitions
# end
# end
else
[]
end
Expand Down
28 changes: 25 additions & 3 deletions lib/steep/project/options.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
module Steep
class Project
class Options
attr_accessor :fallback_any_is_error
attr_accessor :allow_fallback_any
attr_accessor :allow_missing_definitions
attr_accessor :allow_unknown_constant_assignment
attr_accessor :allow_unknown_method_calls
attr_accessor :vendored_stdlib_path
attr_accessor :vendored_gems_path
attr_reader :libraries

def initialize
self.fallback_any_is_error = false
self.allow_missing_definitions = true
apply_default_typing_options!
self.vendored_gems_path = nil
self.vendored_stdlib_path = nil

@libraries = []
end

def apply_default_typing_options!
self.allow_fallback_any = true
self.allow_missing_definitions = true
self.allow_unknown_constant_assignment = false
self.allow_unknown_method_calls = false
end

def apply_strict_typing_options!
self.allow_fallback_any = false
self.allow_missing_definitions = false
self.allow_unknown_constant_assignment = false
self.allow_unknown_method_calls = false
end

def apply_lenient_typing_options!
self.allow_fallback_any = true
self.allow_missing_definitions = true
self.allow_unknown_constant_assignment = true
self.allow_unknown_method_calls = true
end
end
end
end
1 change: 1 addition & 0 deletions smoke/alias/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/and/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/array/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/block/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
Expand Down
1 change: 1 addition & 0 deletions smoke/case/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/class/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/const/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/dstr/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/ensure/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/enumerator/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/extension/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/hash/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/hello/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/if/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/implements/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/initialize/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/integer/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/interface/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/kwbegin/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/lambda/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/literal/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/map/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/method/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/module/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/regexp/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/regression/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
library "set"
Expand Down
1 change: 1 addition & 0 deletions smoke/rescue/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/self/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/skip/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/stdout/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/super/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/type_case/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
1 change: 1 addition & 0 deletions smoke/yield/Steepfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target :test do
typing_options :strict
check "*.rb"
signature "*.rbs"
end
3 changes: 3 additions & 0 deletions test/steepfile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_config

Project::DSL.parse(project, <<EOF)
target :app do
typing_options :strict
check "app"
ignore "app/views"
vendor
Expand All @@ -40,6 +41,7 @@ def test_config
assert_equal ["set", "strong_json"], target.options.libraries
assert_equal Pathname("vendor/sigs/stdlib"), target.options.vendored_stdlib_path
assert_equal Pathname("vendor/sigs/gems"), target.options.vendored_gems_path
assert_equal false, target.options.allow_missing_definitions
end

project.targets.find {|target| target.name == :Gemfile }.tap do |target|
Expand All @@ -50,6 +52,7 @@ def test_config
assert_equal ["gemfile"], target.options.libraries
assert_nil target.options.vendored_stdlib_path
assert_equal Pathname("vendor/signatures/gems"), target.options.vendored_gems_path
assert_equal true, target.options.allow_missing_definitions
end
end
end
Expand Down