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,138 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::UndefinedVariables do
4
- example 'add an error for using an undefined instance variable' do
5
- report = build_report('@number', RubyLint::Analysis::UndefinedVariables)
6
- entry = report.entries[0]
7
-
8
- entry.is_a?(RubyLint::Report::Entry).should == true
9
-
10
- entry.line.should == 1
11
- entry.column.should == 1
12
- entry.message.should == 'undefined instance variable @number'
13
- end
14
-
15
- example 'add an error for using an undefined class variable' do
16
- report = build_report('@@number', RubyLint::Analysis::UndefinedVariables)
17
- entry = report.entries[0]
18
-
19
- entry.is_a?(RubyLint::Report::Entry).should == true
20
-
21
- entry.line.should == 1
22
- entry.column.should == 1
23
- entry.message.should == 'undefined class variable @@number'
24
- end
25
-
26
- example 'add an error for using an undefined global variable' do
27
- report = build_report('$number', RubyLint::Analysis::UndefinedVariables)
28
- entry = report.entries[0]
29
-
30
- entry.is_a?(RubyLint::Report::Entry).should == true
31
-
32
- entry.line.should == 1
33
- entry.column.should == 1
34
- entry.message.should == 'undefined global variable $number'
35
- end
36
-
37
- example 'add an error for using an undefined constant' do
38
- report = build_report('NUMBER', RubyLint::Analysis::UndefinedVariables)
39
- entry = report.entries[0]
40
-
41
- entry.is_a?(RubyLint::Report::Entry).should == true
42
-
43
- entry.line.should == 1
44
- entry.column.should == 1
45
- entry.message.should == 'undefined constant NUMBER'
46
- end
47
-
48
- example 'add an error for using an undefined constant path' do
49
- code = <<-CODE
50
- # This is to ensure that the on_const() callback isn't used to check for "B"
51
- # in the global scope.
52
- B = 10
53
-
54
- module A
55
- end
56
-
57
- A::B
58
- CODE
59
-
60
- report = build_report(code, RubyLint::Analysis::UndefinedVariables)
61
- entry = report.entries[0]
62
-
63
- entry.is_a?(RubyLint::Report::Entry).should == true
64
-
65
- entry.line.should == 8
66
- entry.column.should == 1
67
- entry.message.should == 'undefined constant A::B'
68
- end
69
-
70
- example 'do not depend on the order of variable definitions' do
71
- code = <<-CODE
72
- class Person
73
- def first
74
- @number = 10
75
- end
76
-
77
- def second
78
- return @number
79
- end
80
- end
81
- CODE
82
-
83
- report = build_report(code, RubyLint::Analysis::UndefinedVariables)
84
-
85
- report.entries.empty?.should == true
86
- end
87
-
88
- example 'do not add errors when autoloading constants' do
89
- code = 'Encoding::BIG5'
90
- report = build_report(code, RubyLint::Analysis::UndefinedVariables)
91
-
92
- report.entries.empty?.should == true
93
- end
94
-
95
- example 'do not error when inheriting data in a block' do
96
- code = <<-CODE
97
- NUMBER = 10
98
-
99
- example_method do
100
- NUMBER
101
- end
102
- CODE
103
-
104
- report = build_report(code, RubyLint::Analysis::UndefinedVariables)
105
-
106
- report.entries.empty?.should == true
107
- end
108
-
109
- example 'do not add errors for variable references in string interpolation' do
110
- code = 'number = 10; "#{number}"'
111
- report = build_report(code, RubyLint::Analysis::UndefinedVariables)
112
-
113
- report.entries.empty?.should == true
114
- end
115
-
116
- example 'do not add errors for class names' do
117
- code = <<-CODE
118
- class Foo
119
- end
120
-
121
- module Namespace
122
- class Bar
123
- end
124
- end
125
- CODE
126
-
127
- report = build_report(code, RubyLint::Analysis::UndefinedVariables)
128
-
129
- report.entries.empty?.should == true
130
- end
131
-
132
- example 'do not add errors when aliasing global variables' do
133
- code = 'alias $ARGV $*'
134
- report = build_report(code, RubyLint::Analysis::UndefinedVariables)
135
-
136
- report.entries.empty?.should == true
137
- end
138
- end
@@ -1,270 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::UnusedVariables do
4
- example 'warn for unused local variables' do
5
- report = build_report('number = 1', RubyLint::Analysis::UnusedVariables)
6
- entry = report.entries[0]
7
-
8
- entry.is_a?(RubyLint::Report::Entry).should == true
9
-
10
- entry.line.should == 1
11
- entry.column.should == 1
12
- entry.message.should == 'unused local variable number'
13
- end
14
-
15
- example 'warn for unused instance variables' do
16
- report = build_report('@number = 1', RubyLint::Analysis::UnusedVariables)
17
- entry = report.entries[0]
18
-
19
- entry.line.should == 1
20
- entry.column.should == 1
21
- entry.message.should == 'unused instance variable @number'
22
- end
23
-
24
- example 'do not warn for used variables' do
25
- code = <<-CODE
26
- number = 1
27
-
28
- number
29
- CODE
30
-
31
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
32
-
33
- report.entries.empty?.should == true
34
- end
35
-
36
- example 'warn for unused constants' do
37
- report = build_report('NUMBER = 10', RubyLint::Analysis::UnusedVariables)
38
- entry = report.entries[0]
39
-
40
- entry.is_a?(RubyLint::Report::Entry).should == true
41
-
42
- entry.line.should == 1
43
- entry.column.should == 1
44
- entry.message.should == 'unused constant NUMBER'
45
- end
46
-
47
- example 'do not warn for used constants' do
48
- code = <<-CODE
49
- A = 10
50
-
51
- A
52
- CODE
53
-
54
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
55
-
56
- report.entries.empty?.should == true
57
- end
58
-
59
- example 'warn for unused constant paths' do
60
- code = <<-CODE
61
- module A
62
- end
63
-
64
- A::B = 10
65
- CODE
66
-
67
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
68
-
69
- report.entries.length.should == 1
70
-
71
- entry = report.entries[0]
72
-
73
- entry.is_a?(RubyLint::Report::Entry).should == true
74
-
75
- entry.line.should == 4
76
- entry.column.should == 1
77
- entry.message.should == 'unused constant A::B'
78
- end
79
-
80
- example 'warn for unused variables in a method scope' do
81
- code = <<-CODE
82
- def some_method
83
- number = 10
84
- end
85
- CODE
86
-
87
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
88
- entry = report.entries[0]
89
-
90
- entry.is_a?(RubyLint::Report::Entry).should == true
91
-
92
- entry.line.should == 2
93
- entry.column.should == 3
94
- entry.message.should == 'unused local variable number'
95
- end
96
-
97
- example 'do not add a warning when assigning a variable to another variable' do
98
- code = <<-CODE
99
- first = 10
100
- second = first
101
- CODE
102
-
103
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
104
-
105
- report.entries.length.should == 1
106
-
107
- entry = report.entries[0]
108
-
109
- entry.line.should == 2
110
- entry.column.should == 1
111
- entry.message.should == 'unused local variable second'
112
- end
113
-
114
- example 'do not add warnings when defining classes and modules' do
115
- code = <<-CODE
116
- module A
117
- end
118
-
119
- class B
120
- end
121
- CODE
122
-
123
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
124
-
125
- report.entries.empty?.should == true
126
- end
127
-
128
- example 'ignore ivars if there is a corresponding method' do
129
- code = <<-CODE
130
- @number = 10
131
-
132
- def number; end
133
- CODE
134
-
135
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
136
-
137
- report.entries.empty?.should == true
138
- end
139
-
140
- example 'ignore local variables that start with an underscore' do
141
- report = build_report('_number = 10', RubyLint::Analysis::UnusedVariables)
142
-
143
- report.entries.empty?.should == true
144
- end
145
-
146
- context 'method arguments' do
147
- example 'warn for a unused argument' do
148
- code = <<-CODE
149
- def multiply(number)
150
- end
151
- CODE
152
-
153
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
154
- entry = report.entries[0]
155
-
156
- entry.message.should == 'unused argument number'
157
- entry.line.should == 1
158
- entry.column.should == 14
159
- end
160
-
161
- example 'warn for a unused optional argument' do
162
- code = <<-CODE
163
- def multiply(amount = 2)
164
- end
165
- CODE
166
-
167
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
168
- entry = report.entries[0]
169
-
170
- entry.message.should == 'unused argument amount'
171
- entry.line.should == 1
172
- entry.column.should == 14
173
- end
174
-
175
- example 'warn for a unused rest argument' do
176
- code = <<-CODE
177
- def multiply(*args)
178
- end
179
- CODE
180
-
181
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
182
- entry = report.entries[0]
183
-
184
- entry.message.should == 'unused argument args'
185
- entry.line.should == 1
186
- entry.column.should == 14
187
- end
188
-
189
- example 'warn for a unused block argument' do
190
- code = <<-CODE
191
- def multiply(&block)
192
- end
193
- CODE
194
-
195
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
196
- entry = report.entries[0]
197
-
198
- entry.message.should == 'unused argument block'
199
- entry.line.should == 1
200
- entry.column.should == 14
201
- end
202
-
203
- specific_ruby_version '2.0' do
204
- example 'warn for a unused keyword argument' do
205
- code = <<-CODE
206
- def multiply(amount: 10)
207
- end
208
- CODE
209
-
210
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
211
- entry = report.entries[0]
212
-
213
- entry.message.should == 'unused argument amount'
214
- entry.line.should == 1
215
- entry.column.should == 14
216
- end
217
- end
218
-
219
- example 'do not warn for a used argument' do
220
- code = <<-CODE
221
- def multiply(number)
222
- return number * 2
223
- end
224
- CODE
225
-
226
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
227
-
228
- report.entries.empty?.should == true
229
- end
230
-
231
- example 'do not warn for unused anonymous splat arguments' do
232
- code = <<-CODE
233
- def example(*)
234
- end
235
- CODE
236
-
237
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
238
-
239
- report.entries.empty?.should == true
240
- end
241
- end
242
-
243
- context 'block arguments' do
244
- example 'warn for a unused argument' do
245
- code = <<-CODE
246
- [10, 20].each do |number|
247
- end
248
- CODE
249
-
250
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
251
- entry = report.entries[0]
252
-
253
- entry.message.should == 'unused argument number'
254
- entry.line.should == 1
255
- entry.column.should == 19
256
- end
257
-
258
- example 'do not warn for a used argument' do
259
- code = <<-CODE
260
- [10, 20].each do |number|
261
- number
262
- end
263
- CODE
264
-
265
- report = build_report(code, RubyLint::Analysis::UnusedVariables)
266
-
267
- report.entries.empty?.should == true
268
- end
269
- end
270
- end
@@ -1,107 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::UselessEqualityChecks do
4
- example 'compare a String literal with a Fixnum literal' do
5
- code = "'foo' == 10"
6
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
7
- entry = report.entries[0]
8
-
9
- entry.line.should == 1
10
- entry.column.should == 1
11
- entry.message.should == 'Comparing String with Fixnum evaluates to false'
12
- end
13
-
14
- example 'compare a variable with a Fixnum literal' do
15
- code = <<-EOF
16
- string = 'foo'
17
-
18
- string == 10
19
- EOF
20
-
21
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
22
- entry = report.entries[0]
23
-
24
- entry.message.should == 'Comparing String with Fixnum evaluates to false'
25
- end
26
-
27
- example 'compare two variables' do
28
- code = <<-EOF
29
- string = 'foo'
30
- number = 10
31
-
32
- string == number
33
- EOF
34
-
35
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
36
- entry = report.entries[0]
37
-
38
- entry.message.should == 'Comparing String with Fixnum evaluates to false'
39
- end
40
-
41
- example 'compare a String literal with a method call' do
42
- code = <<-EOF
43
- # @return [Fixnum]
44
- def number
45
- return 10
46
- end
47
-
48
- 'foo' == number
49
- EOF
50
-
51
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
52
- entry = report.entries[0]
53
-
54
- entry.message.should == 'Comparing String with Fixnum evaluates to false'
55
- end
56
-
57
- example 'ignore values that are unknown' do
58
- code = <<-EOF
59
- def foo
60
- end
61
-
62
- 10 == foo
63
- EOF
64
-
65
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
66
-
67
- report.entries.empty?.should == true
68
- end
69
-
70
- example 'calling methods on objects that return unknown values' do
71
- code = <<-CODE
72
- def example(number)
73
- return '10' == number.to_s
74
- end
75
- CODE
76
-
77
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
78
-
79
- report.entries.empty?.should == true
80
- end
81
-
82
- context 'ignoring variables with unknown values' do
83
- example 'ignore a local variable without a value' do
84
- code = <<-CODE
85
- [10, 20].each do |number|
86
- number == false
87
- end
88
- CODE
89
-
90
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
91
-
92
- report.entries.empty?.should == true
93
- end
94
-
95
- example 'ignore an instance variable without a value' do
96
- code = <<-CODE
97
- [10, 20].each do |@number|
98
- @number == false
99
- end
100
- CODE
101
-
102
- report = build_report(code, RubyLint::Analysis::UselessEqualityChecks)
103
-
104
- report.entries.empty?.should == true
105
- end
106
- end
107
- end