ruby-lint 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,22 @@
|
|
1
|
+
##
|
2
|
+
# Constant: ThreadGroup
|
3
|
+
# Created: 2013-04-01 18:33:55 +0200
|
4
|
+
# Platform: rbx 2.0.0.rc1
|
5
|
+
#
|
6
|
+
RubyLint.global_scope.define_constant('ThreadGroup') do |klass|
|
7
|
+
klass.inherits(RubyLint.global_constant('Object'))
|
8
|
+
|
9
|
+
klass.define_method('__class_init__')
|
10
|
+
|
11
|
+
klass.define_instance_method('add') do |method|
|
12
|
+
method.define_argument('thread')
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.define_instance_method('initialize')
|
16
|
+
|
17
|
+
klass.define_instance_method('list')
|
18
|
+
|
19
|
+
klass.define_instance_method('remove') do |method|
|
20
|
+
method.define_argument('thread')
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
##
|
2
|
+
# Constant: Time
|
3
|
+
# Created: 2013-04-01 18:33:55 +0200
|
4
|
+
# Platform: rbx 2.0.0.rc1
|
5
|
+
#
|
6
|
+
RubyLint.global_scope.define_constant('Time') do |klass|
|
7
|
+
klass.inherits(RubyLint.global_constant('Object'))
|
8
|
+
|
9
|
+
klass.define_method('__class_init__')
|
10
|
+
|
11
|
+
klass.define_method('_load') do |method|
|
12
|
+
method.define_argument('data')
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.define_method('at') do |method|
|
16
|
+
method.define_argument('sec')
|
17
|
+
method.define_optional_argument('usec')
|
18
|
+
end
|
19
|
+
|
20
|
+
klass.define_method('compose') do |method|
|
21
|
+
method.define_argument('offset')
|
22
|
+
method.define_argument('p1')
|
23
|
+
method.define_optional_argument('p2')
|
24
|
+
method.define_optional_argument('p3')
|
25
|
+
method.define_optional_argument('p4')
|
26
|
+
method.define_optional_argument('p5')
|
27
|
+
method.define_optional_argument('p6')
|
28
|
+
method.define_optional_argument('p7')
|
29
|
+
method.define_optional_argument('yday')
|
30
|
+
method.define_optional_argument('is_dst')
|
31
|
+
method.define_optional_argument('tz')
|
32
|
+
end
|
33
|
+
|
34
|
+
klass.define_method('duplicate') do |method|
|
35
|
+
method.define_argument('other')
|
36
|
+
end
|
37
|
+
|
38
|
+
klass.define_method('from_array') do |method|
|
39
|
+
method.define_argument('sec')
|
40
|
+
method.define_argument('min')
|
41
|
+
method.define_argument('hour')
|
42
|
+
method.define_argument('mday')
|
43
|
+
method.define_argument('month')
|
44
|
+
method.define_argument('year')
|
45
|
+
method.define_argument('nsec')
|
46
|
+
method.define_argument('is_dst')
|
47
|
+
method.define_argument('from_gmt')
|
48
|
+
method.define_argument('utc_offset')
|
49
|
+
end
|
50
|
+
|
51
|
+
klass.define_method('gm') do |method|
|
52
|
+
method.define_rest_argument('args')
|
53
|
+
end
|
54
|
+
|
55
|
+
klass.define_method('local') do |method|
|
56
|
+
method.define_rest_argument('args')
|
57
|
+
end
|
58
|
+
|
59
|
+
klass.define_method('mktime') do |method|
|
60
|
+
method.define_rest_argument('args')
|
61
|
+
end
|
62
|
+
|
63
|
+
klass.define_method('new') do |method|
|
64
|
+
method.define_optional_argument('year')
|
65
|
+
method.define_optional_argument('month')
|
66
|
+
method.define_optional_argument('day')
|
67
|
+
method.define_optional_argument('hour')
|
68
|
+
method.define_optional_argument('minute')
|
69
|
+
method.define_optional_argument('second')
|
70
|
+
method.define_optional_argument('utc_offset')
|
71
|
+
end
|
72
|
+
|
73
|
+
klass.define_method('now')
|
74
|
+
|
75
|
+
klass.define_method('specific') do |method|
|
76
|
+
method.define_argument('sec')
|
77
|
+
method.define_argument('nsec')
|
78
|
+
method.define_argument('from_gmt')
|
79
|
+
method.define_argument('offset')
|
80
|
+
end
|
81
|
+
|
82
|
+
klass.define_method('utc') do |method|
|
83
|
+
method.define_rest_argument('args')
|
84
|
+
end
|
85
|
+
|
86
|
+
klass.define_instance_method('+') do |method|
|
87
|
+
method.define_argument('other')
|
88
|
+
end
|
89
|
+
|
90
|
+
klass.define_instance_method('-') do |method|
|
91
|
+
method.define_argument('other')
|
92
|
+
end
|
93
|
+
|
94
|
+
klass.define_instance_method('<=>') do |method|
|
95
|
+
method.define_argument('other')
|
96
|
+
end
|
97
|
+
|
98
|
+
klass.define_instance_method('_dump') do |method|
|
99
|
+
method.define_optional_argument('limit')
|
100
|
+
end
|
101
|
+
|
102
|
+
klass.define_instance_method('asctime')
|
103
|
+
|
104
|
+
klass.define_instance_method('ctime')
|
105
|
+
|
106
|
+
klass.define_instance_method('day')
|
107
|
+
|
108
|
+
klass.define_instance_method('dst?')
|
109
|
+
|
110
|
+
klass.define_instance_method('dup')
|
111
|
+
|
112
|
+
klass.define_instance_method('eql?') do |method|
|
113
|
+
method.define_argument('other')
|
114
|
+
end
|
115
|
+
|
116
|
+
klass.define_instance_method('friday?')
|
117
|
+
|
118
|
+
klass.define_instance_method('getgm')
|
119
|
+
|
120
|
+
klass.define_instance_method('getlocal') do |method|
|
121
|
+
method.define_optional_argument('offset')
|
122
|
+
end
|
123
|
+
|
124
|
+
klass.define_instance_method('getutc')
|
125
|
+
|
126
|
+
klass.define_instance_method('gmt?')
|
127
|
+
|
128
|
+
klass.define_instance_method('gmt_offset')
|
129
|
+
|
130
|
+
klass.define_instance_method('gmtime')
|
131
|
+
|
132
|
+
klass.define_instance_method('gmtoff')
|
133
|
+
|
134
|
+
klass.define_instance_method('hash')
|
135
|
+
|
136
|
+
klass.define_instance_method('hour')
|
137
|
+
|
138
|
+
klass.define_instance_method('inspect')
|
139
|
+
|
140
|
+
klass.define_instance_method('isdst')
|
141
|
+
|
142
|
+
klass.define_instance_method('localtime') do |method|
|
143
|
+
method.define_optional_argument('offset')
|
144
|
+
end
|
145
|
+
|
146
|
+
klass.define_instance_method('mday')
|
147
|
+
|
148
|
+
klass.define_instance_method('min')
|
149
|
+
|
150
|
+
klass.define_instance_method('mon')
|
151
|
+
|
152
|
+
klass.define_instance_method('monday?')
|
153
|
+
|
154
|
+
klass.define_instance_method('month')
|
155
|
+
|
156
|
+
klass.define_instance_method('nsec')
|
157
|
+
|
158
|
+
klass.define_instance_method('rake_original_time_compare') do |method|
|
159
|
+
method.define_argument('other')
|
160
|
+
end
|
161
|
+
|
162
|
+
klass.define_instance_method('round') do |method|
|
163
|
+
method.define_optional_argument('places')
|
164
|
+
end
|
165
|
+
|
166
|
+
klass.define_instance_method('saturday?')
|
167
|
+
|
168
|
+
klass.define_instance_method('sec')
|
169
|
+
|
170
|
+
klass.define_instance_method('seconds')
|
171
|
+
|
172
|
+
klass.define_instance_method('strftime') do |method|
|
173
|
+
method.define_argument('format')
|
174
|
+
end
|
175
|
+
|
176
|
+
klass.define_instance_method('subsec')
|
177
|
+
|
178
|
+
klass.define_instance_method('succ')
|
179
|
+
|
180
|
+
klass.define_instance_method('sunday?')
|
181
|
+
|
182
|
+
klass.define_instance_method('thursday?')
|
183
|
+
|
184
|
+
klass.define_instance_method('to_a')
|
185
|
+
|
186
|
+
klass.define_instance_method('to_date')
|
187
|
+
|
188
|
+
klass.define_instance_method('to_datetime')
|
189
|
+
|
190
|
+
klass.define_instance_method('to_f')
|
191
|
+
|
192
|
+
klass.define_instance_method('to_i')
|
193
|
+
|
194
|
+
klass.define_instance_method('to_r')
|
195
|
+
|
196
|
+
klass.define_instance_method('to_s')
|
197
|
+
|
198
|
+
klass.define_instance_method('to_time')
|
199
|
+
|
200
|
+
klass.define_instance_method('tuesday?')
|
201
|
+
|
202
|
+
klass.define_instance_method('tv_nsec')
|
203
|
+
|
204
|
+
klass.define_instance_method('tv_sec')
|
205
|
+
|
206
|
+
klass.define_instance_method('tv_usec')
|
207
|
+
|
208
|
+
klass.define_instance_method('usec')
|
209
|
+
|
210
|
+
klass.define_instance_method('utc')
|
211
|
+
|
212
|
+
klass.define_instance_method('utc?')
|
213
|
+
|
214
|
+
klass.define_instance_method('utc_offset')
|
215
|
+
|
216
|
+
klass.define_instance_method('wday')
|
217
|
+
|
218
|
+
klass.define_instance_method('wednesday?')
|
219
|
+
|
220
|
+
klass.define_instance_method('yday')
|
221
|
+
|
222
|
+
klass.define_instance_method('year')
|
223
|
+
|
224
|
+
klass.define_instance_method('zone')
|
225
|
+
end
|
226
|
+
|
227
|
+
##
|
228
|
+
# Constant: Time::MonthValue
|
229
|
+
# Created: 2013-04-01 18:33:55 +0200
|
230
|
+
# Platform: rbx 2.0.0.rc1
|
231
|
+
#
|
232
|
+
RubyLint.global_scope.define_constant('Time::MonthValue') do |klass|
|
233
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
##
|
2
|
+
# Constant: TrueClass
|
3
|
+
# Created: 2013-04-01 18:33:55 +0200
|
4
|
+
# Platform: rbx 2.0.0.rc1
|
5
|
+
#
|
6
|
+
RubyLint.global_scope.define_constant('TrueClass') do |klass|
|
7
|
+
klass.inherits(RubyLint.global_constant('Object'))
|
8
|
+
|
9
|
+
klass.define_method('__class_init__')
|
10
|
+
|
11
|
+
klass.define_instance_method('&') do |method|
|
12
|
+
method.define_argument('other')
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.define_instance_method('^') do |method|
|
16
|
+
method.define_argument('other')
|
17
|
+
end
|
18
|
+
|
19
|
+
klass.define_instance_method('__marshal__') do |method|
|
20
|
+
method.define_argument('ms')
|
21
|
+
end
|
22
|
+
|
23
|
+
klass.define_instance_method('inspect')
|
24
|
+
|
25
|
+
klass.define_instance_method('to_s')
|
26
|
+
|
27
|
+
klass.define_instance_method('|') do |method|
|
28
|
+
method.define_argument('other')
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
##
|
2
|
+
# Constant: UnboundMethod
|
3
|
+
# Created: 2013-04-01 18:33:55 +0200
|
4
|
+
# Platform: rbx 2.0.0.rc1
|
5
|
+
#
|
6
|
+
RubyLint.global_scope.define_constant('UnboundMethod') do |klass|
|
7
|
+
klass.inherits(RubyLint.global_constant('Object'))
|
8
|
+
|
9
|
+
klass.define_method('__class_init__')
|
10
|
+
|
11
|
+
klass.define_instance_method('==') do |method|
|
12
|
+
method.define_argument('other')
|
13
|
+
end
|
14
|
+
|
15
|
+
klass.define_instance_method('arity')
|
16
|
+
|
17
|
+
klass.define_instance_method('bind') do |method|
|
18
|
+
method.define_argument('receiver')
|
19
|
+
end
|
20
|
+
|
21
|
+
klass.define_instance_method('call_on_instance') do |method|
|
22
|
+
method.define_argument('obj')
|
23
|
+
method.define_rest_argument('args')
|
24
|
+
method.define_block_argument('block')
|
25
|
+
end
|
26
|
+
|
27
|
+
klass.define_instance_method('defined_in')
|
28
|
+
|
29
|
+
klass.define_instance_method('executable')
|
30
|
+
|
31
|
+
klass.define_instance_method('hash')
|
32
|
+
|
33
|
+
klass.define_instance_method('initialize') do |method|
|
34
|
+
method.define_argument('mod')
|
35
|
+
method.define_argument('executable')
|
36
|
+
method.define_argument('pulled_from')
|
37
|
+
method.define_argument('name')
|
38
|
+
end
|
39
|
+
|
40
|
+
klass.define_instance_method('inspect')
|
41
|
+
|
42
|
+
klass.define_instance_method('name')
|
43
|
+
|
44
|
+
klass.define_instance_method('owner')
|
45
|
+
|
46
|
+
klass.define_instance_method('parameters')
|
47
|
+
|
48
|
+
klass.define_instance_method('source_location')
|
49
|
+
|
50
|
+
klass.define_instance_method('to_s')
|
51
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
##
|
2
|
+
# Constant: Unmarshalable
|
3
|
+
# Created: 2013-04-01 18:33:55 +0200
|
4
|
+
# Platform: rbx 2.0.0.rc1
|
5
|
+
#
|
6
|
+
RubyLint.global_scope.define_constant('Unmarshalable') do |klass|
|
7
|
+
|
8
|
+
klass.define_method('__module_init__')
|
9
|
+
|
10
|
+
klass.define_instance_method('__marshal__') do |method|
|
11
|
+
method.define_argument('ms')
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
##
|
2
|
+
# Constant: WeakRef
|
3
|
+
# Created: 2013-04-01 18:33:55 +0200
|
4
|
+
# Platform: rbx 2.0.0.rc1
|
5
|
+
#
|
6
|
+
RubyLint.global_scope.define_constant('WeakRef') do |klass|
|
7
|
+
klass.inherits(RubyLint.global_constant('BasicObject'))
|
8
|
+
|
9
|
+
klass.define_method('__class_init__')
|
10
|
+
|
11
|
+
klass.define_method('new')
|
12
|
+
|
13
|
+
klass.define_instance_method('__getobj__')
|
14
|
+
|
15
|
+
klass.define_instance_method('__object__')
|
16
|
+
|
17
|
+
klass.define_instance_method('__setobj__') do |method|
|
18
|
+
method.define_argument('obj')
|
19
|
+
end
|
20
|
+
|
21
|
+
klass.define_instance_method('method_missing') do |method|
|
22
|
+
method.define_argument('method')
|
23
|
+
method.define_rest_argument('args')
|
24
|
+
method.define_block_argument('block')
|
25
|
+
end
|
26
|
+
|
27
|
+
klass.define_instance_method('respond_to_missing?') do |method|
|
28
|
+
method.define_argument('method')
|
29
|
+
method.define_argument('include_private')
|
30
|
+
end
|
31
|
+
|
32
|
+
klass.define_instance_method('weakref_alive?')
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Constant: WeakRef::RefError
|
37
|
+
# Created: 2013-04-01 18:33:55 +0200
|
38
|
+
# Platform: rbx 2.0.0.rc1
|
39
|
+
#
|
40
|
+
RubyLint.global_scope.define_constant('WeakRef::RefError') do |klass|
|
41
|
+
klass.inherits(RubyLint.global_constant('RuntimeError'))
|
42
|
+
end
|
@@ -0,0 +1,692 @@
|
|
1
|
+
module RubyLint
|
2
|
+
##
|
3
|
+
# {RubyLint::DefinitionsBuilder} is a iterator class responsible for building
|
4
|
+
# a list of definitions. This approach means that individual iterator classes
|
5
|
+
# don't have to bother with this process and can instead focus on analyzing
|
6
|
+
# code.
|
7
|
+
#
|
8
|
+
class DefinitionsBuilder < Iterator
|
9
|
+
##
|
10
|
+
# Array of variable types that should be exported to the outer scope of a
|
11
|
+
# method definition.
|
12
|
+
#
|
13
|
+
# @return [Array]
|
14
|
+
#
|
15
|
+
EXPORT_VARIABLES = [:instance_variable, :class_variable, :constant]
|
16
|
+
|
17
|
+
##
|
18
|
+
# Hash containing the definition types to copy when including/extending a
|
19
|
+
# module.
|
20
|
+
#
|
21
|
+
# @return [Hash]
|
22
|
+
#
|
23
|
+
INCLUDE_CALLS = {
|
24
|
+
'include' => {
|
25
|
+
:constant => :constant,
|
26
|
+
:instance_method => :instance_method
|
27
|
+
},
|
28
|
+
'extend' => {
|
29
|
+
:constant => :constant,
|
30
|
+
:instance_method => :method
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
# Define the methods used for incrementing the amount of references to a
|
35
|
+
# variable.
|
36
|
+
[
|
37
|
+
:local_variable,
|
38
|
+
:global_variable,
|
39
|
+
:instance_variable,
|
40
|
+
:class_variable,
|
41
|
+
:constant,
|
42
|
+
:constant_path
|
43
|
+
].each do |type|
|
44
|
+
define_method("on_#{type}") do |node|
|
45
|
+
if node.constant_path?
|
46
|
+
variable = resolve_definitions(node.children)
|
47
|
+
else
|
48
|
+
variable = definitions.lookup(node.type, node.name)
|
49
|
+
end
|
50
|
+
|
51
|
+
increment_reference_amount(variable) if variable
|
52
|
+
|
53
|
+
enable_reference_counting
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Called at the root node of a Ruby script.
|
59
|
+
#
|
60
|
+
# @param [RubyLint::Node] node
|
61
|
+
#
|
62
|
+
def on_root(node)
|
63
|
+
@options[:node_definitions] = {}
|
64
|
+
@options[:definitions] = initial_definitions
|
65
|
+
|
66
|
+
enable_reference_counting
|
67
|
+
associate_node_definition(node, definitions)
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Creates a new module definition and updates the scope accordingly. If the
|
72
|
+
# module already exists the existing set of definitions is used instead of
|
73
|
+
# creating a new one.
|
74
|
+
#
|
75
|
+
# @param [RubyLint::Node] node
|
76
|
+
#
|
77
|
+
def on_module(node)
|
78
|
+
scope = definitions
|
79
|
+
mod_def = Definition::RubyObject.new_from_node(
|
80
|
+
node,
|
81
|
+
:value => nil,
|
82
|
+
:parents => [scope]
|
83
|
+
)
|
84
|
+
|
85
|
+
increment_reference_amount(mod_def)
|
86
|
+
|
87
|
+
if scope.has_definition?(:constant, mod_def.name)
|
88
|
+
existing = scope.lookup(:constant, mod_def.name)
|
89
|
+
|
90
|
+
if existing
|
91
|
+
@definitions << update_parent_definitions(existing, scope)
|
92
|
+
|
93
|
+
increment_reference_amount(existing)
|
94
|
+
associate_node_definition(node, existing)
|
95
|
+
|
96
|
+
return
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
define_module(node, mod_def)
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Changes the scope back to the outer scope of a module definition.
|
105
|
+
#
|
106
|
+
# @param [RubyLint::Node] node
|
107
|
+
#
|
108
|
+
def after_module(node)
|
109
|
+
@definitions.pop
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Creates a new class definition and updates the scope accordingly.
|
114
|
+
#
|
115
|
+
# @see RubyLint::DefinitionsBuilder#on_module
|
116
|
+
#
|
117
|
+
def on_class(node)
|
118
|
+
scope = definitions
|
119
|
+
parent = RubyLint.global_constant('Object')
|
120
|
+
|
121
|
+
# Resolve the definition of the parent class.
|
122
|
+
if node.children[1]
|
123
|
+
if node.children[1].constant_path?
|
124
|
+
parent = resolve_definitions(node.children[1].children)
|
125
|
+
else
|
126
|
+
parent = resolve_definitions([node.children[1]])
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class_def = Definition::RubyObject.new_from_node(
|
131
|
+
node,
|
132
|
+
:value => nil,
|
133
|
+
:parents => [parent, scope]
|
134
|
+
)
|
135
|
+
|
136
|
+
increment_reference_amount(class_def)
|
137
|
+
|
138
|
+
# Use an existing definition list if it exists.
|
139
|
+
if scope.has_definition?(:constant, class_def.name)
|
140
|
+
existing = scope.lookup(:constant, class_def.name)
|
141
|
+
|
142
|
+
if existing
|
143
|
+
@definitions << update_parent_definitions(existing, scope)
|
144
|
+
|
145
|
+
increment_reference_amount(existing)
|
146
|
+
associate_node_definition(node, existing)
|
147
|
+
|
148
|
+
return
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
define_module(node, class_def)
|
153
|
+
end
|
154
|
+
|
155
|
+
##
|
156
|
+
# Changes the scope back to the outer scope of the class definition.
|
157
|
+
#
|
158
|
+
# @param [RubyLint::Node] node
|
159
|
+
#
|
160
|
+
def after_class(node)
|
161
|
+
@definitions.pop
|
162
|
+
end
|
163
|
+
|
164
|
+
##
|
165
|
+
# Called when an sclass block is found. These blocks look like the
|
166
|
+
# following:
|
167
|
+
#
|
168
|
+
# class << self
|
169
|
+
# # ...
|
170
|
+
# end
|
171
|
+
#
|
172
|
+
# @param [RubyLint::Node] node
|
173
|
+
#
|
174
|
+
def on_sclass(node)
|
175
|
+
use = node.children[0]
|
176
|
+
found = definitions.lookup(use.type, use.name) || definitions
|
177
|
+
|
178
|
+
associate_node_definition(node, found)
|
179
|
+
|
180
|
+
@definitions << found
|
181
|
+
@call_types << :method
|
182
|
+
end
|
183
|
+
|
184
|
+
##
|
185
|
+
# Called after an sclass block has been processed.
|
186
|
+
#
|
187
|
+
# @param [RubyLint::Node] node
|
188
|
+
#
|
189
|
+
def after_sclass(node)
|
190
|
+
@definitions.pop
|
191
|
+
@call_types.pop
|
192
|
+
end
|
193
|
+
|
194
|
+
##
|
195
|
+
# Creates a new method definition. This definition is either added in the
|
196
|
+
# current scope or in the scope of the receiver in case one is specified.
|
197
|
+
# Any method arguments are automatically added as definitions to the inner
|
198
|
+
# scope.
|
199
|
+
#
|
200
|
+
# @param [RubyLint::Node] node
|
201
|
+
#
|
202
|
+
def on_method_definition(node)
|
203
|
+
scope = definitions
|
204
|
+
method = Definition::RubyMethod.new_from_node(
|
205
|
+
node,
|
206
|
+
:parents => [scope],
|
207
|
+
:method_type => call_type,
|
208
|
+
:instance_type => :instance
|
209
|
+
)
|
210
|
+
|
211
|
+
if method.receiver
|
212
|
+
existing = scope.lookup(method.receiver.type, method.receiver.name)
|
213
|
+
|
214
|
+
if existing
|
215
|
+
scope = method.receiver = existing
|
216
|
+
else
|
217
|
+
return
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
scope.add(method.method_type, method.name, method)
|
222
|
+
|
223
|
+
associate_node_definition(node, method)
|
224
|
+
|
225
|
+
@definitions << method
|
226
|
+
end
|
227
|
+
|
228
|
+
##
|
229
|
+
# Resets the scope to the outer scope and exports various variables into
|
230
|
+
# this scope.
|
231
|
+
#
|
232
|
+
# @param [RubyLint::Node] node
|
233
|
+
#
|
234
|
+
def after_method_definition(node)
|
235
|
+
method = @definitions.pop
|
236
|
+
|
237
|
+
# TODO: variables should only be exported when the method is actually
|
238
|
+
# called.
|
239
|
+
EXPORT_VARIABLES.each do |type|
|
240
|
+
method.definitions[type].each do |name, defs|
|
241
|
+
definitions.add(type, name, defs)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
##
|
247
|
+
# Creates definitions for variable assignments. When assigning a value to a
|
248
|
+
# constant path and a particular segment does not exist the entire
|
249
|
+
# assignment is skipped.
|
250
|
+
#
|
251
|
+
# @param [RubyLint::Node|Array] node
|
252
|
+
#
|
253
|
+
def on_assign(node)
|
254
|
+
variable, value = *node
|
255
|
+
assign_method = "on_#{variable.type}_assign"
|
256
|
+
|
257
|
+
# Deal with multiple variable assignments such as the following:
|
258
|
+
# first = second = third = 10
|
259
|
+
value = resolve_assignment_value(value)
|
260
|
+
|
261
|
+
if respond_to?(assign_method)
|
262
|
+
send(assign_method, variable, value)
|
263
|
+
else
|
264
|
+
assign_variable(definitions_for(variable), variable, value)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Don't count references for the variable that's being assigned.
|
268
|
+
disable_reference_counting
|
269
|
+
end
|
270
|
+
|
271
|
+
##
|
272
|
+
# @see RubyLint::DefinitionsBuilder#on_assign
|
273
|
+
#
|
274
|
+
def after_assign(node)
|
275
|
+
enable_reference_counting
|
276
|
+
end
|
277
|
+
|
278
|
+
##
|
279
|
+
# Processes conditional variable assignments.
|
280
|
+
#
|
281
|
+
# @see RubyLint::DefinitionsBuilder#on_assign
|
282
|
+
#
|
283
|
+
def on_op_assign(node)
|
284
|
+
type = node.children[0].type
|
285
|
+
name = node.children[0].children[0]
|
286
|
+
|
287
|
+
on_assign(node.children) unless definitions.lookup(type, name)
|
288
|
+
end
|
289
|
+
|
290
|
+
##
|
291
|
+
# Handles the assignments of constant paths.
|
292
|
+
#
|
293
|
+
# @param [RubyLint::Node] variable
|
294
|
+
# @param [RubyLint::Node] value
|
295
|
+
#
|
296
|
+
def on_constant_path_assign(variable, value)
|
297
|
+
scope = resolve_definitions(variable.children[0..-2])
|
298
|
+
last = variable.children[-1]
|
299
|
+
|
300
|
+
assign_variable(scope, last, value, last.type) if scope
|
301
|
+
end
|
302
|
+
|
303
|
+
##
|
304
|
+
# Handles the assignments of Array indexes, Hash keys and object members.
|
305
|
+
#
|
306
|
+
# @param [RubyLint::Node] variable
|
307
|
+
# @param [RubyLint::Node] values
|
308
|
+
#
|
309
|
+
def on_aref_assign(variable, values)
|
310
|
+
target = variable.children[0]
|
311
|
+
members = variable.gather_arguments(:argument)
|
312
|
+
scope = definitions.lookup(target.type, target.name)
|
313
|
+
|
314
|
+
return unless scope
|
315
|
+
|
316
|
+
members.each_with_index do |member, index|
|
317
|
+
member = resolve_variable(member) if member.variable?
|
318
|
+
|
319
|
+
next unless member
|
320
|
+
|
321
|
+
assign_variable(scope, member, values[index], :member)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
##
|
326
|
+
# Called when a value is assigned to an object member.
|
327
|
+
#
|
328
|
+
# @param [RubyLint::Node] variable
|
329
|
+
# @param [RubyLint::Node] value
|
330
|
+
#
|
331
|
+
def on_field_assign(variable, value)
|
332
|
+
object, member = *variable
|
333
|
+
object_def = definitions.lookup(object.type, object.name)
|
334
|
+
|
335
|
+
if object_def
|
336
|
+
assign_variable(object_def, member, value, :member)
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
##
|
341
|
+
# Processes the local variables created by `for` loops.
|
342
|
+
#
|
343
|
+
# @param [RubyLint::Node] node
|
344
|
+
#
|
345
|
+
def on_for(node)
|
346
|
+
scope = definitions
|
347
|
+
|
348
|
+
# The values are set to `nil` as the only reliable way of retrieving
|
349
|
+
# these is actual code evaluation.
|
350
|
+
node.children[0].each do |variable|
|
351
|
+
assign_variable(scope, variable, nil)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
##
|
356
|
+
# Creates a new scope for the block's body.
|
357
|
+
#
|
358
|
+
# @param [RubyLint::Node] node
|
359
|
+
#
|
360
|
+
def on_block(node)
|
361
|
+
scope = definitions
|
362
|
+
block = Definition::RubyObject.new_from_node(
|
363
|
+
node,
|
364
|
+
:name => 'block',
|
365
|
+
:parents => [scope],
|
366
|
+
:update_parents => [:local_variable]
|
367
|
+
)
|
368
|
+
|
369
|
+
node.each_argument do |arg|
|
370
|
+
variable = Definition::RubyObject.new_from_node(arg, :ignore => true)
|
371
|
+
|
372
|
+
block.add(arg.type, arg.name, variable)
|
373
|
+
end
|
374
|
+
|
375
|
+
# Ensure that local variables in the current scope are available inside
|
376
|
+
# the block.
|
377
|
+
scope.list(:local_variable).each do |variable|
|
378
|
+
block.add(variable.type, variable.name, variable)
|
379
|
+
end
|
380
|
+
|
381
|
+
associate_node_definition(node, block)
|
382
|
+
|
383
|
+
@definitions << block
|
384
|
+
end
|
385
|
+
|
386
|
+
##
|
387
|
+
# @param [RubyLint::Node] node
|
388
|
+
#
|
389
|
+
def after_block(node)
|
390
|
+
@definitions.pop
|
391
|
+
end
|
392
|
+
|
393
|
+
##
|
394
|
+
# Includes/extends a module when the `include` or `extend` method is
|
395
|
+
# called.
|
396
|
+
#
|
397
|
+
# @param [RubyLint::Node] node
|
398
|
+
#
|
399
|
+
def on_method(node)
|
400
|
+
return unless INCLUDE_CALLS.key?(node.children[0])
|
401
|
+
|
402
|
+
method_call = Definition::RubyMethod.new_from_node(node)
|
403
|
+
copy_types = INCLUDE_CALLS[method_call.name]
|
404
|
+
scope = definitions
|
405
|
+
|
406
|
+
method_call.arguments.each do |param|
|
407
|
+
if param.receiver
|
408
|
+
source = resolve_definitions(param.receiver_path)
|
409
|
+
else
|
410
|
+
source = scope.lookup(param.type, param.name)
|
411
|
+
end
|
412
|
+
|
413
|
+
if source.variable?
|
414
|
+
source = source.value
|
415
|
+
end
|
416
|
+
|
417
|
+
next unless source.is_a?(Definition::RubyObject)
|
418
|
+
|
419
|
+
copy_types.each do |from, to|
|
420
|
+
source.definitions[from].each do |name, definition|
|
421
|
+
scope.add(to, name, definition)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
private
|
428
|
+
|
429
|
+
##
|
430
|
+
# Assigns a value to the specified variable.
|
431
|
+
#
|
432
|
+
# @param [RubyLint::Definition::RubyObject] definition The definition
|
433
|
+
# list to add the variable to.
|
434
|
+
# @param [RubyLint::Node] variable The variable to create.
|
435
|
+
# @param [RubyLint::NOde] value The value of the variable.
|
436
|
+
# @param [NilClass|Symbol] type The type of variable to add, set to the
|
437
|
+
# type of `variable` by default.
|
438
|
+
#
|
439
|
+
def assign_variable(definition, variable, value, type = variable.type)
|
440
|
+
# Resolve variable values.
|
441
|
+
if value and (value.variable? or value.constant?)
|
442
|
+
found_value = resolve_variable(value)
|
443
|
+
value = found_value if found_value
|
444
|
+
end
|
445
|
+
|
446
|
+
if value and value.method?
|
447
|
+
value = resolve_return_value(value)
|
448
|
+
end
|
449
|
+
|
450
|
+
var_def = create_variable_definition(variable, value)
|
451
|
+
|
452
|
+
# Certain types (the core Ruby types in particular) should be turned into
|
453
|
+
# instances when used for assigning a variable.
|
454
|
+
if create_instance?(var_def)
|
455
|
+
val_def = RubyLint.global_constant(var_def.value.ruby_class)
|
456
|
+
|
457
|
+
var_def.value.instance!
|
458
|
+
|
459
|
+
var_def.value.parents << val_def.instance if val_def
|
460
|
+
end
|
461
|
+
|
462
|
+
if value and value.collection?
|
463
|
+
assign_collection_members(var_def, value)
|
464
|
+
end
|
465
|
+
|
466
|
+
definition.add(type, var_def.name, var_def)
|
467
|
+
end
|
468
|
+
|
469
|
+
##
|
470
|
+
# Assigns the indexes of the array to a definitions list.
|
471
|
+
#
|
472
|
+
# @param [RubyLint::Definition::RubyObject] definitions
|
473
|
+
# @param [Array] values
|
474
|
+
#
|
475
|
+
def assign_array_indexes(definitions, values)
|
476
|
+
values.each_with_index do |value, index|
|
477
|
+
assign_variable(
|
478
|
+
definitions,
|
479
|
+
Node.new(:integer, [index.to_s]),
|
480
|
+
value,
|
481
|
+
:member
|
482
|
+
)
|
483
|
+
end
|
484
|
+
end
|
485
|
+
|
486
|
+
##
|
487
|
+
# Assigns the key/value pairs of a hash to a definition list.
|
488
|
+
#
|
489
|
+
# @param [RubyLint::Definition::RubyObject] definitions
|
490
|
+
# @param [Array] values
|
491
|
+
#
|
492
|
+
def assign_hash_pairs(definitions, values)
|
493
|
+
values.each do |pair|
|
494
|
+
assign_variable(definitions, pair, pair.value, :member)
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
##
|
499
|
+
# Determines what method should be used for processing a collection's
|
500
|
+
# member values.
|
501
|
+
#
|
502
|
+
# @param [RubyLint::Definition::RubyObject] variable
|
503
|
+
# @param [RubyLint::Node] value
|
504
|
+
#
|
505
|
+
def assign_collection_members(variable, value)
|
506
|
+
if value.array?
|
507
|
+
assign_array_indexes(variable, value.value)
|
508
|
+
elsif value.hash?
|
509
|
+
assign_hash_pairs(variable, value.value)
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
##
|
514
|
+
# Adds a definition for the `self` keyword.
|
515
|
+
#
|
516
|
+
# @param [RubyLint::Definition::RubyObject] definition The definition
|
517
|
+
# list to add the keyword to.
|
518
|
+
#
|
519
|
+
def add_self(definition)
|
520
|
+
definition.add(:keyword, 'self', definition)
|
521
|
+
end
|
522
|
+
|
523
|
+
##
|
524
|
+
# Increments the reference amount of the specified definition.
|
525
|
+
#
|
526
|
+
# @param [RubyLint::Definition::RubyObject] definition
|
527
|
+
#
|
528
|
+
def increment_reference_amount(definition)
|
529
|
+
definition.reference_amount += 1 if @enable_reference_counting
|
530
|
+
end
|
531
|
+
|
532
|
+
##
|
533
|
+
# Enables reference counting of variables.
|
534
|
+
#
|
535
|
+
def enable_reference_counting
|
536
|
+
@enable_reference_counting = true
|
537
|
+
end
|
538
|
+
|
539
|
+
##
|
540
|
+
# Disables reference counting of variables.
|
541
|
+
#
|
542
|
+
def disable_reference_counting
|
543
|
+
@enable_reference_counting = false
|
544
|
+
end
|
545
|
+
|
546
|
+
##
|
547
|
+
# Creates a new {RubyLint::Definition::RubyObject} instance for a variable
|
548
|
+
# with an optional value.
|
549
|
+
#
|
550
|
+
# @param [RubyLint::Definition::RubyObject|RubyLint::Node] variable
|
551
|
+
# @param [RubyLint::Definition::RubyObject|RubyLint::Node] value
|
552
|
+
# @return [RubyLint::Definition::RubyObject]
|
553
|
+
#
|
554
|
+
def create_variable_definition(variable, value = nil)
|
555
|
+
if variable.is_a?(Node)
|
556
|
+
definition = Definition::RubyObject.new_from_node(
|
557
|
+
variable,
|
558
|
+
:value => value
|
559
|
+
)
|
560
|
+
else
|
561
|
+
definition = variable
|
562
|
+
definition.value = value
|
563
|
+
end
|
564
|
+
|
565
|
+
return definition
|
566
|
+
end
|
567
|
+
|
568
|
+
##
|
569
|
+
# Returns a boolean that indicates if the definition should be an instance
|
570
|
+
# of a Ruby value.
|
571
|
+
#
|
572
|
+
# @param [RubyLint::Definition::RubyObject] definition
|
573
|
+
# @return [TrueClass|FalseClass]
|
574
|
+
#
|
575
|
+
def create_instance?(definition)
|
576
|
+
val = definition.value
|
577
|
+
|
578
|
+
return val && val.ruby_class
|
579
|
+
end
|
580
|
+
|
581
|
+
##
|
582
|
+
# Resolves variables that point to other variables down to the original
|
583
|
+
# one.
|
584
|
+
#
|
585
|
+
# @param [RubyLint::Definition::RubyOject] variable
|
586
|
+
# @return [RubyLint::Definition::RubyObject|NilClass]
|
587
|
+
#
|
588
|
+
def resolve_variable(variable)
|
589
|
+
resolved = variable
|
590
|
+
|
591
|
+
if variable.variable? or variable.constant?
|
592
|
+
resolved = definitions.lookup(variable.type, variable.name)
|
593
|
+
|
594
|
+
if resolved and !resolved.constant?
|
595
|
+
resolved = resolved.value
|
596
|
+
elsif !resolved
|
597
|
+
resolved = nil
|
598
|
+
end
|
599
|
+
end
|
600
|
+
|
601
|
+
return resolved
|
602
|
+
end
|
603
|
+
|
604
|
+
##
|
605
|
+
# Resolves the return value of a method call.
|
606
|
+
#
|
607
|
+
# @param [RubyLint::Node] node
|
608
|
+
# @return [RubyLint::Definition::RubyObject|NilClass]
|
609
|
+
#
|
610
|
+
def resolve_return_value(node)
|
611
|
+
source = definitions
|
612
|
+
|
613
|
+
if node.receiver
|
614
|
+
if node.receiver.method?
|
615
|
+
source = resolve_return_value(node.receiver)
|
616
|
+
else
|
617
|
+
source = source.lookup(node.receiver.type, node.receiver.name)
|
618
|
+
end
|
619
|
+
end
|
620
|
+
|
621
|
+
return source ? source.call(node.name) : nil
|
622
|
+
end
|
623
|
+
|
624
|
+
##
|
625
|
+
# Extracts the end value used in multiple variable assignments in the form
|
626
|
+
# of `first = second = third = 10`.
|
627
|
+
#
|
628
|
+
# @param [RubyLint::Node|Array] node
|
629
|
+
# @return [RubyLint::Node]
|
630
|
+
#
|
631
|
+
def resolve_assignment_value(node)
|
632
|
+
if node.respond_to?(:type) and node.type == :assign
|
633
|
+
node = resolve_assignment_value(node.value)
|
634
|
+
end
|
635
|
+
|
636
|
+
return node
|
637
|
+
end
|
638
|
+
|
639
|
+
##
|
640
|
+
# @param [RubyLint::Node] node
|
641
|
+
# @return [RubyLint::Definition::RubyObject]
|
642
|
+
#
|
643
|
+
def definitions_for(node)
|
644
|
+
return node.global_variable? ? @options[:definitions] : definitions
|
645
|
+
end
|
646
|
+
|
647
|
+
##
|
648
|
+
# Updates the parent definitions of a given definition object.
|
649
|
+
#
|
650
|
+
# @param [RubyLint::Definition::RubyObject] existing
|
651
|
+
# @param [RubyLint::Definition::RubyObject] parent
|
652
|
+
# @return [RubyLint::Definition::RubyObject]
|
653
|
+
#
|
654
|
+
def update_parent_definitions(existing, parent)
|
655
|
+
existing.parents << parent unless existing.parents.include?(parent)
|
656
|
+
|
657
|
+
return existing
|
658
|
+
end
|
659
|
+
|
660
|
+
##
|
661
|
+
# Creates the required definitions for a new class or module.
|
662
|
+
#
|
663
|
+
# @param [RubyLint::Node] node
|
664
|
+
# @param [RubyLint::Definition::RubyObject] constant
|
665
|
+
#
|
666
|
+
def define_module(node, constant)
|
667
|
+
add_self(constant)
|
668
|
+
|
669
|
+
definitions.add(:constant, constant.name, constant)
|
670
|
+
|
671
|
+
associate_node_definition(node, constant)
|
672
|
+
|
673
|
+
@definitions << constant
|
674
|
+
end
|
675
|
+
|
676
|
+
##
|
677
|
+
# @return [RubyLint::Definition::RubyObject]
|
678
|
+
#
|
679
|
+
def initial_definitions
|
680
|
+
definitions = Definition::RubyObject.new(
|
681
|
+
:name => 'root',
|
682
|
+
:type => :root,
|
683
|
+
:parents => [RubyLint.global_constant('Kernel')],
|
684
|
+
:instance_type => :instance
|
685
|
+
)
|
686
|
+
|
687
|
+
definitions.merge(RubyLint.global_scope)
|
688
|
+
|
689
|
+
return definitions
|
690
|
+
end
|
691
|
+
end # DefinitionsBuilder
|
692
|
+
end # RubyLint
|