ruby-lint 1.1.0 → 2.0.0

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.
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
@@ -1,121 +0,0 @@
1
- module RubyLint
2
- ##
3
- # The Cache class is used for storing arbitrary Ruby objects in a cache
4
- # directory. The primary use case of this class is to store cached ASTs and
5
- # their comment associations (as is done by {RubyLint::Runner}).
6
- #
7
- # @!attribute [r] directory
8
- # @return [String]
9
- #
10
- class Cache
11
- attr_reader :directory
12
-
13
- ##
14
- # The version of the cache format.
15
- #
16
- # @return [String]
17
- #
18
- FORMAT_VERSION = '1'
19
-
20
- ##
21
- # @param [String] directory Path to the cache directory.
22
- #
23
- def initialize(directory)
24
- @directory = directory
25
- end
26
-
27
- ##
28
- # Creates the directory specified in {#directory} unless it already exists.
29
- #
30
- def create_directory!
31
- Dir.mkdir(directory) unless File.directory?(directory)
32
- end
33
-
34
- ##
35
- # Checks if there's a cache entry for the given name.
36
- #
37
- # @return [TrueClass|FalseClass]
38
- #
39
- def exists?(name)
40
- return File.file?(entry_filepath(name))
41
- end
42
-
43
- ##
44
- # Returns the cache entry for the given name or `nil` if the entry doesn't
45
- # exist.
46
- #
47
- # @param [String] name
48
- # @return [Mixed]
49
- #
50
- def get(name)
51
- return unless exists?(name)
52
-
53
- data = File.read(entry_filepath(name))
54
-
55
- return decode(data)
56
- end
57
-
58
- ##
59
- # Sets the cache entry to the given value. Existing cache entries are
60
- # overwritten.
61
- #
62
- # @param [String] name
63
- # @param [Mixed] value
64
- #
65
- def set(name, value)
66
- File.open(entry_filepath(name), 'w') do |handle|
67
- handle.write(encode(value))
68
- end
69
- end
70
-
71
- ##
72
- # Removes a cache entry.
73
- #
74
- # @param [String] name
75
- #
76
- def delete(name)
77
- File.unlink(entry_filepath(name)) if exists?(name)
78
- end
79
-
80
- private
81
-
82
- ##
83
- # Returns the filename for the given entry name.
84
- #
85
- # @param [String] name
86
- # @return [String]
87
- #
88
- def entry_filename(name)
89
- return "#{name}.#{FORMAT_VERSION}.cache"
90
- end
91
-
92
- ##
93
- # Returns the full filename of the cache entry's name.
94
- #
95
- # @param [String] name
96
- # @return [String]
97
- #
98
- def entry_filepath(name)
99
- return File.join(directory, entry_filename(name))
100
- end
101
-
102
- ##
103
- # Decodes a cache entry.
104
- #
105
- # @param [String] input
106
- # @return [Mixed]
107
- #
108
- def decode(input)
109
- return Marshal.load(Zlib::Inflate.inflate(input))
110
- end
111
-
112
- ##
113
- # Encodes a cache entry.
114
- #
115
- # @param [String] input
116
- #
117
- def encode(input)
118
- return Zlib::Deflate.deflate(Marshal.dump(input))
119
- end
120
- end # Cache
121
- end # RubyLint
@@ -1,44 +0,0 @@
1
- module RubyLint
2
- ##
3
- # The CacheEntry class is used to store nodes, comments and file modification
4
- # times that belong to a certain root AST. It's primarily used by
5
- # {RubyLint::Runner}.
6
- #
7
- # @!attribute [r] nodes
8
- # @return [Array]
9
- #
10
- # @!attribute [r] comments
11
- # @return [Hash]
12
- #
13
- # @!attribute [r] mtimes
14
- # @return [Hash]
15
- #
16
- class CacheEntry
17
- attr_reader :nodes, :comments, :mtimes
18
-
19
- ##
20
- # @param [Array] nodes
21
- # @param [Hash] comments
22
- # @param [Hash] mtimes
23
- #
24
- def initialize(nodes, comments, mtimes)
25
- @nodes = nodes
26
- @comments = comments
27
- @mtimes = mtimes
28
- end
29
-
30
- ##
31
- # Returns `true` if none of the associated files have been modified,
32
- # `false` otherwise.
33
- #
34
- # @return [TrueClass|FalseClass]
35
- #
36
- def valid?
37
- mtimes.each do |file, mtime|
38
- return false if File.mtime(file) != mtime
39
- end
40
-
41
- return true
42
- end
43
- end # CacheEntry
44
- end # RubyLint
@@ -1,4 +0,0 @@
1
- require 'slop'
2
- require_relative 'cli/base'
3
- require_relative 'cli/analyze'
4
- require_relative 'cli/cache'
@@ -1,209 +0,0 @@
1
- RubyLint::CLI.options.command :analyze do
2
- banner 'Usage: ruby-lint analyze [FILES] [OPTIONS]'
3
- description 'Analyze the source code of Ruby files'
4
-
5
- separator <<-EOF.chomp
6
-
7
- About:
8
-
9
- This command analyses the source code of a Ruby file and presents a report
10
- containing information such as errors about invalid code, warnings and
11
- informational messages.
12
-
13
- Configuration:
14
-
15
- When this command is executed it will try to load a configuration file in
16
- one of the following two locations (in this order):
17
-
18
- * $PWD/ruby-lint.yml
19
- * ~/.ruby-lint.yml
20
-
21
- Only the first existing configuration file is loaded.
22
-
23
- These configuration files can be used for specifying the presenter, reporting
24
- levels and various other options.
25
-
26
- You can also configure various parts using the supplied commandline options.
27
- For example, to use the JSON presenter you'd run the following:
28
-
29
- $ ruby-lint analyze ./test_file.rb --presenter=json
30
-
31
- Analysis Classes:
32
-
33
- #{RubyLint::CLI.format_names('analysis')}
34
-
35
- Presenters:
36
-
37
- #{RubyLint::CLI.format_names('presenters')}
38
-
39
- Reporting Levels:
40
-
41
- #{RubyLint::CLI.format_names('levels')}
42
-
43
- Examples:
44
-
45
- To analyze a single file you can run the following command:
46
-
47
- $ ruby-lint analyze ./test_file.rb
48
-
49
- You can also specify multiple files:
50
-
51
- $ ruby-lint analyze first_file.rb second_file.rb
52
-
53
- Run analysis on an entire directory:
54
-
55
- $ ruby-lint analyze lib/
56
- EOF
57
-
58
- separator RubyLint::CLI::OPTIONS_HEADER
59
-
60
- RubyLint::CLI.help_option(self)
61
-
62
- on :l=, :levels=, 'The reporting levels to enable', :as => Array
63
- on :p=, :presenter=, 'The presenter to use', :as => String
64
- on :a=, :analysis=, 'The analysis classes to use', :as => Array
65
- on :b, :benchmark, 'Enables benchmarking mode'
66
- on :d, :debug, 'Displays debugging output in STDERR'
67
-
68
- on :'disable-cache', 'Disables caching of external files'
69
-
70
- ##
71
- # Returns an Array containing the file paths that exist. If a non existing
72
- # file is encountered `abort` is called.
73
- #
74
- # @param [Array] files
75
- # @return [Array]
76
- #
77
- def extract_files(files)
78
- return RubyLint::FileList.new.process(files)
79
-
80
- rescue Errno::ENOENT => error
81
- abort error.message
82
- end
83
-
84
- ##
85
- # @return [Hash]
86
- #
87
- def option_mapping
88
- return {
89
- :levels => :report_levels=,
90
- :presenter => :presenter=,
91
- :analysis => :analysis_classes=,
92
- :debug => :debug=
93
- }
94
- end
95
-
96
- ##
97
- # @return [IO]
98
- #
99
- def output_destination
100
- return @output_destination ||= STDOUT
101
- end
102
-
103
- ##
104
- # @param [IO] destination
105
- #
106
- def output_destination=(destination)
107
- @output_destination = destination
108
- end
109
-
110
- # The stdout and stderr methods mainly exist to make testing a bit easier.
111
-
112
- ##
113
- # @return [IO]
114
- #
115
- def stdout
116
- return STDOUT
117
- end
118
-
119
- ##
120
- # @return [IO]
121
- #
122
- def stderr
123
- return STDERR
124
- end
125
-
126
- ##
127
- # @param [RubyLint::Configuration] configuration
128
- # @param [Hash] opts
129
- #
130
- def configure(configuration, options)
131
- option_mapping.each do |key, setter|
132
- configuration.send(setter, options[key]) if options[key]
133
- end
134
-
135
- if options[:'disable-cache']
136
- configuration.enable_cache = false
137
- end
138
- end
139
-
140
- ##
141
- # @param [String] output
142
- # @param [Float] exec_time
143
- #
144
- def show_benchmark_info(output, exec_time)
145
- memory_kb = `ps -o rss= #{Process.pid}`.strip.to_f
146
- memory_mb = memory_kb / 1024
147
-
148
- output_destination.puts unless output.empty?
149
-
150
- output_destination.puts "Execution time: #{exec_time.round(4)} seconds"
151
-
152
- output_destination.puts "Memory usage: #{memory_mb.round(2)} MB " \
153
- "(#{memory_kb.round(2)} KB)"
154
- end
155
-
156
- ##
157
- # Shows a lump of debugging information before the rest of the output.
158
- #
159
- # @param [RubyLint::Configuration] config
160
- #
161
- #:nocov:
162
- def debug_header(config)
163
- directories = config.directories.map do |dir|
164
- File.directory?(dir) ? "#{dir}: exists" : "#{dir}: doesn't exist"
165
- end
166
-
167
- directories = directories.empty? ? 'None' : directories.join("\n")
168
-
169
- stderr.puts <<-EOF.strip
170
- ruby: #{RUBY_DESCRIPTION}
171
- ruby-lint: #{RubyLint::VERSION}
172
- directory: #{Dir.pwd}
173
-
174
- Caching:
175
-
176
- enabled: #{config.enable_cache}
177
- directory: #{config.cache_directory}
178
-
179
- Directories:
180
-
181
- #{directories}
182
-
183
- ------
184
- EOF
185
-
186
- stderr.puts
187
- end
188
- #:nocov:
189
-
190
- run do |opts, args|
191
- abort 'You must specify at least one file to analyze' if args.empty?
192
-
193
- start_time = Time.now.to_f
194
- files = extract_files(args)
195
- configuration = RubyLint::Configuration.load_from_file
196
-
197
- configure(configuration, opts)
198
-
199
- debug_header(configuration) if configuration.debug
200
-
201
- runner = RubyLint::Runner.new(configuration)
202
- output = runner.analyze(files)
203
- exec_time = Time.now.to_f - start_time
204
-
205
- output_destination.puts output unless output.empty?
206
-
207
- show_benchmark_info(output, exec_time) if opts[:benchmark]
208
- end # run do |opts, args|
209
- end # RubyLint::CLI.options.command
@@ -1,103 +0,0 @@
1
- module RubyLint
2
- module CLI
3
- ##
4
- # Hash containing configuration options for Slop.
5
- #
6
- # @return [Hash]
7
- #
8
- SLOP_OPTIONS = {
9
- :strict => true,
10
- :banner => 'Usage: ruby-lint [COMMAND] [OPTIONS]'
11
- }
12
-
13
- ##
14
- # The header to use for separating options with other bits of information
15
- # in help messages.
16
- #
17
- # @return [String]
18
- #
19
- OPTIONS_HEADER = "\nOptions:\n"
20
-
21
- #:nocov:
22
-
23
- ##
24
- # Returns a String containing a list of names as registered in
25
- # {RubyLint::Configuration.names}.
26
- #
27
- # @param [String] scope
28
- # @see RubyLint::Configuration.names
29
- # @return [String]
30
- #
31
- def self.format_names(scope)
32
- return "* #{Configuration.names[scope].keys.sort.join("\n * ")}"
33
- end
34
-
35
- ##
36
- # Starts the CLI.
37
- #
38
- # @param [Array] argv
39
- #
40
- def self.run(argv = ARGV)
41
- options.parse(argv)
42
- end
43
-
44
- ##
45
- # @return [Slop]
46
- #
47
- def self.options
48
- return @options ||= default_options
49
- end
50
-
51
- ##
52
- # @return [Slop]
53
- #
54
- def self.default_options
55
- return Slop.new(SLOP_OPTIONS) do
56
- separator OPTIONS_HEADER
57
-
58
- CLI.help_option(self)
59
-
60
- on :v, :version, 'Shows the current version' do
61
- puts CLI.version_information
62
- exit
63
- end
64
-
65
- run do |opts, args|
66
- if args.empty?
67
- puts self
68
- exit
69
- else
70
- CLI.options.commands['analyze'].parse(args)
71
- end
72
- end
73
- end
74
- end
75
-
76
- ##
77
- # Adds a `-h/--help` option for a command. This method should be executed
78
- # in the context of a Slop command.
79
- #
80
- # @param [Mixed] command
81
- #
82
- def self.help_option(command)
83
- command.instance_eval do
84
- on :h, :help, 'Shows this help message' do
85
- puts self
86
- exit
87
- end
88
- end
89
- end
90
-
91
- ##
92
- # Returns a String containing information about the current ruby-lint
93
- # version and platform.
94
- #
95
- # @return [String]
96
- #
97
- def self.version_information
98
- return "ruby-lint v#{VERSION} on #{RUBY_DESCRIPTION}"
99
- end
100
-
101
- #:nocov:
102
- end # CLI
103
- end # RubyLint