-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
89 lines (71 loc) · 2.35 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true
require "minitest/test_task"
require "rake/clean"
require "rubocop/rake_task"
require "securerandom"
require "shellwords"
CLEAN.push(*%w[.idea/ .ruby-lsp/ .yardoc/])
xargs = %w[xargs --no-run-if-empty --null --max-procs=0 --max-args=300 --]
task(default: [:test, :format])
Minitest::TestTask.create do |t|
t.libs = %w[.]
t.test_globs = ENV.fetch("TEST", "./test/**/*_test.rb")
end
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = %w[--fail-level E]
if ENV.key?("CI")
t.options += %w[--format github]
end
end
multitask(:ruboformat) do
find = %w[find ./lib ./test ./rbi -type f -and ( -name *.rb -or -name *.rbi ) -print0]
fmt = xargs + %w[rubocop --fail-level F --autocorrect --format simple --]
sh("#{find.shelljoin} | #{fmt.shelljoin}")
end
multitask(:syntax_tree) do
find = %w[find ./sig -type f -name *.rbs -print0]
inplace = /darwin|bsd/ =~ RUBY_PLATFORM ? %w[-i''] : %w[-i]
uuid = SecureRandom.uuid
# `syntax_tree` has trouble with `rbs`'s class aliases
sed = xargs + %w[sed -E] + inplace + %w[-e]
# annotate class aliases with a unique comment
pre = sed + ["s/class ([^ ]+) = (.+$)/# #{uuid}\\n\\1: \\2/", "--"]
fmt = xargs + %w[stree write --plugin=rbs --]
# remove the unique comment and transform class aliases to type aliases
subst = <<~SED
s/# #{uuid}//
t l1
b
: l1
n
s/([^ :]+): (.+$)/class \\1 = \\2/
SED
# 1. delete the unique comment
# 2. if deletion happened, branch to label `l1`, else continue
# 3. transform the class alias to a type alias at label `l1`
pst = sed + [subst, "--"]
# transform class aliases to type aliases, which syntax tree has no trouble with
sh("#{find.shelljoin} | #{pre.shelljoin}")
# run syntax tree to format `*.rbs` files
sh("#{find.shelljoin} | #{fmt.shelljoin}")
# transform type aliases back to class aliases
sh("#{find.shelljoin} | #{pst.shelljoin}")
end
multitask(format: [:ruboformat, :syntax_tree])
multitask(:steep) do
sh(*%w[steep check])
end
multitask(:sorbet) do
sh(*%w[srb typecheck -- .], chdir: "./rbi")
end
file("sorbet/tapioca") do
sh(*%w[tapioca init])
end
multitask(typecheck: [:steep, :sorbet])
multitask(lint: [:rubocop, :typecheck])
multitask(:build) do
sh(*%w[gem build -- modern_treasury.gemspec])
end
multitask(release: [:build]) do
sh(*%w[gem push], *FileList["modern_treasury-*.gem"])
end