ruby-lint 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +43 -29
  3. data/LICENSE +1 -1
  4. data/README.md +0 -1
  5. data/bin/ruby-lint +91 -3
  6. data/checksum/ruby-lint-1.1.0.gem.sha512 +1 -0
  7. data/doc/changelog.md +30 -0
  8. data/doc/code_analysis.md +13 -0
  9. data/doc/configuration.md +5 -24
  10. data/lib/ruby-lint.rb +7 -10
  11. data/lib/ruby-lint/analysis/argument_amount.rb +2 -0
  12. data/lib/ruby-lint/analysis/base.rb +12 -0
  13. data/lib/ruby-lint/analysis/pedantics.rb +2 -0
  14. data/lib/ruby-lint/analysis/shadowing_variables.rb +2 -0
  15. data/lib/ruby-lint/analysis/undefined_methods.rb +5 -2
  16. data/lib/ruby-lint/analysis/undefined_variables.rb +2 -0
  17. data/lib/ruby-lint/analysis/unused_variables.rb +2 -0
  18. data/lib/ruby-lint/analysis/useless_equality_checks.rb +2 -0
  19. data/lib/ruby-lint/ast/node.rb +0 -15
  20. data/lib/ruby-lint/command.rb +100 -0
  21. data/lib/ruby-lint/configuration.rb +35 -66
  22. data/lib/ruby-lint/constant_path.rb +7 -2
  23. data/lib/ruby-lint/definition/ruby_object.rb +20 -6
  24. data/lib/ruby-lint/definitions/core/argf.rb +3 -3
  25. data/lib/ruby-lint/definitions/gems/minitest.rb +792 -0
  26. data/lib/ruby-lint/file_list.rb +1 -1
  27. data/lib/ruby-lint/file_loader.rb +2 -20
  28. data/lib/ruby-lint/file_scanner.rb +11 -2
  29. data/lib/ruby-lint/method_evaluation.rb +21 -0
  30. data/lib/ruby-lint/presenter/base.rb +18 -0
  31. data/lib/ruby-lint/presenter/json.rb +3 -1
  32. data/lib/ruby-lint/presenter/syntastic.rb +3 -1
  33. data/lib/ruby-lint/presenter/text.rb +3 -1
  34. data/lib/ruby-lint/runner.rb +6 -63
  35. data/lib/ruby-lint/variable_predicates.rb +3 -3
  36. data/lib/ruby-lint/version.rb +1 -1
  37. data/lib/ruby-lint/virtual_machine.rb +4 -1
  38. data/ruby-lint.gemspec +13 -4
  39. metadata +12 -187
  40. data/.editorconfig +0 -15
  41. data/.gitignore +0 -6
  42. data/.ruby-version +0 -1
  43. data/.travis.yml +0 -19
  44. data/Gemfile +0 -15
  45. data/MANIFEST +0 -469
  46. data/Rakefile +0 -25
  47. data/benchmark/bootup.rb +0 -13
  48. data/benchmark/virtual_machine.rb +0 -17
  49. data/checksum/.gitkeep +0 -0
  50. data/doc/.gitkeep +0 -0
  51. data/doc/css/.gitkeep +0 -0
  52. data/doc/images/.gitkeep +0 -0
  53. data/gen/rails/constants.txt +0 -12
  54. data/gen/rails/requires.rb +0 -2
  55. data/gen/stdlib/constants.rb +0 -30
  56. data/gen/stdlib/constants.txt +0 -214
  57. data/gen/stdlib/requires.rb +0 -64
  58. data/lib/ruby-lint/benchmark/average.rb +0 -115
  59. data/lib/ruby-lint/cache.rb +0 -121
  60. data/lib/ruby-lint/cache_entry.rb +0 -44
  61. data/lib/ruby-lint/cli.rb +0 -4
  62. data/lib/ruby-lint/cli/analyze.rb +0 -209
  63. data/lib/ruby-lint/cli/base.rb +0 -103
  64. data/lib/ruby-lint/cli/cache.rb +0 -60
  65. data/lib/ruby-lint/default_names.rb +0 -19
  66. data/lib/ruby-lint/definitions/gems/.gitkeep +0 -0
  67. data/lib/ruby-lint/node_hash.rb +0 -105
  68. data/misc/stdlib.rb +0 -66
  69. data/profiling/virtual_machine.rb +0 -20
  70. data/ruby-lint.yml +0 -7
  71. data/spec/fixtures/associating.rb +0 -7
  72. data/spec/fixtures/complex/rails/basic_controller.rb +0 -9
  73. data/spec/fixtures/complex/rcap.rb +0 -67
  74. data/spec/fixtures/complex/slop.rb +0 -701
  75. data/spec/fixtures/config.yml +0 -8
  76. data/spec/fixtures/deeply/nested/file.rb +0 -1
  77. data/spec/fixtures/file_scanner/lib/example/recursive/source.rb +0 -6
  78. data/spec/fixtures/file_scanner/lib/example/recursive/target.rb +0 -8
  79. data/spec/fixtures/file_scanner/lib/example/user.rb +0 -6
  80. data/spec/fixtures/file_scanner/lib/ruby-lint/definition/constant_proxy.rb +0 -6
  81. data/spec/fixtures/file_scanner/lib/ruby-lint/global_scope.rb +0 -6
  82. data/spec/fixtures/file_scanner/lib/test-dashes/foo.rb +0 -4
  83. data/spec/fixtures/file_scanner/rails/app/models/example/user.rb +0 -6
  84. data/spec/fixtures/file_scanner/rails/app/models/user.rb +0 -4
  85. data/spec/fixtures/invalid.rb +0 -3
  86. data/spec/fixtures/invalid_2.rb +0 -3
  87. data/spec/fixtures/syntax_error.rb +0 -1
  88. data/spec/fixtures/uses_external.rb +0 -1
  89. data/spec/fixtures/uses_external_invalid.rb +0 -3
  90. data/spec/fixtures/uses_external_namespace.rb +0 -1
  91. data/spec/fixtures/valid.rb +0 -3
  92. data/spec/ruby-lint/analysis/argument_amount_spec.rb +0 -131
  93. data/spec/ruby-lint/analysis/base_spec.rb +0 -24
  94. data/spec/ruby-lint/analysis/pedantics_spec.rb +0 -63
  95. data/spec/ruby-lint/analysis/shadowing_variables_spec.rb +0 -85
  96. data/spec/ruby-lint/analysis/undefined_methods_spec.rb +0 -337
  97. data/spec/ruby-lint/analysis/undefined_variables_spec.rb +0 -138
  98. data/spec/ruby-lint/analysis/unused_variables_spec.rb +0 -270
  99. data/spec/ruby-lint/analysis/useless_equality_checks_spec.rb +0 -107
  100. data/spec/ruby-lint/ast/node_spec.rb +0 -39
  101. data/spec/ruby-lint/cache_entry_spec.rb +0 -25
  102. data/spec/ruby-lint/cache_spec.rb +0 -53
  103. data/spec/ruby-lint/cli/analyze_spec.rb +0 -52
  104. data/spec/ruby-lint/configuration_spec.rb +0 -126
  105. data/spec/ruby-lint/constant_loader_spec.rb +0 -79
  106. data/spec/ruby-lint/constant_path.rb +0 -63
  107. data/spec/ruby-lint/definition/constant_proxy_spec.rb +0 -85
  108. data/spec/ruby-lint/definition/dsl_spec.rb +0 -135
  109. data/spec/ruby-lint/definition/registry_spec.rb +0 -106
  110. data/spec/ruby-lint/definition/ruby_method_spec.rb +0 -106
  111. data/spec/ruby-lint/definition/ruby_object_spec.rb +0 -264
  112. data/spec/ruby-lint/definition_builder/primitive_spec.rb +0 -62
  113. data/spec/ruby-lint/definition_builder/ruby_class_spec.rb +0 -107
  114. data/spec/ruby-lint/definition_builder/ruby_method_spec.rb +0 -53
  115. data/spec/ruby-lint/definition_builder/ruby_module_spec.rb +0 -52
  116. data/spec/ruby-lint/definitions/argv_spec.rb +0 -18
  117. data/spec/ruby-lint/definitions/env_spec.rb +0 -13
  118. data/spec/ruby-lint/definitions/file_spec.rb +0 -17
  119. data/spec/ruby-lint/definitions/fixnum_spec.rb +0 -18
  120. data/spec/ruby-lint/definitions/io_spec.rb +0 -15
  121. data/spec/ruby-lint/definitions/kernel_spec.rb +0 -18
  122. data/spec/ruby-lint/definitions/range_spec.rb +0 -21
  123. data/spec/ruby-lint/definitions/string_spec.rb +0 -20
  124. data/spec/ruby-lint/docstring/mapping.rb +0 -27
  125. data/spec/ruby-lint/docstring/parser_spec.rb +0 -88
  126. data/spec/ruby-lint/extensions/string_spec.rb +0 -7
  127. data/spec/ruby-lint/file_list_spec.rb +0 -25
  128. data/spec/ruby-lint/file_loader_spec.rb +0 -69
  129. data/spec/ruby-lint/file_scanner_spec.rb +0 -84
  130. data/spec/ruby-lint/inspector_spec.rb +0 -224
  131. data/spec/ruby-lint/iterator_spec.rb +0 -151
  132. data/spec/ruby-lint/method_call/.gitkeep +0 -0
  133. data/spec/ruby-lint/nested_stack_spec.rb +0 -23
  134. data/spec/ruby-lint/node_hash_spec.rb +0 -56
  135. data/spec/ruby-lint/parser_spec.rb +0 -38
  136. data/spec/ruby-lint/presenter/json_spec.rb +0 -58
  137. data/spec/ruby-lint/presenter/syntastic_spec.rb +0 -49
  138. data/spec/ruby-lint/presenter/text_spec.rb +0 -49
  139. data/spec/ruby-lint/report/entry_spec.rb +0 -58
  140. data/spec/ruby-lint/report_spec.rb +0 -39
  141. data/spec/ruby-lint/runner_spec.rb +0 -74
  142. data/spec/ruby-lint/variable_predicates_spec.rb +0 -30
  143. data/spec/ruby-lint/virtual_machine/alias_spec.rb +0 -55
  144. data/spec/ruby-lint/virtual_machine/assignments/arrays_spec.rb +0 -87
  145. data/spec/ruby-lint/virtual_machine/assignments/assignment_arguments_spec.rb +0 -14
  146. data/spec/ruby-lint/virtual_machine/assignments/constants_spec.rb +0 -23
  147. data/spec/ruby-lint/virtual_machine/assignments/hashes_spec.rb +0 -52
  148. data/spec/ruby-lint/virtual_machine/assignments/optional_spec.rb +0 -41
  149. data/spec/ruby-lint/virtual_machine/assignments/range_spec.rb +0 -28
  150. data/spec/ruby-lint/virtual_machine/assignments/return_values_spec.rb +0 -78
  151. data/spec/ruby-lint/virtual_machine/assignments/variables_spec.rb +0 -130
  152. data/spec/ruby-lint/virtual_machine/associate_nodes_spec.rb +0 -61
  153. data/spec/ruby-lint/virtual_machine/autoloading_spec.rb +0 -18
  154. data/spec/ruby-lint/virtual_machine/blocks_spec.rb +0 -90
  155. data/spec/ruby-lint/virtual_machine/classes/class_methods_spec.rb +0 -21
  156. data/spec/ruby-lint/virtual_machine/classes/extending_spec.rb +0 -109
  157. data/spec/ruby-lint/virtual_machine/classes/redefining_spec.rb +0 -51
  158. data/spec/ruby-lint/virtual_machine/classes/sclass_spec.rb +0 -96
  159. data/spec/ruby-lint/virtual_machine/classes/scoping_spec.rb +0 -60
  160. data/spec/ruby-lint/virtual_machine/complex/rails_spec.rb +0 -21
  161. data/spec/ruby-lint/virtual_machine/complex/rcap_spec.rb +0 -15
  162. data/spec/ruby-lint/virtual_machine/complex/slop_spec.rb +0 -16
  163. data/spec/ruby-lint/virtual_machine/constants_spec.rb +0 -31
  164. data/spec/ruby-lint/virtual_machine/for_spec.rb +0 -16
  165. data/spec/ruby-lint/virtual_machine/freeze_spec.rb +0 -13
  166. data/spec/ruby-lint/virtual_machine/global_variables_spec.rb +0 -15
  167. data/spec/ruby-lint/virtual_machine/inherit_kernel_spec.rb +0 -15
  168. data/spec/ruby-lint/virtual_machine/interpolation_spec.rb +0 -12
  169. data/spec/ruby-lint/virtual_machine/location_spec.rb +0 -64
  170. data/spec/ruby-lint/virtual_machine/method_call_tracking_spec.rb +0 -57
  171. data/spec/ruby-lint/virtual_machine/methods/attr_spec.rb +0 -182
  172. data/spec/ruby-lint/virtual_machine/methods/calls_spec.rb +0 -25
  173. data/spec/ruby-lint/virtual_machine/methods/define_method_spec.rb +0 -41
  174. data/spec/ruby-lint/virtual_machine/methods/defining_spec.rb +0 -40
  175. data/spec/ruby-lint/virtual_machine/methods/docstrings_spec.rb +0 -80
  176. data/spec/ruby-lint/virtual_machine/methods/exporting_spec.rb +0 -19
  177. data/spec/ruby-lint/virtual_machine/methods/kernel_spec.rb +0 -25
  178. data/spec/ruby-lint/virtual_machine/methods/parameters_spec.rb +0 -89
  179. data/spec/ruby-lint/virtual_machine/methods/patching_spec.rb +0 -20
  180. data/spec/ruby-lint/virtual_machine/methods/scoping_spec.rb +0 -63
  181. data/spec/ruby-lint/virtual_machine/methods/square_bracket_spec.rb +0 -32
  182. data/spec/ruby-lint/virtual_machine/methods/visibility_spec.rb +0 -64
  183. data/spec/ruby-lint/virtual_machine/modules_spec.rb +0 -205
  184. data/spec/ruby-lint/virtual_machine/reference_amount_spec.rb +0 -81
  185. data/spec/ruby-lint/virtual_machine/self_spec.rb +0 -37
  186. data/spec/ruby-lint/virtual_machine/unused_spec.rb +0 -17
  187. data/spec/spec_helper.rb +0 -28
  188. data/spec/support/building.rb +0 -50
  189. data/spec/support/coveralls.rb +0 -5
  190. data/spec/support/definitions.rb +0 -39
  191. data/spec/support/fixtures.rb +0 -20
  192. data/spec/support/parsing.rb +0 -30
  193. data/spec/support/simplecov.rb +0 -18
  194. data/spec/support/versions.rb +0 -9
  195. data/task/build.rake +0 -4
  196. data/task/checksum.rake +0 -13
  197. data/task/coverage.rake +0 -6
  198. data/task/doc.rake +0 -16
  199. data/task/generate.rake +0 -77
  200. data/task/graphviz.rake +0 -12
  201. data/task/manifest.rake +0 -8
  202. data/task/tag.rake +0 -6
  203. data/task/test.rake +0 -4
  204. data/task/todo.rake +0 -6
  205. data/task/travis.rake +0 -8
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- require_relative 'lib/ruby-lint/definition_generator'
2
- require_relative 'lib/ruby-lint/rake_task'
3
-
4
- require 'yaml'
5
- require 'bundler/gem_tasks'
6
- require 'digest/sha2'
7
- require 'coveralls/rake/task'
8
- require 'rake/clean'
9
-
10
- RubyLint::RakeTask.new do |task|
11
- task.name = 'lint'
12
- task.files = ['./lib/ruby-lint']
13
- end
14
-
15
- Coveralls::RakeTask.new
16
-
17
- GEMSPEC = Gem::Specification.load('ruby-lint.gemspec')
18
-
19
- CLEAN.include(['coverage', 'yardoc'])
20
-
21
- Dir['./task/*.rake'].each do |task|
22
- import(task)
23
- end
24
-
25
- task :default => :test
@@ -1,13 +0,0 @@
1
- # This benchmark script measures the amount of time it takes to boot up the CLI
2
- # and analyze the VM with caching disabled.
3
-
4
- require_relative '../lib/ruby-lint/benchmark/average'
5
-
6
- script = File.expand_path('../../bin/ruby-lint', __FILE__)
7
- command = "#{script} analyze --disable-cache lib/ruby-lint/virtual_machine.rb"
8
-
9
- RubyLint::Benchmark::Average.measure do
10
- output = `#{command}`
11
-
12
- raise "Command failed: #{output}" unless $?.success?
13
- end
@@ -1,17 +0,0 @@
1
- # This benchmarks N runs of the VM and outputs them to the console making it
2
- # easy to pass the data to tools such as `ministat`
3
- # (http://www.freebsd.org/cgi/man.cgi?ministat).
4
-
5
- require_relative '../lib/ruby-lint'
6
- require 'benchmark'
7
-
8
- parser = RubyLint::Parser.new
9
- file = File.expand_path('../../lib/ruby-lint/virtual_machine.rb', __FILE__)
10
- ast = parser.parse(File.read(file), file)
11
- amount = 1000
12
-
13
- amount.times do
14
- timing = Benchmark.measure { RubyLint::VirtualMachine.new.run(ast) }
15
-
16
- puts timing.real
17
- end
File without changes
File without changes
File without changes
File without changes
@@ -1,12 +0,0 @@
1
- AbstractController
2
- ActionController
3
- ActionDispatch
4
- ActionMailer
5
- ActionPack
6
- ActionView
7
- ActiveModel
8
- ActiveRecord
9
- ActiveSupport
10
- Arel
11
- Rails
12
- Sprockets
@@ -1,2 +0,0 @@
1
- require 'mail'
2
- require 'rails/all'
@@ -1,30 +0,0 @@
1
- # Loads all stdlib files and writes a list of constants to a text file. This is
2
- # run outside of Rake to ensure a clean environment not polluted by Rake and
3
- # other loaded dependencies.
4
-
5
- require_relative 'requires'
6
-
7
- # These are maintained manually.
8
- ignore = DATA.read.split("\n")
9
- consts = Object.constants.map(&:to_s) - ignore
10
-
11
- File.open(File.expand_path('../constants.txt', __FILE__), 'w') do |handle|
12
- handle.write(consts.sort.join("\n"))
13
- end
14
-
15
- __END__
16
- ARGV
17
- BasicObject
18
- Class
19
- ENV
20
- Kernel
21
- Module
22
- RSS
23
- Rubinius
24
- RubyLex
25
- RubySL
26
- RubyToken
27
- Rubysl
28
- STDERR
29
- STDIN
30
- STDOUT
@@ -1,214 +0,0 @@
1
- ARGF
2
- Abbrev
3
- Addrinfo
4
- ArgumentError
5
- Array
6
- Base64
7
- BasicSocket
8
- Benchmark
9
- Bignum
10
- Binding
11
- CGI
12
- CLEANINGS
13
- CMath
14
- COMMON_HEADERS
15
- COMMON_LIBS
16
- COMPILE_C
17
- COMPILE_CXX
18
- COMPILE_RULES
19
- CONFIG
20
- CONFTEST
21
- CONFTEST_C
22
- COUTFLAG
23
- CPPOUTFILE
24
- CROSS_COMPILING
25
- CSV
26
- CXX_EXT
27
- C_EXT
28
- Comparable
29
- Complex
30
- ConditionVariable
31
- Config
32
- DATA
33
- DRb
34
- DRbIdConv
35
- DRbObject
36
- DRbUndumped
37
- Data
38
- Date
39
- DateTime
40
- Delegator
41
- Digest
42
- Dir
43
- EOFError
44
- ERB
45
- EXPORT_PREFIX
46
- Encoding
47
- EncodingError
48
- Enumerable
49
- Enumerator
50
- Errno
51
- Etc
52
- Exception
53
- Exception2MessageMapper
54
- ExceptionForMatrix
55
- FALSE
56
- FailedMessage
57
- FalseClass
58
- Fcntl
59
- Fiber
60
- FiberError
61
- File
62
- FileTest
63
- FileUtils
64
- Find
65
- Fixnum
66
- Float
67
- FloatDomainError
68
- Forwardable
69
- GC
70
- GServer
71
- Gem
72
- GetoptLong
73
- HDR_EXT
74
- Hash
75
- INSTALL_DIRS
76
- IO
77
- IOError
78
- IPAddr
79
- IPSocket
80
- IRB
81
- IndexError
82
- Integer
83
- Interrupt
84
- JSON
85
- Kconv
86
- KeyError
87
- LIBARG
88
- LIBPATHFLAG
89
- LINK_SO
90
- LoadError
91
- LocalJumpError
92
- Logger
93
- Logging
94
- MAIN_DOES_NOTHING
95
- MakeMakefile
96
- Marshal
97
- MatchData
98
- Math
99
- Matrix
100
- Method
101
- Monitor
102
- MonitorMixin
103
- Mutex
104
- Mutex_m
105
- NIL
106
- NKF
107
- NameError
108
- NilClass
109
- NoMemoryError
110
- NoMethodError
111
- NotImplementedError
112
- Numeric
113
- ORIG_LIBPATH
114
- OUTFLAG
115
- Object
116
- ObjectSpace
117
- Observable
118
- Open3
119
- OpenSSL
120
- OpenStruct
121
- OpenURI
122
- OptionParser
123
- PP
124
- PStore
125
- Pathname
126
- PrettyPrint
127
- Prime
128
- Proc
129
- Process
130
- Profiler__
131
- Psych
132
- Queue
133
- RPATHFLAG
134
- RUBYGEMS_ACTIVATION_MONITOR
135
- RUBY_COPYRIGHT
136
- RUBY_DESCRIPTION
137
- RUBY_ENGINE
138
- RUBY_PATCHLEVEL
139
- RUBY_PLATFORM
140
- RUBY_RELEASE_DATE
141
- RUBY_REVISION
142
- RUBY_VERSION
143
- RULE_SUBST
144
- Random
145
- Range
146
- RangeError
147
- Rational
148
- RbConfig
149
- Readline
150
- Regexp
151
- RegexpError
152
- Resolv
153
- RubyVM
154
- RuntimeError
155
- SRC_EXT
156
- STRING_OR_FAILED_FORMAT
157
- ScanError
158
- Scanf
159
- ScriptError
160
- SecureRandom
161
- SecurityError
162
- Set
163
- Shellwords
164
- Signal
165
- SignalException
166
- SimpleDelegator
167
- SingleForwardable
168
- Singleton
169
- SizedQueue
170
- Socket
171
- SocketError
172
- SortedSet
173
- StandardError
174
- StopIteration
175
- String
176
- StringIO
177
- StringScanner
178
- Struct
179
- Symbol
180
- SyntaxError
181
- SystemCallError
182
- SystemExit
183
- SystemStackError
184
- TCPServer
185
- TCPSocket
186
- TOPLEVEL_BINDING
187
- TRUE
188
- TRY_LINK
189
- TSort
190
- Tempfile
191
- ThWait
192
- Thread
193
- ThreadError
194
- ThreadGroup
195
- ThreadsWait
196
- Time
197
- Timeout
198
- TimeoutError
199
- TracePoint
200
- TrueClass
201
- TypeError
202
- UDPSocket
203
- UNIVERSAL_INTS
204
- UNIXServer
205
- UNIXSocket
206
- URI
207
- UnboundMethod
208
- Vector
209
- WEBrick
210
- WeakRef
211
- XMLRPC
212
- YAML
213
- ZeroDivisionError
214
- Zlib
@@ -1,64 +0,0 @@
1
- require 'abbrev'
2
- require 'base64'
3
- require 'benchmark'
4
- require 'cgi'
5
- require 'cmath'
6
- require 'complex'
7
- require 'csv'
8
- require 'date'
9
- require 'delegate'
10
- require 'digest'
11
- require 'drb'
12
- require 'e2mmap'
13
- require 'English'
14
- require 'erb'
15
- require 'expect'
16
- require 'fileutils'
17
- require 'find'
18
- require 'forwardable'
19
- require 'getoptlong'
20
- require 'gserver'
21
- require 'ipaddr'
22
- require 'irb'
23
- require 'json'
24
- require 'kconv'
25
- require 'logger'
26
- require 'mathn'
27
- require 'matrix'
28
- require 'mkmf'
29
- require 'monitor'
30
- require 'mutex_m'
31
- require 'observer'
32
- require 'open3'
33
- require 'openssl'
34
- require 'open-uri'
35
- require 'optparse'
36
- require 'ostruct'
37
- require 'pathname'
38
- require 'pp'
39
- require 'prettyprint'
40
- require 'prime'
41
- require 'profiler'
42
- require 'pstore'
43
- require 'rational'
44
- require 'resolv'
45
- require 'scanf'
46
- require 'securerandom'
47
- require 'set'
48
- require 'shellwords'
49
- require 'singleton'
50
- require 'socket'
51
- require 'stringio'
52
- require 'tempfile'
53
- require 'thread'
54
- require 'thwait'
55
- require 'timeout'
56
- require 'time'
57
- require 'tmpdir'
58
- require 'tsort'
59
- require 'uri'
60
- require 'weakref'
61
- require 'webrick'
62
- require 'xmlrpc'
63
- require 'yaml'
64
- require 'zlib'
@@ -1,115 +0,0 @@
1
- require 'benchmark'
2
-
3
- module RubyLint
4
- module Benchmark
5
- ##
6
- # Benchmark class for measuring min/max/avg timings of a block of Ruby
7
- # code.
8
- #
9
- # @!attribute [r] iterations
10
- # @return [Numeric]
11
- #
12
- # @!attribute [r] precision
13
- # @return [Numeric]
14
- #
15
- class Average
16
- attr_reader :iterations, :precision
17
-
18
- ##
19
- # @return [Array]
20
- #
21
- AVERAGE_COLUMNS = %w(Iterations Minimum Maximum Average)
22
-
23
- ##
24
- # @return [String]
25
- #
26
- SEPARATOR = ' | '
27
-
28
- ##
29
- # Shorthand method for easily measuring a block.
30
- #
31
- # @see #measure
32
- #
33
- def self.measure(*args, &block)
34
- new(*args).measure(&block)
35
- end
36
-
37
- ##
38
- # @param [Numeric] iterations The amount of times to call the block.
39
- # @param [Numeric] precision The amount of decimals to display.
40
- #
41
- def initialize(iterations = 100, precision = 6)
42
- @iterations = iterations
43
- @precision = precision
44
- end
45
-
46
- ##
47
- # Runs the given block N times and displays the minimum, maximum and average
48
- # execution times in secnds.
49
- #
50
- def measure
51
- timings = []
52
-
53
- iterations.times do
54
- timings << ::Benchmark.measure { yield }.real
55
- end
56
-
57
- avg = timings.inject(:+) / iterations
58
-
59
- show(timings.min, timings.max, avg)
60
- end
61
-
62
- ##
63
- # @param [Numeric] min
64
- # @param [Numeric] max
65
- # @param [Numeric] avg
66
- #
67
- def show(min, max, avg)
68
- values = [iterations.to_s] + format_values([min, max, avg])
69
- padding = padding_length(AVERAGE_COLUMNS + values)
70
-
71
- show_header(padding)
72
-
73
- puts values.map { |val| val.ljust(padding) }.join(SEPARATOR)
74
- end
75
-
76
- private
77
-
78
- ##
79
- # Display the header.
80
- #
81
- # @param [Numeric] padding
82
- #
83
- def show_header(padding)
84
- header = format_header(padding)
85
-
86
- puts header
87
- puts header.gsub('|', '+').gsub(/[^+]/, '-')
88
- end
89
-
90
- ##
91
- # @param [Array] values
92
- # @return [Array<String>]
93
- #
94
- def format_values(values)
95
- return values.map { |val| "#{val.round(precision)} sec" }
96
- end
97
-
98
- ##
99
- # @param [Numeric] padding
100
- # @return [String]
101
- #
102
- def format_header(padding)
103
- return AVERAGE_COLUMNS.map { |val| val.ljust(padding) }.join(SEPARATOR)
104
- end
105
-
106
- ##
107
- # @param [Array] values
108
- # @return [Numeric]
109
- #
110
- def padding_length(values)
111
- return values.sort_by { |value| value.length }.last.length
112
- end
113
- end # Average
114
- end # Benchmark
115
- end # RubyLint