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,8 +0,0 @@
1
- ---
2
- report_levels:
3
- - info
4
-
5
- analysis_classes:
6
- - undefined_methods
7
-
8
- presenter: json
@@ -1 +0,0 @@
1
- foobar
@@ -1,6 +0,0 @@
1
- module Example
2
- module Recursive
3
- class Source < Target
4
- end # Source
5
- end # Recursive
6
- end # Example
@@ -1,8 +0,0 @@
1
- module Example
2
- module Recursive
3
- class Target
4
- def example_method
5
- end
6
- end # Target
7
- end # Recursive
8
- end # Example
@@ -1,6 +0,0 @@
1
- module Example
2
- class User
3
- def example_method
4
- end
5
- end
6
- end
@@ -1,6 +0,0 @@
1
- module Definition
2
- class ConstantProxy
3
- def initialize(definitions, name)
4
- end
5
- end # ConstantProxy
6
- end # Definition
@@ -1,6 +0,0 @@
1
- module RubyLint
2
- module GlobalScope
3
- def self.definitions
4
- end
5
- end # GlobalScope
6
- end # RubyLint
@@ -1,4 +0,0 @@
1
- module TestDashes
2
- module Foo
3
- end # Foo
4
- end # TestDashes
@@ -1,6 +0,0 @@
1
- module Example
2
- class User
3
- def example_method
4
- end
5
- end
6
- end
@@ -1,4 +0,0 @@
1
- class User
2
- def example_method
3
- end
4
- end
@@ -1,3 +0,0 @@
1
- name = 'Ruby'
2
-
3
- name.foobar
@@ -1,3 +0,0 @@
1
- name = 'Ruby'
2
-
3
- name.derp
@@ -1 +0,0 @@
1
- module Foo
@@ -1 +0,0 @@
1
- User.new
@@ -1,3 +0,0 @@
1
- user = User.new
2
-
3
- user.foobar
@@ -1 +0,0 @@
1
- Example::User.new
@@ -1,3 +0,0 @@
1
- name = 'Ruby'
2
-
3
- name.upcase
@@ -1,131 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::ArgumentAmount do
4
- example 'validate the amount of required arguments' do
5
- code = <<-CODE
6
- def example(first, second)
7
- end
8
-
9
- example
10
- CODE
11
-
12
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
13
- entry = report.entries[0]
14
-
15
- entry.is_a?(RubyLint::Report::Entry).should == true
16
-
17
- entry.line.should == 4
18
- entry.column.should == 1
19
- entry.message.should == 'wrong number of arguments (expected 2 but got 0)'
20
- end
21
-
22
- example 'validate argument amounts when using optional arguments' do
23
- code = <<-CODE
24
- def example(first, second, third = nil)
25
- end
26
-
27
- example
28
- CODE
29
-
30
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
31
- entry = report.entries[0]
32
-
33
- entry.is_a?(RubyLint::Report::Entry).should == true
34
-
35
- entry.line.should == 4
36
- entry.column.should == 1
37
- entry.message.should == 'wrong number of arguments ' \
38
- '(expected 2..3 but got 0)'
39
- end
40
-
41
- example 'validate argument amounts when using rest arguments' do
42
- code = <<-CODE
43
- def example(first, second, *args)
44
- end
45
-
46
- example
47
- CODE
48
-
49
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
50
- entry = report.entries[0]
51
-
52
- entry.is_a?(RubyLint::Report::Entry).should == true
53
-
54
- entry.line.should == 4
55
- entry.column.should == 1
56
- entry.message.should == 'wrong number of arguments ' \
57
- '(expected 2 but got 0)'
58
- end
59
-
60
- example 'validate argument amounts when using a required and rest argument' do
61
- code = <<-CODE
62
- def example(required, *numbers)
63
- end
64
-
65
- example(10, 20, 30)
66
- CODE
67
-
68
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
69
-
70
- report.entries.length.should == 0
71
- end
72
-
73
- example 'take variable assignments into account' do
74
- code = <<-CODE
75
- name = 'Ruby'
76
-
77
- name.downcase
78
- CODE
79
-
80
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
81
-
82
- report.entries.empty?.should == true
83
- end
84
-
85
- example 'not validate methods called on undefined receivers' do
86
- code = 'A.example_method'
87
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
88
-
89
- report.entries.empty?.should == true
90
- end
91
-
92
- example 'use #initialize for arguments when processing .new' do
93
- code = <<-CODE
94
- class Person
95
- def initialize(name)
96
- end
97
- end
98
-
99
- Person.new
100
- Person.new(10, 20)
101
- CODE
102
-
103
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
104
-
105
- report.entries.length.should == 2
106
-
107
- first, second = report.entries
108
-
109
- first.line.should == 6
110
- first.column.should == 1
111
- first.message.should == 'wrong number of arguments (expected 1 but got 0)'
112
-
113
- second.line.should == 7
114
- second.column.should == 1
115
- second.message.should == 'wrong number of arguments (expected 1 but got 2)'
116
- end
117
-
118
- example 'ignore block arguments' do
119
- code = <<-CODE
120
- def example; end
121
-
122
- block = proc {}
123
-
124
- example(&block)
125
- CODE
126
-
127
- report = build_report(code, RubyLint::Analysis::ArgumentAmount)
128
-
129
- report.entries.empty?.should == true
130
- end
131
- end
@@ -1,24 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::Base do
4
- example 'require a VM' do
5
- lambda { RubyLint::Analysis::Base.new }.should raise_error(ArgumentError)
6
-
7
- vm = RubyLint::VirtualMachine.new
8
- blk = lambda { RubyLint::Analysis::Base.new(:vm => vm) }
9
-
10
- blk.should_not raise_error
11
- end
12
-
13
- example 'allow config objects to be passed in' do
14
- vm = RubyLint::VirtualMachine.new
15
- config = RubyLint::Configuration.new
16
- base = RubyLint::Analysis::Base.new(:vm => vm, :config => config)
17
-
18
- base.config.should == config
19
- end
20
-
21
- example 'enable analysis by default' do
22
- RubyLint::Analysis::Base.analyze?(double(:ast), double(:vm)).should == true
23
- end
24
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::Pedantics do
4
- example 'warn when using do/then in various statements' do
5
- code = <<-CODE
6
- if true then; end
7
- unless true then; end
8
- while true do; end
9
- CODE
10
-
11
- report = build_report(code, RubyLint::Analysis::Pedantics)
12
- entries = report.entries
13
-
14
- entries.length.should == 3
15
-
16
- entries[0].line.should == 1
17
- entries[0].message.should == 'the use of then/do is not needed here'
18
-
19
- entries[1].line.should == 2
20
- entries[1].message.should == 'the use of then/do is not needed here'
21
-
22
- entries[2].line.should == 3
23
- entries[2].message.should == 'the use of then/do is not needed here'
24
- end
25
-
26
- # See https://github.com/YorickPeterse/ruby-lint/issues/32 for the motivation
27
- # behind this test.
28
- example 'not warn when no do/then identifier is used in a statement' do
29
- code = <<-CODE.strip
30
- if true; end
31
-
32
- if foo && bar
33
- true
34
- else
35
- false
36
- end
37
-
38
- foo ? true : false
39
- CODE
40
-
41
- report = build_report(code, RubyLint::Analysis::Pedantics)
42
-
43
- report.entries.empty?.should == true
44
- end
45
-
46
- example 'warn for the use of BEGIN/END' do
47
- code = <<-CODE
48
- BEGIN {}
49
- END {}
50
- CODE
51
-
52
- report = build_report(code, RubyLint::Analysis::Pedantics)
53
- entries = report.entries
54
-
55
- entries.length.should == 2
56
-
57
- entries[0].line.should == 1
58
- entries[0].message.should == 'BEGIN/END is useless'
59
-
60
- entries[1].line.should == 2
61
- entries[1].message.should == 'BEGIN/END is useless'
62
- end
63
- end
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::ShadowingVariables do
4
- example 'warn for shadowing outer variables' do
5
- code = <<-CODE
6
- number = 10
7
-
8
- [10, 20].each do |number|
9
- puts number
10
- end
11
- CODE
12
-
13
- report = build_report(code, RubyLint::Analysis::ShadowingVariables)
14
- entry = report.entries[0]
15
-
16
- entry.is_a?(RubyLint::Report::Entry).should == true
17
-
18
- entry.line.should == 3
19
- entry.column.should == 19
20
- entry.message.should == 'shadowing outer local variable number'
21
- end
22
-
23
- example 'not warn for shadowed variables in a new scope' do
24
- code = <<-CODE
25
- number = 10
26
-
27
- def example
28
- [10, 20].each do |number|
29
- puts number
30
- end
31
- end
32
- CODE
33
-
34
- report = build_report(code, RubyLint::Analysis::ShadowingVariables)
35
-
36
- report.entries.empty?.should == true
37
- end
38
-
39
- example 'warn when shadowing variables after a new scope' do
40
- code = <<-CODE
41
- number = 10
42
-
43
- def example; end
44
-
45
- [10, 20].each do |number|
46
- puts number
47
- end
48
- CODE
49
-
50
- report = build_report(code, RubyLint::Analysis::ShadowingVariables)
51
- entry = report.entries[0]
52
-
53
- entry.is_a?(RubyLint::Report::Entry).should == true
54
-
55
- entry.line.should == 5
56
- entry.column.should == 19
57
- entry.message.should == 'shadowing outer local variable number'
58
- end
59
-
60
- example 'not fail when re-using the same block' do
61
- code = <<-CODE
62
- number = 10
63
-
64
- A::B.example do |number|
65
- number
66
- end
67
-
68
- A::B.example do |number|
69
- number
70
- end
71
- CODE
72
-
73
- report = build_report(code, RubyLint::Analysis::ShadowingVariables)
74
-
75
- report.entries.length.should == 2
76
-
77
- first, second = report.entries
78
-
79
- first.line.should == 3
80
- first.column.should == 18
81
-
82
- second.line.should == 7
83
- second.column.should == 18
84
- end
85
- end
@@ -1,337 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe RubyLint::Analysis::UndefinedMethods do
4
- example 'add an error for calling an undefined method' do
5
- report = build_report('example_method', RubyLint::Analysis::UndefinedMethods)
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 method example_method'
13
- end
14
-
15
- example 'add an error for calling an undefined method with a receiver' do
16
- code = <<-CODE
17
- class << self
18
- def example_method
19
- end
20
- end
21
-
22
- String.example_method
23
- CODE
24
-
25
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
26
- entry = report.entries[0]
27
-
28
- entry.is_a?(RubyLint::Report::Entry).should == true
29
-
30
- entry.line.should == 6
31
- entry.column.should == 1
32
- entry.message.should == 'undefined method example_method on String'
33
- end
34
-
35
- example 'add an error for calling an undefined method on a receiver instance' do
36
- code = '"hello".example_method'
37
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
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 == 'undefined method example_method ' \
45
- 'on an instance of String'
46
- end
47
-
48
- example 'add an error when calling a method defined in a different scope' do
49
- code = <<-CODE
50
- class Person
51
- def person_name
52
- return 'name'
53
- end
54
-
55
- def greet
56
- name
57
- end
58
- end
59
-
60
- person_name
61
- CODE
62
-
63
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
64
-
65
- report.entries.length.should == 1
66
-
67
- entry = report.entries[0]
68
-
69
- entry.is_a?(RubyLint::Report::Entry).should == true
70
-
71
- entry.line.should == 11
72
- entry.column.should == 1
73
- entry.message.should == 'undefined method person_name'
74
- end
75
-
76
- describe 'core Ruby types' do
77
- example 'do not add errors for calling defined methods on a Fixnum' do
78
- report = build_report('10.to_s', RubyLint::Analysis::UndefinedMethods)
79
-
80
- report.entries.empty?.should == true
81
- end
82
-
83
- example 'do not add errors for calling defined methods on a Float' do
84
- report = build_report('(10.0).to_s', RubyLint::Analysis::UndefinedMethods)
85
-
86
- report.entries.empty?.should == true
87
- end
88
-
89
- example 'do not add errors for calling defined methods on a String' do
90
- report = build_report('"10".to_s', RubyLint::Analysis::UndefinedMethods)
91
-
92
- report.entries.empty?.should == true
93
- end
94
-
95
- example 'do not add errors for calling defined methods on a Hash' do
96
- report = build_report('{}.to_s', RubyLint::Analysis::UndefinedMethods)
97
-
98
- report.entries.empty?.should == true
99
- end
100
-
101
- example 'do not add errors for calling defined methods on an Array' do
102
- report = build_report('[].to_s', RubyLint::Analysis::UndefinedMethods)
103
-
104
- report.entries.empty?.should == true
105
- end
106
- end
107
-
108
- example 'do not add errors for variables created using blocks' do
109
- code = <<-CODE
110
- [10, 20].each do |number|
111
- number.to_s
112
- end
113
- CODE
114
-
115
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
116
-
117
- report.entries.empty?.should == true
118
- end
119
-
120
- example 'take variable assignments into account' do
121
- code = <<-CODE
122
- name = 'Ruby'
123
-
124
- name.downcase
125
- name.downcasex
126
- CODE
127
-
128
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
129
-
130
- report.entries.length.should == 1
131
-
132
- entry = report.entries[0]
133
-
134
- entry.line.should == 4
135
- entry.column.should == 1
136
- entry.message.should == 'undefined method downcasex on an instance of String'
137
- end
138
-
139
- example 'take variable assignments and custom classes into account' do
140
- code = <<-CODE
141
- class User
142
- def example
143
- end
144
- end
145
-
146
- user = User.new
147
-
148
- user.example
149
- user.invalid
150
- CODE
151
-
152
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
153
-
154
- report.entries.length.should == 1
155
-
156
- entry = report.entries[0]
157
-
158
- entry.line.should == 9
159
- entry.column.should == 1
160
- entry.message.should == 'undefined method invalid on an instance of User'
161
- end
162
-
163
- example 'do not add errors when calling a method on an undefined constant' do
164
- code = 'A.example_method'
165
-
166
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
167
-
168
- report.entries.empty?.should == true
169
- end
170
-
171
- example 'do not add errors for methods called on variables without values' do
172
- code = <<-CODE
173
- def example(number)
174
- number.to_s
175
- end
176
- CODE
177
-
178
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
179
-
180
- report.entries.empty?.should == true
181
- end
182
-
183
- example 'report the right receiver name in multiple variable assignments' do
184
- code = <<-CODE
185
- number = 10
186
-
187
- first = second = number.foobar
188
- CODE
189
-
190
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
191
-
192
- report.entries.length.should == 1
193
-
194
- entry = report.entries[0]
195
-
196
- entry.message.should == 'undefined method foobar on an instance of Fixnum'
197
- end
198
-
199
- example 'ignore methods calls on other non existing methods' do
200
- code = 'foo.bar'
201
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
202
-
203
- report.entries.length.should == 1
204
-
205
- report.entries[0].message.should == 'undefined method foo'
206
- end
207
-
208
- example 'ignore methods calls with arguments on other non existing methods' do
209
- code = 'foo.bar(:baz)'
210
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
211
-
212
- report.entries.length.should == 1
213
-
214
- report.entries[0].message.should == 'undefined method foo'
215
- end
216
-
217
- context 'Kernel methods' do
218
- example 'do not add errors for methods defined in Kernel' do
219
- code = 'puts "hello"'
220
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
221
-
222
- report.entries.empty?.should == true
223
- end
224
-
225
- example 'do not add errors for Kernel methods in an sclass in a module' do
226
- code = <<-CODE
227
- module Foo
228
- def self.foo
229
- end
230
-
231
- class << self
232
- alias_method :foo, :bar
233
- end
234
- end
235
- CODE
236
-
237
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
238
-
239
- report.entries.empty?.should == true
240
- end
241
- end
242
-
243
- context 'core Ruby methods' do
244
- example 'do not add errors for #include' do
245
- code = <<-CODE
246
- module Foo
247
- end
248
-
249
- class Bar
250
- include Foo
251
- end
252
- CODE
253
-
254
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
255
-
256
- report.entries.empty?.should == true
257
- end
258
-
259
- example 'do not add errors for #attr_reader' do
260
- code = <<-CODE
261
- class Bar
262
- attr_reader :foobar
263
- end
264
- CODE
265
-
266
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
267
-
268
- report.entries.empty?.should == true
269
- end
270
- end
271
-
272
- example 'properly handle method lookups in blocks' do
273
- code = <<-CODE
274
- class Foo
275
- def baz
276
- end
277
-
278
- [10, 20].each do
279
- define_method(:example) do
280
- baz
281
- end
282
- end
283
- end
284
- CODE
285
-
286
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
287
-
288
- report.entries.empty?.should == true
289
- end
290
-
291
- example 'do not add errors for private/protected/public' do
292
- code = <<-CODE
293
- private
294
- protected
295
- public
296
- CODE
297
-
298
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
299
-
300
- report.entries.empty?.should == true
301
- end
302
-
303
- example 'use the correct error message for YARD documented arguments' do
304
- code = <<-CODE
305
- ##
306
- # @param [Fixnum|Bignum|Numeric] number
307
- #
308
- def double(number)
309
- return number.to_foo
310
- end
311
- CODE
312
-
313
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
314
- entry = report.entries[0]
315
-
316
- entry.line.should == 5
317
- entry.message.should == 'undefined method to_foo on an instance of ' \
318
- 'Fixnum, Bignum or Numeric'
319
- end
320
-
321
- context 'method missing' do
322
- example 'do not add errors when method_missing is defined' do
323
- code = <<-CODE
324
- class Foo
325
- def method_missing; end
326
- end
327
-
328
- foo = Foo.new
329
- foo.bar
330
- CODE
331
-
332
- report = build_report(code, RubyLint::Analysis::UndefinedMethods)
333
-
334
- report.entries.empty?.should == true
335
- end
336
- end
337
- end