ruby-lint 0.0.2 → 0.0.3
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.
- data.tar.gz.asc +17 -0
- data/.gitignore +1 -0
- data/.travis.yml +25 -0
- data/.yardopts +4 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/MANIFEST +238 -49
- data/README.md +84 -131
- data/Rakefile +6 -0
- data/bin/ruby-lint +2 -2
- data/checksum/.gitkeep +0 -0
- data/doc/DCO.md +26 -0
- data/doc/architecture.md +63 -0
- data/doc/code_analysis.md +90 -0
- data/doc/configuration.md +86 -0
- data/doc/contributing.md +16 -0
- data/doc/graphviz/flow.dot +7 -0
- data/doc/images/.gitkeep +0 -0
- data/doc/images/flow.png +0 -0
- data/lib/ruby-lint.rb +35 -35
- data/lib/ruby-lint/analyze/argument_amount.rb +73 -0
- data/lib/ruby-lint/analyze/shadowing_variables.rb +19 -24
- data/lib/ruby-lint/analyze/undefined_methods.rb +68 -0
- data/lib/ruby-lint/analyze/undefined_variables.rb +42 -69
- data/lib/ruby-lint/analyze/unused_variables.rb +23 -78
- data/lib/ruby-lint/base.rb +85 -0
- data/lib/ruby-lint/cli.rb +23 -167
- data/lib/ruby-lint/cli/analyze.rb +99 -0
- data/lib/ruby-lint/cli/ast.rb +35 -0
- data/lib/ruby-lint/cli/base.rb +120 -0
- data/lib/ruby-lint/configuration.rb +112 -0
- data/lib/ruby-lint/constant_loader.rb +92 -0
- data/lib/ruby-lint/definition/ruby_method.rb +248 -0
- data/lib/ruby-lint/definition/ruby_object.rb +757 -0
- data/lib/ruby-lint/definition_generator.rb +155 -0
- data/lib/ruby-lint/definitions/core.rb +5 -0
- data/lib/ruby-lint/definitions/core/arg0.rb +7 -0
- data/lib/ruby-lint/definitions/core/argf.rb +7 -0
- data/lib/ruby-lint/definitions/core/argument_error.rb +12 -0
- data/lib/ruby-lint/definitions/core/argv.rb +7 -0
- data/lib/ruby-lint/definitions/core/array.rb +414 -0
- data/lib/ruby-lint/definitions/core/autoload.rb +39 -0
- data/lib/ruby-lint/definitions/core/basic_object.rb +46 -0
- data/lib/ruby-lint/definitions/core/bignum.rb +128 -0
- data/lib/ruby-lint/definitions/core/binding.rb +52 -0
- data/lib/ruby-lint/definitions/core/class.rb +23 -0
- data/lib/ruby-lint/definitions/core/comparable.rb +38 -0
- data/lib/ruby-lint/definitions/core/complex.rb +195 -0
- data/lib/ruby-lint/definitions/core/condition_variable.rb +19 -0
- data/lib/ruby-lint/definitions/core/continuation.rb +8 -0
- data/lib/ruby-lint/definitions/core/data.rb +8 -0
- data/lib/ruby-lint/definitions/core/date.rb +706 -0
- data/lib/ruby-lint/definitions/core/date_time.rb +381 -0
- data/lib/ruby-lint/definitions/core/default_record_separator.rb +7 -0
- data/lib/ruby-lint/definitions/core/digest.rb +166 -0
- data/lib/ruby-lint/definitions/core/dir.rb +496 -0
- data/lib/ruby-lint/definitions/core/encoding.rb +2030 -0
- data/lib/ruby-lint/definitions/core/encoding_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/enumerable.rb +352 -0
- data/lib/ruby-lint/definitions/core/enumerator.rb +37 -0
- data/lib/ruby-lint/definitions/core/env.rb +7 -0
- data/lib/ruby-lint/definitions/core/eoferror.rb +8 -0
- data/lib/ruby-lint/definitions/core/erb.rb +304 -0
- data/lib/ruby-lint/definitions/core/errno.rb +3331 -0
- data/lib/ruby-lint/definitions/core/etc.rb +138 -0
- data/lib/ruby-lint/definitions/core/exception.rb +72 -0
- data/lib/ruby-lint/definitions/core/false.rb +7 -0
- data/lib/ruby-lint/definitions/core/false_class.rb +30 -0
- data/lib/ruby-lint/definitions/core/fatal_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/fiber.rb +35 -0
- data/lib/ruby-lint/definitions/core/fiber_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/file.rb +1277 -0
- data/lib/ruby-lint/definitions/core/file_list.rb +727 -0
- data/lib/ruby-lint/definitions/core/file_test.rb +106 -0
- data/lib/ruby-lint/definitions/core/file_utils.rb +1027 -0
- data/lib/ruby-lint/definitions/core/fixnum.rb +156 -0
- data/lib/ruby-lint/definitions/core/float.rb +307 -0
- data/lib/ruby-lint/definitions/core/float_domain_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/gc.rb +57 -0
- data/lib/ruby-lint/definitions/core/gem.rb +3161 -0
- data/lib/ruby-lint/definitions/core/hash.rb +512 -0
- data/lib/ruby-lint/definitions/core/immediate_value.rb +19 -0
- data/lib/ruby-lint/definitions/core/index_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/integer.rb +100 -0
- data/lib/ruby-lint/definitions/core/interrupt.rb +14 -0
- data/lib/ruby-lint/definitions/core/io.rb +928 -0
- data/lib/ruby-lint/definitions/core/ioerror.rb +8 -0
- data/lib/ruby-lint/definitions/core/kernel.rb +504 -0
- data/lib/ruby-lint/definitions/core/key_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/load_error.rb +28 -0
- data/lib/ruby-lint/definitions/core/local_jump_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/main.rb +25 -0
- data/lib/ruby-lint/definitions/core/marshal.rb +466 -0
- data/lib/ruby-lint/definitions/core/match_data.rb +73 -0
- data/lib/ruby-lint/definitions/core/math.rb +205 -0
- data/lib/ruby-lint/definitions/core/memory_segmention_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/method.rb +61 -0
- data/lib/ruby-lint/definitions/core/module.rb +262 -0
- data/lib/ruby-lint/definitions/core/monitor.rb +39 -0
- data/lib/ruby-lint/definitions/core/monitor_mixin.rb +59 -0
- data/lib/ruby-lint/definitions/core/mutex.rb +32 -0
- data/lib/ruby-lint/definitions/core/name_error.rb +16 -0
- data/lib/ruby-lint/definitions/core/nil.rb +7 -0
- data/lib/ruby-lint/definitions/core/nil_class.rb +46 -0
- data/lib/ruby-lint/definitions/core/no_memory_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/no_method_error.rb +18 -0
- data/lib/ruby-lint/definitions/core/not_implemented_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/numeric.rb +123 -0
- data/lib/ruby-lint/definitions/core/object.rb +31 -0
- data/lib/ruby-lint/definitions/core/object_space.rb +41 -0
- data/lib/ruby-lint/definitions/core/open_struct.rb +49 -0
- data/lib/ruby-lint/definitions/core/option_parser.rb +1355 -0
- data/lib/ruby-lint/definitions/core/precision.rb +21 -0
- data/lib/ruby-lint/definitions/core/primitive_failure.rb +8 -0
- data/lib/ruby-lint/definitions/core/proc.rb +109 -0
- data/lib/ruby-lint/definitions/core/process.rb +602 -0
- data/lib/ruby-lint/definitions/core/psych.rb +2231 -0
- data/lib/ruby-lint/definitions/core/queue.rb +44 -0
- data/lib/ruby-lint/definitions/core/rake.rb +4784 -0
- data/lib/ruby-lint/definitions/core/rake_file_utils.rb +203 -0
- data/lib/ruby-lint/definitions/core/rakeversion.rb +7 -0
- data/lib/ruby-lint/definitions/core/random.rb +38 -0
- data/lib/ruby-lint/definitions/core/range.rb +104 -0
- data/lib/ruby-lint/definitions/core/range_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/rational.rb +96 -0
- data/lib/ruby-lint/definitions/core/rb_config.rb +36 -0
- data/lib/ruby-lint/definitions/core/regexp.rb +396 -0
- data/lib/ruby-lint/definitions/core/regexp_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/rubinius.rb +16637 -0
- data/lib/ruby-lint/definitions/core/ruby_copyright.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_description.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_engine.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_lint.rb +93 -0
- data/lib/ruby-lint/definitions/core/ruby_patchlevel.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_platform.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_release_date.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_version.rb +7 -0
- data/lib/ruby-lint/definitions/core/runtime_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/scan_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/script_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/security_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/shellwords.rb +37 -0
- data/lib/ruby-lint/definitions/core/signal.rb +37 -0
- data/lib/ruby-lint/definitions/core/signal_exception.rb +19 -0
- data/lib/ruby-lint/definitions/core/singleton.rb +37 -0
- data/lib/ruby-lint/definitions/core/sized_queue.rb +42 -0
- data/lib/ruby-lint/definitions/core/standard_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/stderr.rb +7 -0
- data/lib/ruby-lint/definitions/core/stdin.rb +7 -0
- data/lib/ruby-lint/definitions/core/stdout.rb +7 -0
- data/lib/ruby-lint/definitions/core/stop_iteration.rb +8 -0
- data/lib/ruby-lint/definitions/core/string.rb +713 -0
- data/lib/ruby-lint/definitions/core/string_io.rb +287 -0
- data/lib/ruby-lint/definitions/core/string_scanner.rb +158 -0
- data/lib/ruby-lint/definitions/core/struct.rb +357 -0
- data/lib/ruby-lint/definitions/core/syck.rb +30 -0
- data/lib/ruby-lint/definitions/core/symbol.rb +90 -0
- data/lib/ruby-lint/definitions/core/syntax_error.rb +44 -0
- data/lib/ruby-lint/definitions/core/system_call_error.rb +31 -0
- data/lib/ruby-lint/definitions/core/system_exit.rb +19 -0
- data/lib/ruby-lint/definitions/core/system_stack_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/thread.rb +209 -0
- data/lib/ruby-lint/definitions/core/thread_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/thread_group.rb +22 -0
- data/lib/ruby-lint/definitions/core/time.rb +233 -0
- data/lib/ruby-lint/definitions/core/toplevel_binding.rb +7 -0
- data/lib/ruby-lint/definitions/core/true.rb +7 -0
- data/lib/ruby-lint/definitions/core/true_class.rb +30 -0
- data/lib/ruby-lint/definitions/core/type_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/unbound_method.rb +51 -0
- data/lib/ruby-lint/definitions/core/unmarshalable.rb +13 -0
- data/lib/ruby-lint/definitions/core/unsupported_library_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/weak_ref.rb +42 -0
- data/lib/ruby-lint/definitions/core/zero_division_error.rb +8 -0
- data/lib/ruby-lint/definitions_builder.rb +692 -0
- data/lib/ruby-lint/extensions/string.rb +15 -0
- data/lib/ruby-lint/helper/constant_paths.rb +41 -0
- data/lib/ruby-lint/helper/conversion.rb +33 -0
- data/lib/ruby-lint/helper/current_scope.rb +98 -0
- data/lib/ruby-lint/helper/methods.rb +91 -0
- data/lib/ruby-lint/inspector.rb +191 -0
- data/lib/ruby-lint/iterator.rb +187 -127
- data/lib/ruby-lint/node.rb +107 -0
- data/lib/ruby-lint/parser.rb +510 -1137
- data/lib/ruby-lint/parser_error.rb +15 -27
- data/lib/ruby-lint/presenter/json.rb +19 -0
- data/lib/ruby-lint/presenter/text.rb +37 -0
- data/lib/ruby-lint/report.rb +95 -53
- data/lib/ruby-lint/report/entry.rb +71 -0
- data/lib/ruby-lint/template/definition.erb +24 -0
- data/lib/ruby-lint/template/scope.rb +25 -0
- data/lib/ruby-lint/variable_predicates.rb +109 -0
- data/lib/ruby-lint/version.rb +1 -1
- data/ruby-lint.gemspec +19 -8
- data/spec/helper.rb +10 -2
- data/spec/ruby-lint/analyze/argument_amount.rb +91 -0
- data/spec/ruby-lint/analyze/shadowing_variables.rb +69 -14
- data/spec/ruby-lint/analyze/undefined_methods.rb +174 -0
- data/spec/ruby-lint/analyze/undefined_variables.rb +70 -179
- data/spec/ruby-lint/analyze/unused_variables.rb +63 -183
- data/spec/ruby-lint/configuration.rb +15 -0
- data/spec/ruby-lint/constant_loader.rb +32 -0
- data/spec/ruby-lint/definition/dsl.rb +142 -0
- data/spec/ruby-lint/definition/method_calls.rb +26 -0
- data/spec/ruby-lint/definition/ruby_method.rb +175 -0
- data/spec/ruby-lint/definition/ruby_object.rb +228 -0
- data/spec/ruby-lint/definitions_builder/assignments/arrays.rb +71 -0
- data/spec/ruby-lint/definitions_builder/assignments/hashes.rb +65 -0
- data/spec/ruby-lint/definitions_builder/assignments/objects.rb +23 -0
- data/spec/ruby-lint/definitions_builder/assignments/optional.rb +22 -0
- data/spec/ruby-lint/definitions_builder/assignments/return_values.rb +78 -0
- data/spec/ruby-lint/definitions_builder/assignments/variables.rb +71 -0
- data/spec/ruby-lint/definitions_builder/associate_nodes.rb +17 -0
- data/spec/ruby-lint/definitions_builder/blocks.rb +40 -0
- data/spec/ruby-lint/definitions_builder/classes.rb +230 -0
- data/spec/ruby-lint/definitions_builder/for.rb +16 -0
- data/spec/ruby-lint/definitions_builder/methods.rb +147 -0
- data/spec/ruby-lint/definitions_builder/modules.rb +175 -0
- data/spec/ruby-lint/definitions_builder/reference_amount.rb +31 -0
- data/spec/ruby-lint/definitions_builder/unused.rb +15 -0
- data/spec/ruby-lint/extensions/string.rb +7 -0
- data/spec/ruby-lint/iterator.rb +42 -417
- data/spec/ruby-lint/node.rb +38 -0
- data/spec/ruby-lint/parser/assignments.rb +225 -0
- data/spec/ruby-lint/parser/classes.rb +80 -122
- data/spec/ruby-lint/parser/errors.rb +7 -14
- data/spec/ruby-lint/parser/metadata.rb +17 -0
- data/spec/ruby-lint/parser/method_definitions.rb +111 -0
- data/spec/ruby-lint/parser/methods.rb +184 -216
- data/spec/ruby-lint/parser/modules.rb +54 -33
- data/spec/ruby-lint/parser/operators.rb +30 -65
- data/spec/ruby-lint/parser/statements/begin.rb +55 -0
- data/spec/ruby-lint/parser/statements/case.rb +34 -0
- data/spec/ruby-lint/parser/statements/defined.rb +11 -0
- data/spec/ruby-lint/parser/statements/for.rb +34 -0
- data/spec/ruby-lint/parser/statements/if.rb +46 -0
- data/spec/ruby-lint/parser/statements/return.rb +14 -0
- data/spec/ruby-lint/parser/statements/super.rb +49 -0
- data/spec/ruby-lint/parser/statements/unless.rb +42 -0
- data/spec/ruby-lint/parser/statements/until.rb +25 -0
- data/spec/ruby-lint/parser/statements/while.rb +25 -0
- data/spec/ruby-lint/parser/statements/yield.rb +18 -0
- data/spec/ruby-lint/parser/types/arrays.rb +47 -0
- data/spec/ruby-lint/parser/types/booleans.rb +11 -0
- data/spec/ruby-lint/parser/types/constants.rb +32 -0
- data/spec/ruby-lint/parser/types/hashes.rb +55 -0
- data/spec/ruby-lint/parser/types/nil.rb +7 -0
- data/spec/ruby-lint/parser/types/numbers.rb +11 -0
- data/spec/ruby-lint/parser/types/procs.rb +11 -0
- data/spec/ruby-lint/parser/types/ranges.rb +11 -0
- data/spec/ruby-lint/parser/types/regexp.rb +27 -0
- data/spec/ruby-lint/parser/types/strings.rb +44 -0
- data/spec/ruby-lint/parser/types/symbols.rb +15 -0
- data/spec/ruby-lint/presenter/json.rb +31 -0
- data/spec/ruby-lint/presenter/text.rb +22 -0
- data/spec/ruby-lint/report.rb +45 -15
- data/spec/ruby-lint/report/entry.rb +24 -0
- data/spec/support/bacon.rb +33 -0
- data/spec/support/building.rb +43 -0
- data/spec/support/definitions.rb +23 -0
- data/spec/support/parsing.rb +23 -0
- data/spec/support/simplecov.rb +16 -0
- data/task/build.rake +9 -0
- data/task/checksum.rake +13 -0
- data/task/coverage.rake +6 -0
- data/task/doc.rake +5 -0
- data/task/generate.rake +34 -0
- data/task/graphviz.rake +12 -0
- data/task/stdlib.rake +2 -9
- data/task/tag.rake +6 -0
- metadata +337 -68
- metadata.gz.asc +17 -0
- data/.rbenv-version +0 -1
- data/lib/ruby-lint/analyze/coding_style.rb +0 -407
- data/lib/ruby-lint/analyze/definitions.rb +0 -244
- data/lib/ruby-lint/analyze/method_validation.rb +0 -104
- data/lib/ruby-lint/callback.rb +0 -67
- data/lib/ruby-lint/constant_importer.rb +0 -112
- data/lib/ruby-lint/definition.rb +0 -230
- data/lib/ruby-lint/formatter/text.rb +0 -54
- data/lib/ruby-lint/helper/definition_resolver.rb +0 -143
- data/lib/ruby-lint/helper/scoping.rb +0 -138
- data/lib/ruby-lint/options.rb +0 -58
- data/lib/ruby-lint/token/assignment_token.rb +0 -35
- data/lib/ruby-lint/token/begin_rescue_token.rb +0 -57
- data/lib/ruby-lint/token/block_token.rb +0 -26
- data/lib/ruby-lint/token/case_token.rb +0 -44
- data/lib/ruby-lint/token/class_token.rb +0 -24
- data/lib/ruby-lint/token/keyword_token.rb +0 -43
- data/lib/ruby-lint/token/method_definition_token.rb +0 -64
- data/lib/ruby-lint/token/method_token.rb +0 -56
- data/lib/ruby-lint/token/parameters_token.rb +0 -99
- data/lib/ruby-lint/token/regexp_token.rb +0 -15
- data/lib/ruby-lint/token/statement_token.rb +0 -69
- data/lib/ruby-lint/token/token.rb +0 -176
- data/lib/ruby-lint/token/variable_token.rb +0 -18
- data/spec/benchmarks/memory.rb +0 -52
- data/spec/benchmarks/parse_parser.rb +0 -16
- data/spec/fixtures/stdlib/un.rb +0 -348
- data/spec/ruby-lint/analyze/coding_style.rb +0 -224
- data/spec/ruby-lint/analyze/complex/un.rb +0 -29
- data/spec/ruby-lint/analyze/definitions/classes.rb +0 -114
- data/spec/ruby-lint/analyze/definitions/methods.rb +0 -91
- data/spec/ruby-lint/analyze/definitions/modules.rb +0 -207
- data/spec/ruby-lint/analyze/definitions/variables.rb +0 -103
- data/spec/ruby-lint/analyze/method_validation.rb +0 -177
- data/spec/ruby-lint/callback.rb +0 -28
- data/spec/ruby-lint/constant_importer.rb +0 -27
- data/spec/ruby-lint/definition.rb +0 -96
- data/spec/ruby-lint/formatter/text.rb +0 -21
- data/spec/ruby-lint/parser/arrays.rb +0 -147
- data/spec/ruby-lint/parser/expander_assignments.rb +0 -183
- data/spec/ruby-lint/parser/hashes.rb +0 -136
- data/spec/ruby-lint/parser/keywords.rb +0 -89
- data/spec/ruby-lint/parser/objects.rb +0 -39
- data/spec/ruby-lint/parser/procs.rb +0 -113
- data/spec/ruby-lint/parser/ranges.rb +0 -49
- data/spec/ruby-lint/parser/regexp.rb +0 -31
- data/spec/ruby-lint/parser/scalars.rb +0 -93
- data/spec/ruby-lint/parser/statements.rb +0 -591
- data/spec/ruby-lint/parser/variables.rb +0 -230
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../../../../helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
describe 'RubyLint::Analyze::Definitions: modules' do
|
|
4
|
-
it 'Define a module in the global scope' do
|
|
5
|
-
code = <<-CODE
|
|
6
|
-
module Example
|
|
7
|
-
def example_method
|
|
8
|
-
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
CODE
|
|
12
|
-
|
|
13
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
14
|
-
iterator = RubyLint::Iterator.new
|
|
15
|
-
|
|
16
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
17
|
-
iterator.run(tokens)
|
|
18
|
-
|
|
19
|
-
scope = iterator.storage[:scope]
|
|
20
|
-
const = scope.lookup(:constant, 'Example')
|
|
21
|
-
|
|
22
|
-
const.class.should == RubyLint::Definition
|
|
23
|
-
|
|
24
|
-
const.token.class.should == RubyLint::Token::Token
|
|
25
|
-
const.token.type.should == :module
|
|
26
|
-
const.token.name.should == ['Example']
|
|
27
|
-
|
|
28
|
-
scope.lookup(:instance_method, 'example_method').nil?.should == true
|
|
29
|
-
|
|
30
|
-
method = const.lookup(:instance_method, 'example_method')
|
|
31
|
-
|
|
32
|
-
method.class.should == RubyLint::Definition
|
|
33
|
-
|
|
34
|
-
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
|
35
|
-
method.token.name.should == 'example_method'
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'Define a class method in a module' do
|
|
39
|
-
code = <<-CODE
|
|
40
|
-
module Example
|
|
41
|
-
def self.example_method
|
|
42
|
-
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
CODE
|
|
46
|
-
|
|
47
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
48
|
-
iterator = RubyLint::Iterator.new
|
|
49
|
-
|
|
50
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
51
|
-
iterator.run(tokens)
|
|
52
|
-
|
|
53
|
-
scope = iterator.storage[:scope]
|
|
54
|
-
const = scope.lookup(:constant, 'Example')
|
|
55
|
-
|
|
56
|
-
const.class.should == RubyLint::Definition
|
|
57
|
-
|
|
58
|
-
const.token.class.should == RubyLint::Token::Token
|
|
59
|
-
const.token.type.should == :module
|
|
60
|
-
const.token.name.should == ['Example']
|
|
61
|
-
|
|
62
|
-
scope.lookup(:method, 'example_method').nil?.should == true
|
|
63
|
-
|
|
64
|
-
method = const.lookup(:method, 'example_method')
|
|
65
|
-
|
|
66
|
-
method.class.should == RubyLint::Definition
|
|
67
|
-
|
|
68
|
-
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
|
69
|
-
method.token.name.should == 'example_method'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it 'Include a module into a class' do
|
|
73
|
-
code = <<-CODE
|
|
74
|
-
module A
|
|
75
|
-
def example_method
|
|
76
|
-
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
class B
|
|
81
|
-
include A
|
|
82
|
-
end
|
|
83
|
-
CODE
|
|
84
|
-
|
|
85
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
86
|
-
iterator = RubyLint::Iterator.new
|
|
87
|
-
|
|
88
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
89
|
-
iterator.run(tokens)
|
|
90
|
-
|
|
91
|
-
scope = iterator.storage[:scope]
|
|
92
|
-
const = scope.lookup(:constant, 'B')
|
|
93
|
-
|
|
94
|
-
const.class.should == RubyLint::Definition
|
|
95
|
-
|
|
96
|
-
const.lookup(:method, 'example_method').nil?.should == true
|
|
97
|
-
|
|
98
|
-
method = const.lookup(:instance_method, 'example_method')
|
|
99
|
-
|
|
100
|
-
method.class.should == RubyLint::Definition
|
|
101
|
-
|
|
102
|
-
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
|
103
|
-
method.token.name.should == 'example_method'
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'Extend a class using a module' do
|
|
107
|
-
code = <<-CODE
|
|
108
|
-
module A
|
|
109
|
-
def example_method
|
|
110
|
-
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
class B
|
|
115
|
-
extend A
|
|
116
|
-
end
|
|
117
|
-
CODE
|
|
118
|
-
|
|
119
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
120
|
-
iterator = RubyLint::Iterator.new
|
|
121
|
-
|
|
122
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
123
|
-
iterator.run(tokens)
|
|
124
|
-
|
|
125
|
-
scope = iterator.storage[:scope]
|
|
126
|
-
const = scope.lookup(:constant, 'B')
|
|
127
|
-
|
|
128
|
-
const.class.should == RubyLint::Definition
|
|
129
|
-
|
|
130
|
-
const.lookup(:instance_method, 'example_method').nil?.should == true
|
|
131
|
-
|
|
132
|
-
method = const.lookup(:method, 'example_method')
|
|
133
|
-
|
|
134
|
-
method.class.should == RubyLint::Definition
|
|
135
|
-
|
|
136
|
-
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
|
137
|
-
method.token.name.should == 'example_method'
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it 'Include a module using a constant path' do
|
|
141
|
-
code = <<-CODE
|
|
142
|
-
module A
|
|
143
|
-
module B
|
|
144
|
-
def example_method
|
|
145
|
-
|
|
146
|
-
end
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
class C
|
|
151
|
-
include A::B
|
|
152
|
-
end
|
|
153
|
-
CODE
|
|
154
|
-
|
|
155
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
156
|
-
iterator = RubyLint::Iterator.new
|
|
157
|
-
|
|
158
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
159
|
-
iterator.run(tokens)
|
|
160
|
-
|
|
161
|
-
scope = iterator.storage[:scope]
|
|
162
|
-
const = scope.lookup(:constant, 'C')
|
|
163
|
-
|
|
164
|
-
const.class.should == RubyLint::Definition
|
|
165
|
-
|
|
166
|
-
const.lookup(:method, 'example_method').nil?.should == true
|
|
167
|
-
|
|
168
|
-
method = const.lookup(:instance_method, 'example_method')
|
|
169
|
-
|
|
170
|
-
method.class.should == RubyLint::Definition
|
|
171
|
-
|
|
172
|
-
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
|
173
|
-
method.token.name.should == 'example_method'
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it 'Define a module in an existing module' do
|
|
177
|
-
code = <<-CODE
|
|
178
|
-
module RubyLint
|
|
179
|
-
module Derp
|
|
180
|
-
|
|
181
|
-
end
|
|
182
|
-
end
|
|
183
|
-
CODE
|
|
184
|
-
|
|
185
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
186
|
-
iterator = RubyLint::Iterator.new
|
|
187
|
-
|
|
188
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
189
|
-
iterator.run(tokens)
|
|
190
|
-
|
|
191
|
-
scope = iterator.storage[:scope]
|
|
192
|
-
|
|
193
|
-
scope.lookup(:constant, 'Derp').nil?.should == true
|
|
194
|
-
|
|
195
|
-
scope.lookup(:constant, 'RubyLint').class.should == RubyLint::Definition
|
|
196
|
-
|
|
197
|
-
scope.lookup(:constant, 'RubyLint') \
|
|
198
|
-
.lookup(:constant, 'Derp') \
|
|
199
|
-
.class \
|
|
200
|
-
.should == RubyLint::Definition
|
|
201
|
-
|
|
202
|
-
ruby_lint = scope.lookup(:constant, 'RubyLint')
|
|
203
|
-
derp = ruby_lint.lookup(:constant, 'Derp')
|
|
204
|
-
|
|
205
|
-
derp.parent.length.should == 1
|
|
206
|
-
end
|
|
207
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../../../../helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
describe 'RubyLint::Analyze::Definitions: variables' do
|
|
4
|
-
it 'Build a list of variables defined in the global scope' do
|
|
5
|
-
code = <<-CODE
|
|
6
|
-
number = 10
|
|
7
|
-
@number = 10
|
|
8
|
-
@@number = 10
|
|
9
|
-
$number = 10
|
|
10
|
-
NUMBER = 10
|
|
11
|
-
CODE
|
|
12
|
-
|
|
13
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
14
|
-
iterator = RubyLint::Iterator.new
|
|
15
|
-
|
|
16
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
17
|
-
iterator.run(tokens)
|
|
18
|
-
|
|
19
|
-
scope = iterator.storage[:scope]
|
|
20
|
-
|
|
21
|
-
scope.class.should == RubyLint::Definition
|
|
22
|
-
|
|
23
|
-
lvar = scope.lookup(:local_variable, 'number')
|
|
24
|
-
ivar = scope.lookup(:instance_variable, '@number')
|
|
25
|
-
cvar = scope.lookup(:class_variable, '@@number')
|
|
26
|
-
gvar = scope.lookup(:global_variable, '$number')
|
|
27
|
-
const = scope.lookup(:constant, 'NUMBER')
|
|
28
|
-
|
|
29
|
-
lvar.class.should == RubyLint::Definition
|
|
30
|
-
lvar.token.class.should == RubyLint::Token::AssignmentToken
|
|
31
|
-
lvar.token.name.should == 'number'
|
|
32
|
-
lvar.token.type.should == :local_variable
|
|
33
|
-
lvar.token.value.class.should == RubyLint::Token::Token
|
|
34
|
-
lvar.token.value.type.should == :integer
|
|
35
|
-
lvar.token.value.value.should == '10'
|
|
36
|
-
|
|
37
|
-
ivar.class.should == RubyLint::Definition
|
|
38
|
-
ivar.token.class.should == RubyLint::Token::AssignmentToken
|
|
39
|
-
ivar.token.name.should == '@number'
|
|
40
|
-
ivar.token.type.should == :instance_variable
|
|
41
|
-
ivar.token.value.class.should == RubyLint::Token::Token
|
|
42
|
-
ivar.token.value.type.should == :integer
|
|
43
|
-
ivar.token.value.value.should == '10'
|
|
44
|
-
|
|
45
|
-
cvar.class.should == RubyLint::Definition
|
|
46
|
-
cvar.token.class.should == RubyLint::Token::AssignmentToken
|
|
47
|
-
cvar.token.name.should == '@@number'
|
|
48
|
-
cvar.token.type.should == :class_variable
|
|
49
|
-
cvar.token.value.class.should == RubyLint::Token::Token
|
|
50
|
-
cvar.token.value.type.should == :integer
|
|
51
|
-
cvar.token.value.value.should == '10'
|
|
52
|
-
|
|
53
|
-
gvar.class.should == RubyLint::Definition
|
|
54
|
-
gvar.token.class.should == RubyLint::Token::AssignmentToken
|
|
55
|
-
gvar.token.name.should == '$number'
|
|
56
|
-
gvar.token.type.should == :global_variable
|
|
57
|
-
gvar.token.value.class.should == RubyLint::Token::Token
|
|
58
|
-
gvar.token.value.type.should == :integer
|
|
59
|
-
gvar.token.value.value.should == '10'
|
|
60
|
-
|
|
61
|
-
const.class.should == RubyLint::Definition
|
|
62
|
-
const.token.class.should == RubyLint::Token::AssignmentToken
|
|
63
|
-
const.token.name.should == 'NUMBER'
|
|
64
|
-
const.token.type.should == :constant
|
|
65
|
-
const.token.value.class.should == RubyLint::Token::Token
|
|
66
|
-
const.token.value.type.should == :integer
|
|
67
|
-
const.token.value.value.should == '10'
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'Build a list of variables defined inside a method' do
|
|
71
|
-
code = <<-CODE
|
|
72
|
-
def example_method
|
|
73
|
-
number = 10
|
|
74
|
-
end
|
|
75
|
-
CODE
|
|
76
|
-
|
|
77
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
78
|
-
iterator = RubyLint::Iterator.new
|
|
79
|
-
|
|
80
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
81
|
-
iterator.run(tokens)
|
|
82
|
-
|
|
83
|
-
scope = iterator.storage[:scope]
|
|
84
|
-
|
|
85
|
-
scope.lookup(:local_variable, 'number').nil?.should == true
|
|
86
|
-
|
|
87
|
-
method = scope.lookup(:instance_method, 'example_method')
|
|
88
|
-
|
|
89
|
-
method.class.should == RubyLint::Definition
|
|
90
|
-
|
|
91
|
-
method.token.class.should == RubyLint::Token::MethodDefinitionToken
|
|
92
|
-
method.token.name.should == 'example_method'
|
|
93
|
-
method.token.value.nil?.should == true
|
|
94
|
-
|
|
95
|
-
variable = method.lookup(:local_variable, 'number')
|
|
96
|
-
|
|
97
|
-
variable.class.should == RubyLint::Definition
|
|
98
|
-
variable.token.name.should == 'number'
|
|
99
|
-
variable.token.value.class.should == RubyLint::Token::Token
|
|
100
|
-
variable.token.value.type.should == :integer
|
|
101
|
-
variable.token.value.value.should == '10'
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../../../helper', __FILE__)
|
|
2
|
-
|
|
3
|
-
describe 'RubyLint::Analyze::MethodValidation' do
|
|
4
|
-
it 'Calling undefined methods' do
|
|
5
|
-
code = <<-CODE
|
|
6
|
-
def defined_method; end
|
|
7
|
-
|
|
8
|
-
undefined_method
|
|
9
|
-
defined_method
|
|
10
|
-
CODE
|
|
11
|
-
|
|
12
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
13
|
-
report = RubyLint::Report.new
|
|
14
|
-
iterator = RubyLint::Iterator.new(report)
|
|
15
|
-
|
|
16
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
17
|
-
iterator.bind(RubyLint::Analyze::MethodValidation)
|
|
18
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
19
|
-
iterator.run(tokens)
|
|
20
|
-
|
|
21
|
-
report.messages[:error].class.should == Array
|
|
22
|
-
report.messages[:error].length.should == 1
|
|
23
|
-
|
|
24
|
-
error = report.messages[:error][0]
|
|
25
|
-
|
|
26
|
-
error[:message].should == 'undefined local variable or method ' \
|
|
27
|
-
'undefined_method'
|
|
28
|
-
|
|
29
|
-
error[:line].should == 3
|
|
30
|
-
error[:column].should == 0
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'Calling non existing methods on constants' do
|
|
34
|
-
code = <<-CODE
|
|
35
|
-
String.new
|
|
36
|
-
String.newx
|
|
37
|
-
Foobar.new
|
|
38
|
-
CODE
|
|
39
|
-
|
|
40
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
41
|
-
report = RubyLint::Report.new
|
|
42
|
-
iterator = RubyLint::Iterator.new(report)
|
|
43
|
-
|
|
44
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
45
|
-
iterator.bind(RubyLint::Analyze::MethodValidation)
|
|
46
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
47
|
-
iterator.run(tokens)
|
|
48
|
-
|
|
49
|
-
report.messages[:error].class.should == Array
|
|
50
|
-
report.messages[:error].length.should == 2
|
|
51
|
-
|
|
52
|
-
errors = report.messages[:error]
|
|
53
|
-
|
|
54
|
-
errors[0][:message].should == 'undefined class method newx'
|
|
55
|
-
errors[0][:line].should == 2
|
|
56
|
-
errors[0][:column].should == 7
|
|
57
|
-
|
|
58
|
-
errors[1][:message].should == 'undefined constant Foobar'
|
|
59
|
-
errors[1][:line].should == 3
|
|
60
|
-
errors[1][:column].should == 0
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it 'Calling non existing methods on variables and values directly' do
|
|
64
|
-
code = <<-CODE
|
|
65
|
-
name = 'Ruby'
|
|
66
|
-
|
|
67
|
-
name.upcase
|
|
68
|
-
name.upcasexx
|
|
69
|
-
foo.upcase
|
|
70
|
-
|
|
71
|
-
''.downcase
|
|
72
|
-
''.downcasex
|
|
73
|
-
CODE
|
|
74
|
-
|
|
75
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
76
|
-
report = RubyLint::Report.new
|
|
77
|
-
iterator = RubyLint::Iterator.new(report)
|
|
78
|
-
|
|
79
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
80
|
-
iterator.bind(RubyLint::Analyze::MethodValidation)
|
|
81
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
82
|
-
iterator.run(tokens)
|
|
83
|
-
|
|
84
|
-
report.messages[:error].class.should == Array
|
|
85
|
-
report.messages[:error].length.should == 3
|
|
86
|
-
|
|
87
|
-
errors = report.messages[:error]
|
|
88
|
-
|
|
89
|
-
errors[0][:message].should == 'undefined instance method upcasexx'
|
|
90
|
-
errors[0][:line].should == 4
|
|
91
|
-
errors[0][:column].should == 5
|
|
92
|
-
|
|
93
|
-
errors[1][:message].should == 'undefined instance method downcasex'
|
|
94
|
-
errors[1][:line].should == 8
|
|
95
|
-
errors[1][:column].should == 3
|
|
96
|
-
|
|
97
|
-
errors[2][:message].should == 'undefined local variable or method foo'
|
|
98
|
-
errors[2][:line].should == 5
|
|
99
|
-
errors[2][:column].should == 0
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'Method parameters should be added as local variables' do
|
|
103
|
-
code = <<-CODE
|
|
104
|
-
def uppercase(name = 'Ruby', *args, &block)
|
|
105
|
-
name.upcase
|
|
106
|
-
namex.upcase
|
|
107
|
-
args.flatten
|
|
108
|
-
block.call
|
|
109
|
-
end
|
|
110
|
-
CODE
|
|
111
|
-
|
|
112
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
113
|
-
report = RubyLint::Report.new
|
|
114
|
-
iterator = RubyLint::Iterator.new(report)
|
|
115
|
-
|
|
116
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
117
|
-
iterator.bind(RubyLint::Analyze::MethodValidation)
|
|
118
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
119
|
-
iterator.run(tokens)
|
|
120
|
-
|
|
121
|
-
report.messages[:error].class.should == Array
|
|
122
|
-
report.messages[:error].length.should == 1
|
|
123
|
-
|
|
124
|
-
error = report.messages[:error][0]
|
|
125
|
-
|
|
126
|
-
error[:message].should == 'undefined local variable or method namex'
|
|
127
|
-
error[:line].should == 3
|
|
128
|
-
error[:column].should == 2
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it 'Calling methods on a constant path' do
|
|
132
|
-
code = <<-CODE
|
|
133
|
-
A::B.invalid_method
|
|
134
|
-
|
|
135
|
-
module A; end
|
|
136
|
-
|
|
137
|
-
A::B.invalid_method
|
|
138
|
-
|
|
139
|
-
module A
|
|
140
|
-
module B
|
|
141
|
-
def self.valid_method
|
|
142
|
-
|
|
143
|
-
end
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
A::B.invalid_method
|
|
148
|
-
A::B.valid_method
|
|
149
|
-
CODE
|
|
150
|
-
|
|
151
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
152
|
-
report = RubyLint::Report.new
|
|
153
|
-
iterator = RubyLint::Iterator.new(report)
|
|
154
|
-
|
|
155
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
156
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
157
|
-
iterator.bind(RubyLint::Analyze::MethodValidation)
|
|
158
|
-
iterator.run(tokens)
|
|
159
|
-
|
|
160
|
-
report.messages[:error].class.should == Array
|
|
161
|
-
report.messages[:error].length.should == 3
|
|
162
|
-
|
|
163
|
-
errors = report.messages[:error]
|
|
164
|
-
|
|
165
|
-
errors[0][:message].should == 'undefined constant A'
|
|
166
|
-
errors[0][:line].should == 1
|
|
167
|
-
errors[0][:column].should == 0
|
|
168
|
-
|
|
169
|
-
errors[1][:message].should == 'undefined constant A::B'
|
|
170
|
-
errors[1][:line].should == 5
|
|
171
|
-
errors[1][:column].should == 0
|
|
172
|
-
|
|
173
|
-
errors[2][:message].should == 'undefined class method invalid_method'
|
|
174
|
-
errors[2][:line].should == 15
|
|
175
|
-
errors[2][:column].should == 5
|
|
176
|
-
end
|
|
177
|
-
end
|