wile 0.9.261203
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.version +1 -0
- data/CREDITS.md +20 -0
- data/README.md +253 -0
- data/bin/wile +102 -0
- data/cache/.bin/pane +99 -0
- data/cache/.bin/panes +54 -0
- data/cache/.config.fish +2 -0
- data/cache/.dictionary +0 -0
- data/cache/.gemignore +16 -0
- data/cache/.gitignore +9 -0
- data/cache/.greeting.erb +1 -0
- data/cache/.irbrc +30 -0
- data/cache/.lexicon +0 -0
- data/cache/.prompt.erb +1 -0
- data/cache/.reek-strict.yml +1 -0
- data/cache/.reek.yml +1 -0
- data/cache/.rubocop-strict.yml +4 -0
- data/cache/.rubocop.yml +4 -0
- data/cache/.ruby-version-floor +1 -0
- data/cache/.ruby-version.erb +1 -0
- data/cache/.solargraph.yml +21 -0
- data/cache/.title.erb +1 -0
- data/cache/.version +1 -0
- data/cache/.wile/example.rb +56 -0
- data/cache/.wileignore +3 -0
- data/cache/CREDITS.md +10 -0
- data/cache/Gemfile +5 -0
- data/cache/Gemfile.lock +1 -0
- data/cache/History.txt +0 -0
- data/cache/README.md.erb +54 -0
- data/cache/TODO.md +3 -0
- data/cache/bin/project.erb +12 -0
- data/cache/cucumber.yml +1 -0
- data/cache/examples/README.md +3 -0
- data/cache/features/help.feature.erb +30 -0
- data/cache/features/step_definitions/command_steps.rb +171 -0
- data/cache/features/support/env.rb +11 -0
- data/cache/features/version.feature.erb +19 -0
- data/cache/git/hooks/pre-commit +93 -0
- data/cache/lib/project.rb.erb +4 -0
- data/cache/man/project.md.erb +24 -0
- data/cache/pkg/README.md +3 -0
- data/cache/test/cons.gz +0 -0
- data/cache/test/tc_comments +216 -0
- data/cache/test/tc_cucumber_slow +67 -0
- data/cache/test/tc_dependency_scrapes +126 -0
- data/cache/test/tc_dictionary +51 -0
- data/cache/test/tc_encoding +53 -0
- data/cache/test/tc_lexicon +34 -0
- data/cache/test/tc_lib_tests +37 -0
- data/cache/test/tc_lints +71 -0
- data/cache/test/tc_readme_rocket_check +128 -0
- data/cache/test/tc_reek +20 -0
- data/cache/test/tc_rubocop +20 -0
- data/cache/test/tc_ruby_syntax +28 -0
- data/cache/test/tc_tags +32 -0
- data/cache/test/tc_tasks_test +31 -0
- data/cache/test/tc_version +97 -0
- data/cache/test/tc_weird_filenames +23 -0
- data/cache/test/test_helper.rb +230 -0
- data/cache/tmp/README.md +8 -0
- data/data/command_version.tsv +281 -0
- data/dependencies.txt +70 -0
- data/lib/wile/autoloads/cache.rb +123 -0
- data/lib/wile/autoloads/code_content.rb +225 -0
- data/lib/wile/autoloads/code_data.rb +153 -0
- data/lib/wile/autoloads/code_data_function.rb +79 -0
- data/lib/wile/autoloads/code_data_valuation.rb +60 -0
- data/lib/wile/autoloads/code_stats.rb +185 -0
- data/lib/wile/autoloads/command_version.rb +119 -0
- data/lib/wile/autoloads/content.rb +196 -0
- data/lib/wile/autoloads/dependencies.rb +170 -0
- data/lib/wile/autoloads/gem_utils.rb +69 -0
- data/lib/wile/autoloads/gemspec.rb +163 -0
- data/lib/wile/autoloads/git.rb +59 -0
- data/lib/wile/autoloads/info.rb +91 -0
- data/lib/wile/autoloads/manpage.rb +44 -0
- data/lib/wile/autoloads/methods.rb +130 -0
- data/lib/wile/autoloads/nvim_files.rb +54 -0
- data/lib/wile/autoloads/options_dictionary.rb +345 -0
- data/lib/wile/autoloads/order_optimizer.rb +185 -0
- data/lib/wile/autoloads/project.rb +60 -0
- data/lib/wile/autoloads/readme.rb +137 -0
- data/lib/wile/autoloads/receivers.rb +101 -0
- data/lib/wile/autoloads/responds.rb +36 -0
- data/lib/wile/autoloads/test.rb +78 -0
- data/lib/wile/autoloads/thread_pool.rb +64 -0
- data/lib/wile/help.rb +41 -0
- data/lib/wile/requires.rb +7 -0
- data/lib/wile/run.rb +108 -0
- data/lib/wile/sysexits.rb +43 -0
- data/lib/wile/tasks/build.rb +46 -0
- data/lib/wile/tasks/bump.rb +61 -0
- data/lib/wile/tasks/compare.rb +139 -0
- data/lib/wile/tasks/content.rb +44 -0
- data/lib/wile/tasks/cp.rb +52 -0
- data/lib/wile/tasks/dependencies.rb +58 -0
- data/lib/wile/tasks/dictionary.rb +59 -0
- data/lib/wile/tasks/gemcheck.rb +142 -0
- data/lib/wile/tasks/gemfile.rb +60 -0
- data/lib/wile/tasks/help.rb +29 -0
- data/lib/wile/tasks/info.rb +77 -0
- data/lib/wile/tasks/install.rb +53 -0
- data/lib/wile/tasks/lexicon.rb +59 -0
- data/lib/wile/tasks/list.rb +97 -0
- data/lib/wile/tasks/methods.rb +154 -0
- data/lib/wile/tasks/mkdir.rb +19 -0
- data/lib/wile/tasks/note.rb +49 -0
- data/lib/wile/tasks/nvim.rb +60 -0
- data/lib/wile/tasks/order.rb +93 -0
- data/lib/wile/tasks/oscheck.rb +49 -0
- data/lib/wile/tasks/publish.rb +67 -0
- data/lib/wile/tasks/receivers.rb +34 -0
- data/lib/wile/tasks/review.rb +157 -0
- data/lib/wile/tasks/ruby.rb +38 -0
- data/lib/wile/tasks/tc.rb +114 -0
- data/lib/wile/tasks/test.rb +57 -0
- data/lib/wile/tasks/todo.rb +55 -0
- data/lib/wile/tasks/update.rb +67 -0
- data/lib/wile/tasks.rb +34 -0
- data/lib/wile/usage.rb +56 -0
- data/lib/wile/usage_error.rb +18 -0
- data/lib/wile/utilities.rb +283 -0
- data/lib/wile/utilities_refinements.rb +41 -0
- data/lib/wile/wile_refinements.rb +137 -0
- data/lib/wile.rb +39 -0
- data/man/wile.1 +1121 -0
- data/man/wile.md +786 -0
- data/pkg/README.md +3 -0
- metadata +399 -0
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
require 'prism'
|
|
6
|
+
|
|
7
|
+
# Scans Prism AST nodes for OS command invocations.
|
|
8
|
+
class OsScanner < Prism::Visitor
|
|
9
|
+
CMD_NAME = %r{\A(\w[-\w.]*)\b(?![/=])}
|
|
10
|
+
|
|
11
|
+
def initialize(calls)
|
|
12
|
+
super()
|
|
13
|
+
@calls = calls
|
|
14
|
+
@found = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def scan(source)
|
|
18
|
+
Prism.parse(source).value.accept(self)
|
|
19
|
+
@found
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def visit_interpolated_x_string_node(node)
|
|
23
|
+
first = node.parts.first
|
|
24
|
+
record(first.unescaped, node.location.start_line) if
|
|
25
|
+
first.is_a?(Prism::StringNode)
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def visit_x_string_node(node)
|
|
30
|
+
record(node.unescaped, node.location.start_line)
|
|
31
|
+
super
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def visit_call_node(node)
|
|
35
|
+
record_call(node) if os_call?(node)
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def record(text, line)
|
|
42
|
+
return unless text && (cmd = text.lstrip[CMD_NAME, 1])
|
|
43
|
+
|
|
44
|
+
@found << [cmd, line]
|
|
45
|
+
cmd
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def os_call?(node)
|
|
49
|
+
recv = node.receiver&.slice
|
|
50
|
+
@calls.any? do |pat, name|
|
|
51
|
+
name == node.name && (pat.is_a?(Regexp) ? pat.match?(recv) : pat == recv)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def record_call(node)
|
|
56
|
+
args = call_args(node)
|
|
57
|
+
return if args.empty?
|
|
58
|
+
|
|
59
|
+
line = node.location.start_line
|
|
60
|
+
cmd = record(arg_text(args.first), line)
|
|
61
|
+
record(arg_text(args[1]), line) if cmd == 'sudo'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# :reek:UtilityFunction
|
|
65
|
+
def call_args(node)
|
|
66
|
+
args = node.arguments&.arguments || []
|
|
67
|
+
args.first.is_a?(Prism::HashNode) ? args.drop(1) : args
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def arg_text(arg)
|
|
71
|
+
case arg
|
|
72
|
+
when Prism::StringNode then arg.unescaped
|
|
73
|
+
when Prism::InterpolatedStringNode then arg_text(arg.parts.first)
|
|
74
|
+
when Prism::ArrayNode then arg_text(arg.elements.first)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Comments Test ensures side comments do not contain quotes or closing
|
|
80
|
+
# delimiters (' " / ) } ]), making it simple to split "code # comment"
|
|
81
|
+
# without quote or delimiter balancing.
|
|
82
|
+
class TestComments < Test::Unit::TestCase
|
|
83
|
+
FORBIDDEN = %r{['"/)\}\]]}
|
|
84
|
+
COMMENT = /^\s*#/
|
|
85
|
+
# Known magic comments:
|
|
86
|
+
# frozen_string_literal, :reek, rubocop, wile, category.
|
|
87
|
+
KNOWN_MAGIC = %w[frozen_string_literal :reek rubocop wile category].freeze
|
|
88
|
+
LOOSE_MAGIC = /^\s*#\s*(?<key>:?[a-z_]+):/
|
|
89
|
+
STRICT_MAGIC = /^\s*# :?[a-z_]+:/
|
|
90
|
+
MAGIC_REQUIRE = /^\s*# wile: require '\w[-\w.]*(,\w[-\w.]*)*'$/
|
|
91
|
+
MAGIC_OS = /^\s*# wile: os `(\w[-\w.]*(?:,\w[-\w.]*)*)`( permit)?$/
|
|
92
|
+
OS_CALLS = [
|
|
93
|
+
[nil, :system], [nil, :spawn], ['IO', :popen],
|
|
94
|
+
# Custom callers: [receiver (nil, String, or Regexp), method_name]
|
|
95
|
+
[/\bUtilities\z/, :run], [/\bUtilities\z/, :run!]
|
|
96
|
+
].freeze
|
|
97
|
+
|
|
98
|
+
def test_comments
|
|
99
|
+
return if ruby_files.sum { check_file(it) }.zero?
|
|
100
|
+
|
|
101
|
+
print 'Remove these characters from side comments: '.blue
|
|
102
|
+
# Backslash escapes the %q delimiter; prints '"/)}] matching FORBIDDEN.
|
|
103
|
+
puts %q('"/\)}]).red
|
|
104
|
+
flunk
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def test_magic_comments
|
|
108
|
+
flunk 'Invalid magic comments found.'.red if
|
|
109
|
+
ruby_files.sum { check_magic_comments(it) }.positive?
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def test_os_commands = quiet? || ruby_files.each { check_os_commands(it) }
|
|
113
|
+
|
|
114
|
+
private
|
|
115
|
+
|
|
116
|
+
def check_file(filename)
|
|
117
|
+
source = File.read(filename)
|
|
118
|
+
lines = source.lines
|
|
119
|
+
Prism.parse_comments(source).grep(Prism::InlineComment).count do |comment|
|
|
120
|
+
bad_comment?(filename, comment, lines[comment.location.start_line - 1])
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def check_magic_comments(filename)
|
|
125
|
+
lines = File.readlines(filename)
|
|
126
|
+
lines.each_with_index.sum do |line, idx|
|
|
127
|
+
check_magic_line(filename, line, lines[idx + 1], idx + 1)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def bad_comment?(filename, comment, line)
|
|
132
|
+
return false if /^\s*#/.match?(line)
|
|
133
|
+
|
|
134
|
+
loc = comment.location
|
|
135
|
+
return false unless FORBIDDEN.match?(loc.slice)
|
|
136
|
+
|
|
137
|
+
puts_blue(filename, loc.start_line, line)
|
|
138
|
+
true
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def valid_wile?(line) = MAGIC_REQUIRE.match?(line) || MAGIC_OS.match?(line)
|
|
142
|
+
|
|
143
|
+
def bad_magic_format?(filename, line_number, line, key)
|
|
144
|
+
valid = STRICT_MAGIC.match?(line) && (key != 'wile' || valid_wile?(line))
|
|
145
|
+
return false if valid
|
|
146
|
+
|
|
147
|
+
puts_blue(filename, line_number, line)
|
|
148
|
+
true
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def puts_blue(file, num, line) = puts "#{file}:#{num}:#{line.chomp}".blue
|
|
152
|
+
|
|
153
|
+
def check_magic_line(filename, line, next_line, line_number)
|
|
154
|
+
match = LOOSE_MAGIC.match(line)
|
|
155
|
+
return 0 unless match
|
|
156
|
+
|
|
157
|
+
key = match[:key]
|
|
158
|
+
return alert_unknown(filename, line_number, line, key) unless known?(key)
|
|
159
|
+
|
|
160
|
+
errors = bad_magic_format?(filename, line_number, line, key) ? 1 : 0
|
|
161
|
+
errors + (bad_magic_follow?(filename, line_number + 1, next_line) ? 1 : 0)
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def known?(key) = KNOWN_MAGIC.include?(key)
|
|
165
|
+
|
|
166
|
+
def bad_magic_follow?(filename, line_number, next_line)
|
|
167
|
+
return false unless next_line && COMMENT.match?(next_line)
|
|
168
|
+
return false if STRICT_MAGIC.match?(next_line) &&
|
|
169
|
+
known?(LOOSE_MAGIC.match(next_line)&.[](:key))
|
|
170
|
+
|
|
171
|
+
puts_blue(filename, line_number, next_line)
|
|
172
|
+
true
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def alert_unknown(filename, line_number, line, key)
|
|
176
|
+
return 0 if quiet? || /^\s*# {4}/.match?(line)
|
|
177
|
+
|
|
178
|
+
puts_alert("Unknown magic comment: #{filename}:#{line_number}:", line, key)
|
|
179
|
+
0
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
def check_os_commands(filename)
|
|
183
|
+
source = File.read(filename)
|
|
184
|
+
lines = source.lines
|
|
185
|
+
accepted = collect_os_magic(lines)
|
|
186
|
+
OsScanner.new(OS_CALLS).scan(source).each do |cmd, num|
|
|
187
|
+
next accepted[cmd] = nil if accepted.key?(cmd)
|
|
188
|
+
|
|
189
|
+
line = lines[num - 1]
|
|
190
|
+
next if line.chomp.end_with?('# permit')
|
|
191
|
+
|
|
192
|
+
puts_alert("Unregistered os command: #{filename}:#{num}:", line, cmd)
|
|
193
|
+
end
|
|
194
|
+
alert_unused_os(filename, accepted)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def puts_alert(head, line, token)
|
|
198
|
+
before, after = line.chomp.split(token, 2)
|
|
199
|
+
puts [(head + before).yellow, token.black, after.yellow].join
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
def alert_unused_os(filename, accepted)
|
|
203
|
+
accepted.compact.each do |cmd, (num, src)|
|
|
204
|
+
puts_alert("Unused os command: #{filename}:#{num}:", src, cmd)
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def collect_os_magic(lines)
|
|
209
|
+
lines.each_with_index.with_object({}) do |(line, idx), acc|
|
|
210
|
+
next unless (match = MAGIC_OS.match(line))
|
|
211
|
+
|
|
212
|
+
val = match[2] ? nil : [idx + 1, line]
|
|
213
|
+
match[1].split(',').each { acc[it] = val unless acc.key?(it) }
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'etc'
|
|
5
|
+
require_relative 'test_helper'
|
|
6
|
+
# wile: require 'cucumber'
|
|
7
|
+
# wile: os `cucumber`
|
|
8
|
+
|
|
9
|
+
# Cucumber Tests runs the feature suite and flunks if any scenario fails.
|
|
10
|
+
class TestCucumber < Test::Unit::TestCase
|
|
11
|
+
def test_cucumber
|
|
12
|
+
if quiet?
|
|
13
|
+
batch_cucumber
|
|
14
|
+
else
|
|
15
|
+
normal_cucumber
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def normal_cucumber
|
|
22
|
+
res = system('cucumber', '-f', 'progress')
|
|
23
|
+
flunk 'cucumber command not found!'.red if res.nil?
|
|
24
|
+
flunk 'Rotten cucumber!'.red unless res
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# :reek:UtilityFunction
|
|
28
|
+
def batch_worker(queue, state)
|
|
29
|
+
while (ff = queue.pop)
|
|
30
|
+
res = system('cucumber', '-f', 'progress', ff,
|
|
31
|
+
out: File::NULL, err: File::NULL)
|
|
32
|
+
state[:mutex].synchronize { state[:failed] << ff } unless res
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def run_workers(limit, queue)
|
|
37
|
+
state = { failed: [], mutex: Mutex.new }
|
|
38
|
+
Array.new(limit) do
|
|
39
|
+
Thread.new { batch_worker(queue, state) }
|
|
40
|
+
end.each(&:join)
|
|
41
|
+
state[:failed].sort
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# :reek:UtilityFunction
|
|
45
|
+
def feature_queue
|
|
46
|
+
queue = Thread::Queue.new
|
|
47
|
+
Dir['features/*.feature'].each { queue << it }
|
|
48
|
+
queue.close
|
|
49
|
+
queue
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def report_failures(failed)
|
|
53
|
+
return if failed.empty?
|
|
54
|
+
|
|
55
|
+
msg = failed.size == 1 ? failed.first : "\n#{failed.join("\n")}"
|
|
56
|
+
flunk "Rotten cucumber in: #{msg}".red
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def batch_cucumber
|
|
60
|
+
res = system('cucumber', '--version', out: File::NULL, err: File::NULL)
|
|
61
|
+
flunk 'cucumber command not found!'.red if res.nil?
|
|
62
|
+
|
|
63
|
+
limit = [1, (Etc.nprocessors * 0.5).round].max
|
|
64
|
+
failed = run_workers(limit, feature_queue)
|
|
65
|
+
report_failures(failed)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
|
|
6
|
+
# Lints require, require_relative, autoload, and `# wile: require`
|
|
7
|
+
# statements to ensure compatibility with Wile's dependency scraper.
|
|
8
|
+
class TestDependencyScrapes < Test::Unit::TestCase
|
|
9
|
+
DIRECTIVE = /^\s*#\s*wile:\s*require\b/
|
|
10
|
+
VALID_DIRECTIVE = /^\s*# wile: require '\w[-\w.]*(,\w[-\w.]*)*'$/
|
|
11
|
+
OS_DIRECTIVE = /^\s*#\s*wile:\s*os\b/
|
|
12
|
+
VALID_OS_DIRECTIVE = /^\s*# wile: os `\w[-\w.]*(,\w[-\w.]*)*`( permit)?$/
|
|
13
|
+
DOUBLE_QUOTE_REQUIRE = /\brequire(_relative)?\s*"/
|
|
14
|
+
AUTOLOAD_CONST = /\bautoload\s+['"][A-Z]/
|
|
15
|
+
AUTOLOAD_DOUBLE_QUOTE = /\bautoload\s+:\w+,\s*"/
|
|
16
|
+
|
|
17
|
+
def test_require_lines
|
|
18
|
+
errors = ruby_files.flat_map { check_file(it) }
|
|
19
|
+
assert_empty errors, "Malformed require lines:\n#{errors.join("\n").red}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_valid_lines
|
|
23
|
+
assert_nil chk("require 'json'")
|
|
24
|
+
assert_nil chk("require_relative 'test_helper'")
|
|
25
|
+
assert_nil chk('require_relative "tasks/\#{task}"')
|
|
26
|
+
assert_nil chk("autoload :JSON, 'json'")
|
|
27
|
+
assert_nil chk("autoload :Run, File.join(__dir__, 'run')")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_valid_directive_lines
|
|
31
|
+
assert_nil chk("# wile: require 'tmuxinator'")
|
|
32
|
+
assert_nil chk("# wile: require 'reek,rubocop'")
|
|
33
|
+
assert_nil chk('# wile: os `diff`')
|
|
34
|
+
assert_nil chk('# wile: os `diff,apt-get`')
|
|
35
|
+
assert_nil chk('# wile: os `curl` permit')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def test_invalid_require_lines
|
|
39
|
+
assert_match 'must use single quotes', chk('require "json"')
|
|
40
|
+
assert_match 'must use single quotes', chk('require_relative "test_helper"')
|
|
41
|
+
assert_match 'must use single quotes', chk('# wile: require "tmuxinator"')
|
|
42
|
+
assert_match "must not contain '/'",
|
|
43
|
+
chk("# wile: require 'irbtools/configure'")
|
|
44
|
+
assert_match 'malformed', chk('# wile: require tmuxinator')
|
|
45
|
+
assert_match 'malformed', chk("# wile: require 'colora'")
|
|
46
|
+
assert_match 'malformed', chk("# wile: require 'reek, rubocop'")
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_invalid_os_directive_lines
|
|
50
|
+
assert_match 'must use backticks', chk("# wile: os 'diff'")
|
|
51
|
+
assert_match 'must use backticks', chk('# wile: os "diff"')
|
|
52
|
+
assert_match 'malformed', chk('# wile: os diff')
|
|
53
|
+
assert_match 'malformed', chk('# wile: os `dpkg-query`')
|
|
54
|
+
assert_match 'malformed', chk('# wile: os `diff, apt-get`')
|
|
55
|
+
assert_match 'malformed', chk('# wile: os `curl` bogus')
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_invalid_autoload_lines
|
|
59
|
+
assert_match 'constant must be a symbol', chk("autoload 'JSON', 'json'")
|
|
60
|
+
assert_match 'must use single quotes', chk('autoload :JSON, "json"')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def chk(line) = check_line('f.rb', 1, line)
|
|
66
|
+
|
|
67
|
+
def ruby_files
|
|
68
|
+
files = super.reject { it.end_with?('tc_dependency_scrapes') }
|
|
69
|
+
files << '.irbrc' if File.file?('.irbrc')
|
|
70
|
+
files
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def check_file(filename)
|
|
74
|
+
File.readlines(filename).filter_map.with_index(1) do |line, lineno|
|
|
75
|
+
check_line(filename, lineno, line)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def check_line(filename, lineno, line)
|
|
80
|
+
return check_wile_directive(filename, lineno, line) if line.match?(/^\s*#/)
|
|
81
|
+
|
|
82
|
+
check_code_line(filename, lineno, line)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def check_wile_directive(filename, lineno, line)
|
|
86
|
+
return check_directive(filename, lineno, line) if line.match?(DIRECTIVE)
|
|
87
|
+
|
|
88
|
+
check_os_directive(filename, lineno, line) if line.match?(OS_DIRECTIVE)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def check_code_line(filename, lineno, line)
|
|
92
|
+
if line.match?(DOUBLE_QUOTE_REQUIRE)
|
|
93
|
+
return if line.include?('#{')
|
|
94
|
+
|
|
95
|
+
"#{filename}:#{lineno}: require must use single quotes: #{line.strip}"
|
|
96
|
+
elsif line.match?(/\bautoload\b/)
|
|
97
|
+
check_autoload(filename, lineno, line)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def check_autoload(filename, lineno, line)
|
|
102
|
+
if line.match?(AUTOLOAD_CONST)
|
|
103
|
+
"#{filename}:#{lineno}: autoload constant must be a symbol"
|
|
104
|
+
elsif line.match?(AUTOLOAD_DOUBLE_QUOTE) && !line.include?('#{')
|
|
105
|
+
"#{filename}:#{lineno}: autoload must use single quotes"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def check_directive(filename, lineno, line)
|
|
110
|
+
if line.include?('"')
|
|
111
|
+
"#{filename}:#{lineno}: # wile: require must use single quotes"
|
|
112
|
+
elsif line.include?('/')
|
|
113
|
+
"#{filename}:#{lineno}: # wile: require must not contain '/'"
|
|
114
|
+
elsif !line.match?(VALID_DIRECTIVE)
|
|
115
|
+
"#{filename}:#{lineno}: # wile: require malformed: #{line.strip}"
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def check_os_directive(filename, lineno, line)
|
|
120
|
+
if line.include?("'") || line.include?('"')
|
|
121
|
+
"#{filename}:#{lineno}: # wile: os must use backticks"
|
|
122
|
+
elsif !line.match?(VALID_OS_DIRECTIVE)
|
|
123
|
+
"#{filename}:#{lineno}: # wile: os malformed: #{line.strip}"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
require 'zlib'
|
|
6
|
+
require 'fileutils'
|
|
7
|
+
|
|
8
|
+
# Dictionary Test uses Trigram-Based Spelling to detect non-standard words,
|
|
9
|
+
# asserting that any unrecognized terms match the .dictionary whitelist.
|
|
10
|
+
class TestDictionary < Test::Unit::TestCase
|
|
11
|
+
FILES = ['README.md', *Dir.glob('bin/*'), *Dir.glob('lib/**/*.rb')].freeze
|
|
12
|
+
VALID = Zlib::GzipReader.open('test/cons.gz') { it.readlines.to_set(&:strip) }
|
|
13
|
+
|
|
14
|
+
def test_dictionary
|
|
15
|
+
FileUtils.mkdir_p('tmp')
|
|
16
|
+
unrecognized = words_from_files.select { unrecognized?(it) }.sort
|
|
17
|
+
File.open('tmp/.dictionary', 'w') { it.puts unrecognized }
|
|
18
|
+
diff = diff_output('.dictionary', 'tmp/.dictionary')
|
|
19
|
+
assert_empty(diff, "#{'Dictionary changed:'.colorize(:blue)}\n#{diff}")
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
### Trigram-Based Spelling ###
|
|
25
|
+
# Note that `.all?` is true if not iterated.
|
|
26
|
+
# If word.length<3, the word is assumed good.
|
|
27
|
+
def unrecognized?(word)
|
|
28
|
+
!word.chars.each_cons(3).all? { VALID.include? it.join }
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def words_from_files
|
|
32
|
+
FILES.flat_map do |path|
|
|
33
|
+
next [] unless File.file?(path)
|
|
34
|
+
|
|
35
|
+
extract_words(File.read(path))
|
|
36
|
+
end.uniq
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Extracts normalized words from code and documentation text:
|
|
40
|
+
# 1. Splits camelCase and PascalCase into separate words.
|
|
41
|
+
# 2. Scans for alphabetical tokens, optionally prefixed with backslash.
|
|
42
|
+
# 3. Strips escape prefixes (e.g. hex escapes).
|
|
43
|
+
# 4. Discards empty tokens and downcases to lowercase words.
|
|
44
|
+
def extract_words(text)
|
|
45
|
+
text.gsub(/([a-z])([A-Z])/, '\1 \2')
|
|
46
|
+
.scan(/\\?[a-zA-Z]+/)
|
|
47
|
+
.map { it.start_with?('\\') ? it[2..] : it }
|
|
48
|
+
.reject(&:empty?)
|
|
49
|
+
.map(&:downcase)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
require 'find'
|
|
6
|
+
|
|
7
|
+
# Encoding Test reports non-ASCII characters and verifies valid UTF-8.
|
|
8
|
+
class TestEncoding < Test::Unit::TestCase
|
|
9
|
+
ALLOWED_BINARY = %w[.gem .gz .ico .jpeg .jpg .pdf .png .idx .dat].freeze
|
|
10
|
+
PRUNED = %w[./.git ./tmp ./wiki].freeze
|
|
11
|
+
SKIP_REPORT = %w[features/fixtures/ man/].freeze
|
|
12
|
+
|
|
13
|
+
def test_encoding
|
|
14
|
+
invalid = []
|
|
15
|
+
Find.find('.') do |path|
|
|
16
|
+
Find.prune if PRUNED.include?(path)
|
|
17
|
+
check_path(path, invalid) if File.file?(path)
|
|
18
|
+
end
|
|
19
|
+
assert_empty invalid,
|
|
20
|
+
"Invalid UTF-8 sequences found:\n#{invalid.join("\n")}"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def check_path(path, invalid)
|
|
26
|
+
return if ALLOWED_BINARY.include?(File.extname(path))
|
|
27
|
+
|
|
28
|
+
rel = path.delete_prefix('./')
|
|
29
|
+
if binary?(path)
|
|
30
|
+
invalid << "#{rel}: Unexpected binary content in text file".red
|
|
31
|
+
return
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
scan_file(rel, invalid)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def scan_file(filename, invalid)
|
|
38
|
+
File.foreach(filename, chomp: true).with_index(1) do |line, lno|
|
|
39
|
+
unless line.valid_encoding? && !line.include?("\x00")
|
|
40
|
+
invalid << "#{filename}:#{lno}: #{line.scrub}".red
|
|
41
|
+
next
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
puts "#{filename}:#{lno}: #{line}".gray if report_utf8?(filename, line)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def report_utf8?(filename, line)
|
|
49
|
+
return false if quiet? || line.ascii_only? || line.end_with?('# UTF-8')
|
|
50
|
+
|
|
51
|
+
SKIP_REPORT.none? { filename.start_with?(it) }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
require 'fileutils'
|
|
6
|
+
# wile: require 'parser'
|
|
7
|
+
# wile: os `ruby-parse`
|
|
8
|
+
|
|
9
|
+
# Lexicon Test scans the codebase AST for symbols and identifiers,
|
|
10
|
+
# asserting that the vocabulary matches the committed .lexicon whitelist.
|
|
11
|
+
class TestLexicon < Test::Unit::TestCase
|
|
12
|
+
FILES = [*Dir.glob('bin/*'), *Dir.glob('lib/**/*.rb')].freeze
|
|
13
|
+
|
|
14
|
+
def test_lexicon
|
|
15
|
+
FileUtils.mkdir_p('tmp')
|
|
16
|
+
File.open('tmp/.lexicon', 'w') { it.puts(lexicon_words) }
|
|
17
|
+
diff = diff_output('.lexicon', 'tmp/.lexicon')
|
|
18
|
+
assert_empty(diff, "#{'Code lexicon changed:'.colorize(:blue)}\n#{diff}")
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def lexicon_words
|
|
24
|
+
files = FILES.select { File.file?(it) }
|
|
25
|
+
flunk 'No files found for lexicon scan!'.red if files.empty?
|
|
26
|
+
|
|
27
|
+
output = IO.popen(['ruby-parse', *files], err: File::NULL, &:read)
|
|
28
|
+
extract_lexicon(output)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def extract_lexicon(text)
|
|
32
|
+
text.scan(/:@?(\w+)/).flatten.uniq.sort
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
|
|
6
|
+
# Fail-less warnings of missing lib tests.
|
|
7
|
+
class TestLibTests < Test::Unit::TestCase
|
|
8
|
+
def test_lib_tests
|
|
9
|
+
return if quiet?
|
|
10
|
+
|
|
11
|
+
lib_files.each do |file|
|
|
12
|
+
test_file = expected_test(file)
|
|
13
|
+
next if test_exists?(test_file)
|
|
14
|
+
|
|
15
|
+
puts "Missing: #{test_file}".yellow
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def lib_files
|
|
22
|
+
Dir.glob('lib/**/*.rb').reject { it.include?('/tasks/') }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_exists?(test_file)
|
|
26
|
+
File.exist?(test_file) || File.exist?("#{test_file}_slow")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def expected_test(file)
|
|
30
|
+
parts = file.split('/')
|
|
31
|
+
parts.delete('autoloads')
|
|
32
|
+
parts.shift
|
|
33
|
+
parts.shift if parts.length > 1
|
|
34
|
+
parts.unshift('tc_ut')
|
|
35
|
+
"test/#{parts.join('_').chomp('.rb')}"
|
|
36
|
+
end
|
|
37
|
+
end
|
data/cache/test/tc_lints
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative 'test_helper'
|
|
5
|
+
require 'prism'
|
|
6
|
+
|
|
7
|
+
# Scans Prism AST nodes for configured method calls.
|
|
8
|
+
class CallScanner < Prism::Visitor
|
|
9
|
+
def initialize(calls)
|
|
10
|
+
super()
|
|
11
|
+
@calls = calls
|
|
12
|
+
@found = []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def scan(source)
|
|
16
|
+
Prism.parse(source).value.accept(self)
|
|
17
|
+
@found
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.match_call?(node, entry)
|
|
21
|
+
pat, name = entry
|
|
22
|
+
return false unless node.name == name
|
|
23
|
+
|
|
24
|
+
recv = node.receiver&.slice
|
|
25
|
+
pat.is_a?(Regexp) ? pat.match?(recv) : pat == recv
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.label(node)
|
|
29
|
+
[node.receiver&.slice, node.name].compact.join('.')
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def visit_call_node(node)
|
|
33
|
+
match = @calls.find { CallScanner.match_call?(node, it) }
|
|
34
|
+
@found << [match[2], CallScanner.label(node), node.location.start_line] if
|
|
35
|
+
match
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Fail-less lint checks for Wile's code expectations.
|
|
41
|
+
class TestLints < Test::Unit::TestCase
|
|
42
|
+
CALLS = [
|
|
43
|
+
[nil, :system, /system(?:\(|\s+)["'][a-z]/],
|
|
44
|
+
['Kernel', :system, /Kernel\.system(?:\(|\s+)["'][a-z]/],
|
|
45
|
+
[nil, :spawn, /spawn(?:\(|\s+)["'][a-z]/],
|
|
46
|
+
['Kernel', :spawn, /Kernel\.spawn(?:\(|\s+)["'][a-z]/],
|
|
47
|
+
['IO', :popen, /IO\.popen(?:\(|\s+)\[?["'][a-z]/],
|
|
48
|
+
# Custom calls:
|
|
49
|
+
[/\bUtilities\z/, :run, /Utilities\.run(?:\(|\s+)["'][a-z]/],
|
|
50
|
+
[/\bUtilities\z/, :run!, /Utilities\.run!(?:\(|\s+)["'][a-z]/]
|
|
51
|
+
].freeze
|
|
52
|
+
|
|
53
|
+
def test_calls = quiet? || ruby_files.each { check_calls(it) }
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def check_calls(filename)
|
|
58
|
+
source = File.read(filename)
|
|
59
|
+
lines = source.lines
|
|
60
|
+
CallScanner.new(CALLS).scan(source).each do |pattern, label, num|
|
|
61
|
+
alert_call("#{filename}:#{num}", [pattern, label], lines[num - 1].chomp)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def alert_call(loc, match, line)
|
|
66
|
+
pattern, label = match
|
|
67
|
+
return if pattern.match?(line) || line.end_with?('# permit')
|
|
68
|
+
|
|
69
|
+
puts "#{label}: #{loc}:#{line}".yellow
|
|
70
|
+
end
|
|
71
|
+
end
|