Skip to content

Commit

Permalink
Steepfile: Allow to change the extension of the source files
Browse files Browse the repository at this point in the history
To support ERB, this allows to change the extension of the source files
via `ext` setting in Steepfile.

Example:

```
target :views do
  check "app/views"
  ext ".erb"
end
```

refs: #1409
  • Loading branch information
tk0miya committed Jan 3, 2025
1 parent 850c66f commit 6c905b8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/steep/project/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def check(*args)
sources.concat(args)
end

def ext(ext)
@ext = ext
end

def ignore(*args)
ignored_sources.concat(args)
end
Expand Down Expand Up @@ -103,7 +107,7 @@ def ignored_signatures
end

def source_pattern
Pattern.new(patterns: sources, ignores: ignored_sources, ext: ".rb")
Pattern.new(patterns: sources, ignores: ignored_sources, ext: @ext || ".rb")
end

def signature_pattern
Expand Down
4 changes: 2 additions & 2 deletions lib/steep/server/master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def process_message_from_client(message)
end
target.source_pattern.prefixes.each do |pat|
path = project.base_dir + pat
patterns << (path + "**/*.rb").to_s unless path.file?
patterns << (path + "**/*#{target.source_pattern.ext}").to_s unless path.file?
end
target.signature_pattern.patterns.each do |pat|
path = project.base_dir + pat
Expand Down Expand Up @@ -800,7 +800,7 @@ def start_type_check(request: nil, last_request:, progress: nil, include_unchang
Steep.logger.info "Starting new progress..."

@current_type_check_request = request

if progress
# If `request:` keyword arg is not given
request.work_done_progress.begin("Type checking", request_id: fresh_request_id)
Expand Down
5 changes: 5 additions & 0 deletions sample/Steepfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ end
# signature "sig/length.rbs"
# unreferenced!
# end

# target :templates do
# check "lib/templates" # Directory name
# ext ".erb"
# end
4 changes: 4 additions & 0 deletions sig/steep/project/dsl.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ module Steep

attr_reader ignored_signatures: Array[String]

@ext: String?

def check: (*String args) -> void

def ext: (String ext) -> void

def ignore: (*String args) -> void

def signature: (*String args) -> void
Expand Down
24 changes: 24 additions & 0 deletions test/steepfile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,28 @@ def test_string
end
end
end

def test_ext
in_tmpdir do
project = Project.new(steepfile_path: current_dir + "Steepfile")

Project::DSL.parse(project, <<EOF)
target :views do
check "app/views"
ext ".erb"
signature "sig"
end
EOF

assert_equal 1, project.targets.size

project.targets.find {|target| target.name == :views }.tap do |target|
assert_instance_of Project::Target, target

assert_equal ["app/views"], target.source_pattern.patterns
assert_equal ".erb", target.source_pattern.ext
assert_equal ["sig"], target.signature_pattern.patterns
end
end
end
end

0 comments on commit 6c905b8

Please sign in to comment.