ruby-lint 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.asc +14 -14
- data/.gitignore +1 -2
- data/.rubocop.yml +59 -0
- data/.travis.yml +3 -7
- data/.yardopts +2 -2
- data/Gemfile +4 -0
- data/MANIFEST +103 -67
- data/README.md +13 -31
- data/Rakefile +1 -6
- data/checksum/ruby-lint-0.0.3.gem.sha512 +1 -0
- data/debug/memory_usage.rb +14 -0
- data/debug/profile.rb +18 -0
- data/doc/architecture.md +14 -18
- data/doc/changelog.md +29 -0
- data/doc/code_analysis.md +12 -12
- data/doc/configuration.md +21 -50
- data/doc/graphviz/flow.dot +1 -1
- data/doc/images/flow.png +0 -0
- data/lib/ruby-lint.rb +33 -19
- data/lib/ruby-lint/analysis/argument_amount.rb +84 -0
- data/lib/ruby-lint/analysis/base.rb +132 -0
- data/lib/ruby-lint/analysis/confusing_variables.rb +26 -0
- data/lib/ruby-lint/analysis/pedantics.rb +36 -0
- data/lib/ruby-lint/analysis/shadowing_variables.rb +47 -0
- data/lib/ruby-lint/analysis/undefined_methods.rb +91 -0
- data/lib/ruby-lint/analysis/undefined_variables.rb +46 -0
- data/lib/ruby-lint/analysis/unused_variables.rb +49 -0
- data/lib/ruby-lint/ast/builder.rb +17 -0
- data/lib/ruby-lint/ast/node.rb +39 -0
- data/lib/ruby-lint/cli.rb +0 -19
- data/lib/ruby-lint/cli/analyze.rb +54 -28
- data/lib/ruby-lint/cli/ast.rb +21 -6
- data/lib/ruby-lint/cli/base.rb +0 -23
- data/lib/ruby-lint/configuration.rb +112 -42
- data/lib/ruby-lint/constant_loader.rb +10 -28
- data/lib/ruby-lint/default_names.rb +19 -0
- data/lib/ruby-lint/definition/constant_proxy.rb +56 -0
- data/lib/ruby-lint/definition/ruby_method.rb +21 -143
- data/lib/ruby-lint/definition/ruby_object.rb +142 -246
- data/lib/ruby-lint/definition_builder/base.rb +43 -0
- data/lib/ruby-lint/definition_builder/primitive.rb +39 -0
- data/lib/ruby-lint/definition_builder/ruby_array.rb +77 -0
- data/lib/ruby-lint/definition_builder/ruby_block.rb +34 -0
- data/lib/ruby-lint/definition_builder/ruby_class.rb +24 -0
- data/lib/ruby-lint/definition_builder/ruby_hash.rb +37 -0
- data/lib/ruby-lint/definition_builder/ruby_method.rb +84 -0
- data/lib/ruby-lint/definition_builder/ruby_module.rb +68 -0
- data/lib/ruby-lint/definition_generator.rb +41 -15
- data/lib/ruby-lint/definitions/core/arg0.rb +1 -1
- data/lib/ruby-lint/definitions/core/argf.rb +1 -1
- data/lib/ruby-lint/definitions/core/argument_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/argv.rb +1 -1
- data/lib/ruby-lint/definitions/core/array.rb +6 -6
- data/lib/ruby-lint/definitions/core/autoload.rb +2 -2
- data/lib/ruby-lint/definitions/core/basic_object.rb +3 -3
- data/lib/ruby-lint/definitions/core/bignum.rb +2 -2
- data/lib/ruby-lint/definitions/core/binding.rb +2 -2
- data/lib/ruby-lint/definitions/core/class.rb +2 -2
- data/lib/ruby-lint/definitions/core/comparable.rb +1 -1
- data/lib/ruby-lint/definitions/core/complex.rb +4 -4
- data/lib/ruby-lint/definitions/core/condition_variable.rb +2 -2
- data/lib/ruby-lint/definitions/core/continuation.rb +2 -2
- data/lib/ruby-lint/definitions/core/data.rb +2 -2
- data/lib/ruby-lint/definitions/core/date.rb +34 -34
- data/lib/ruby-lint/definitions/core/date_time.rb +26 -26
- data/lib/ruby-lint/definitions/core/default_record_separator.rb +1 -1
- data/lib/ruby-lint/definitions/core/digest.rb +14 -14
- data/lib/ruby-lint/definitions/core/dir.rb +34 -34
- data/lib/ruby-lint/definitions/core/encoding.rb +237 -237
- data/lib/ruby-lint/definitions/core/encoding_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/enumerable.rb +15 -15
- data/lib/ruby-lint/definitions/core/enumerator.rb +2 -2
- data/lib/ruby-lint/definitions/core/env.rb +1 -1
- data/lib/ruby-lint/definitions/core/eoferror.rb +2 -2
- data/lib/ruby-lint/definitions/core/erb.rb +22 -22
- data/lib/ruby-lint/definitions/core/errno.rb +525 -525
- data/lib/ruby-lint/definitions/core/etc.rb +6 -6
- data/lib/ruby-lint/definitions/core/exception.rb +2 -2
- data/lib/ruby-lint/definitions/core/false.rb +1 -1
- data/lib/ruby-lint/definitions/core/false_class.rb +2 -2
- data/lib/ruby-lint/definitions/core/fatal_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/fiber.rb +2 -2
- data/lib/ruby-lint/definitions/core/fiber_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/file.rb +68 -68
- data/lib/ruby-lint/definitions/core/file_list.rb +2 -2
- data/lib/ruby-lint/definitions/core/file_test.rb +1 -1
- data/lib/ruby-lint/definitions/core/file_utils.rb +16 -16
- data/lib/ruby-lint/definitions/core/fixnum.rb +4 -4
- data/lib/ruby-lint/definitions/core/float.rb +16 -16
- data/lib/ruby-lint/definitions/core/float_domain_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/gc.rb +2 -2
- data/lib/ruby-lint/definitions/core/gem.rb +119 -119
- data/lib/ruby-lint/definitions/core/hash.rb +14 -14
- data/lib/ruby-lint/definitions/core/immediate_value.rb +1 -1
- data/lib/ruby-lint/definitions/core/index_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/integer.rb +2 -2
- data/lib/ruby-lint/definitions/core/interrupt.rb +2 -2
- data/lib/ruby-lint/definitions/core/io.rb +38 -38
- data/lib/ruby-lint/definitions/core/ioerror.rb +2 -2
- data/lib/ruby-lint/definitions/core/kernel.rb +3 -3
- data/lib/ruby-lint/definitions/core/key_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/load_error.rb +6 -6
- data/lib/ruby-lint/definitions/core/local_jump_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/main.rb +1 -1
- data/lib/ruby-lint/definitions/core/marshal.rb +35 -35
- data/lib/ruby-lint/definitions/core/match_data.rb +2 -2
- data/lib/ruby-lint/definitions/core/math.rb +7 -7
- data/lib/ruby-lint/definitions/core/memory_segmention_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/method.rb +2 -2
- data/lib/ruby-lint/definitions/core/module.rb +1 -1
- data/lib/ruby-lint/definitions/core/monitor.rb +4 -4
- data/lib/ruby-lint/definitions/core/monitor_mixin.rb +5 -5
- data/lib/ruby-lint/definitions/core/mutex.rb +2 -2
- data/lib/ruby-lint/definitions/core/name_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/nil.rb +1 -1
- data/lib/ruby-lint/definitions/core/nil_class.rb +2 -2
- data/lib/ruby-lint/definitions/core/no_memory_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/no_method_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/not_implemented_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/numeric.rb +2 -2
- data/lib/ruby-lint/definitions/core/object.rb +2 -2
- data/lib/ruby-lint/definitions/core/object_space.rb +1 -1
- data/lib/ruby-lint/definitions/core/open_struct.rb +3 -3
- data/lib/ruby-lint/definitions/core/option_parser.rb +83 -83
- data/lib/ruby-lint/definitions/core/precision.rb +1 -1
- data/lib/ruby-lint/definitions/core/primitive_failure.rb +2 -2
- data/lib/ruby-lint/definitions/core/proc.rb +2 -2
- data/lib/ruby-lint/definitions/core/process.rb +29 -29
- data/lib/ruby-lint/definitions/core/psych.rb +149 -149
- data/lib/ruby-lint/definitions/core/queue.rb +2 -2
- data/lib/ruby-lint/definitions/core/rake.rb +117 -117
- data/lib/ruby-lint/definitions/core/rake_file_utils.rb +1 -1
- data/lib/ruby-lint/definitions/core/rakeversion.rb +1 -1
- data/lib/ruby-lint/definitions/core/random.rb +2 -2
- data/lib/ruby-lint/definitions/core/range.rb +4 -4
- data/lib/ruby-lint/definitions/core/range_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/rational.rb +2 -2
- data/lib/ruby-lint/definitions/core/rb_config.rb +3 -3
- data/lib/ruby-lint/definitions/core/regexp.rb +28 -28
- data/lib/ruby-lint/definitions/core/regexp_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/rubinius.rb +1057 -1057
- data/lib/ruby-lint/definitions/core/ruby_copyright.rb +1 -1
- data/lib/ruby-lint/definitions/core/ruby_description.rb +1 -1
- data/lib/ruby-lint/definitions/core/ruby_engine.rb +1 -1
- data/lib/ruby-lint/definitions/core/ruby_lint.rb +9 -9
- data/lib/ruby-lint/definitions/core/ruby_patchlevel.rb +1 -1
- data/lib/ruby-lint/definitions/core/ruby_platform.rb +1 -1
- data/lib/ruby-lint/definitions/core/ruby_release_date.rb +1 -1
- data/lib/ruby-lint/definitions/core/ruby_version.rb +1 -1
- data/lib/ruby-lint/definitions/core/runtime_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/scan_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/script_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/security_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/shellwords.rb +1 -1
- data/lib/ruby-lint/definitions/core/signal.rb +3 -3
- data/lib/ruby-lint/definitions/core/signal_exception.rb +2 -2
- data/lib/ruby-lint/definitions/core/singleton.rb +2 -2
- data/lib/ruby-lint/definitions/core/sized_queue.rb +2 -2
- data/lib/ruby-lint/definitions/core/standard_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/stderr.rb +1 -1
- data/lib/ruby-lint/definitions/core/stdin.rb +1 -1
- data/lib/ruby-lint/definitions/core/stdout.rb +1 -1
- data/lib/ruby-lint/definitions/core/stop_iteration.rb +2 -2
- data/lib/ruby-lint/definitions/core/string.rb +21 -21
- data/lib/ruby-lint/definitions/core/string_io.rb +7 -7
- data/lib/ruby-lint/definitions/core/string_scanner.rb +4 -4
- data/lib/ruby-lint/definitions/core/struct.rb +20 -20
- data/lib/ruby-lint/definitions/core/syck.rb +4 -4
- data/lib/ruby-lint/definitions/core/symbol.rb +2 -2
- data/lib/ruby-lint/definitions/core/syntax_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/system_call_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/system_exit.rb +2 -2
- data/lib/ruby-lint/definitions/core/system_stack_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/thread.rb +6 -6
- data/lib/ruby-lint/definitions/core/thread_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/thread_group.rb +2 -2
- data/lib/ruby-lint/definitions/core/time.rb +3 -3
- data/lib/ruby-lint/definitions/core/toplevel_binding.rb +1 -1
- data/lib/ruby-lint/definitions/core/true.rb +1 -1
- data/lib/ruby-lint/definitions/core/true_class.rb +2 -2
- data/lib/ruby-lint/definitions/core/type_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/unbound_method.rb +2 -2
- data/lib/ruby-lint/definitions/core/unmarshalable.rb +1 -1
- data/lib/ruby-lint/definitions/core/unsupported_library_error.rb +2 -2
- data/lib/ruby-lint/definitions/core/weak_ref.rb +4 -4
- data/lib/ruby-lint/definitions/core/zero_division_error.rb +2 -2
- data/lib/ruby-lint/definitions/rails.rb +12 -0
- data/lib/ruby-lint/definitions/rails/abstract_controller.rb +335 -0
- data/lib/ruby-lint/definitions/rails/action_controller.rb +1244 -0
- data/lib/ruby-lint/definitions/rails/action_dispatch.rb +741 -0
- data/lib/ruby-lint/definitions/rails/action_mailer.rb +502 -0
- data/lib/ruby-lint/definitions/rails/action_pack.rb +16 -0
- data/lib/ruby-lint/definitions/rails/action_view.rb +898 -0
- data/lib/ruby-lint/definitions/rails/active_model.rb +437 -0
- data/lib/ruby-lint/definitions/rails/active_record.rb +2901 -0
- data/lib/ruby-lint/definitions/rails/active_support.rb +1963 -0
- data/lib/ruby-lint/definitions/rails/arel.rb +665 -0
- data/lib/ruby-lint/definitions/rails/rails.rb +452 -0
- data/lib/ruby-lint/definitions/rails/sprockets.rb +968 -0
- data/lib/ruby-lint/generated_constant.rb +33 -0
- data/lib/ruby-lint/helper/constant_paths.rb +30 -21
- data/lib/ruby-lint/inspector.rb +20 -2
- data/lib/ruby-lint/iterator.rb +11 -171
- data/lib/ruby-lint/nested_stack.rb +46 -0
- data/lib/ruby-lint/parser.rb +24 -806
- data/lib/ruby-lint/report.rb +2 -30
- data/lib/ruby-lint/report/entry.rb +2 -2
- data/lib/ruby-lint/runner.rb +81 -0
- data/lib/ruby-lint/template/definition.erb +12 -8
- data/lib/ruby-lint/variable_predicates.rb +16 -58
- data/lib/ruby-lint/version.rb +1 -1
- data/lib/ruby-lint/virtual_machine.rb +1044 -0
- data/ruby-lint.gemspec +17 -7
- data/spec/fixtures/complex/rails/basic_controller.rb +9 -0
- data/spec/fixtures/complex/rcap.rb +38 -0
- data/spec/fixtures/complex/slop.rb +680 -0
- data/spec/fixtures/config.yml +8 -0
- data/spec/fixtures/invalid.rb +3 -0
- data/spec/fixtures/invalid_2.rb +3 -0
- data/spec/fixtures/syntax_error.rb +1 -0
- data/spec/fixtures/valid.rb +3 -0
- data/spec/helper.rb +6 -0
- data/spec/ruby-lint/{analyze → analysis}/argument_amount.rb +7 -7
- data/spec/ruby-lint/analysis/confusing_variables.rb +46 -0
- data/spec/ruby-lint/analysis/pedantics.rb +43 -0
- data/spec/ruby-lint/{analyze → analysis}/shadowing_variables.rb +5 -5
- data/spec/ruby-lint/{analyze → analysis}/undefined_methods.rb +18 -18
- data/spec/ruby-lint/{analyze → analysis}/undefined_variables.rb +19 -25
- data/spec/ruby-lint/{analyze → analysis}/unused_variables.rb +29 -16
- data/spec/ruby-lint/ast/node.rb +33 -0
- data/spec/ruby-lint/cli/analyze.rb +31 -0
- data/spec/ruby-lint/cli/ast.rb +23 -0
- data/spec/ruby-lint/configuration.rb +45 -6
- data/spec/ruby-lint/definition/constant_proxy.rb +31 -0
- data/spec/ruby-lint/definition/dsl.rb +13 -20
- data/spec/ruby-lint/definition/ruby_method.rb +65 -148
- data/spec/ruby-lint/definition/ruby_object.rb +60 -96
- data/spec/ruby-lint/definition_builder/primitive.rb +62 -0
- data/spec/ruby-lint/definition_builder/ruby_class.rb +108 -0
- data/spec/ruby-lint/definition_builder/ruby_method.rb +53 -0
- data/spec/ruby-lint/definition_builder/ruby_module.rb +50 -0
- data/spec/ruby-lint/iterator.rb +40 -16
- data/spec/ruby-lint/nested_stack.rb +23 -0
- data/spec/ruby-lint/parser.rb +14 -0
- data/spec/ruby-lint/report.rb +0 -10
- data/spec/ruby-lint/report/entry.rb +8 -4
- data/spec/ruby-lint/runner.rb +32 -0
- data/spec/ruby-lint/virtual_machine/assignments/arrays.rb +87 -0
- data/spec/ruby-lint/virtual_machine/assignments/hashes.rb +52 -0
- data/spec/ruby-lint/virtual_machine/assignments/optional.rb +41 -0
- data/spec/ruby-lint/{definitions_builder → virtual_machine}/assignments/return_values.rb +11 -11
- data/spec/ruby-lint/virtual_machine/assignments/variables.rb +85 -0
- data/spec/ruby-lint/virtual_machine/associate_nodes.rb +17 -0
- data/spec/ruby-lint/virtual_machine/autoloading.rb +31 -0
- data/spec/ruby-lint/virtual_machine/blocks.rb +64 -0
- data/spec/ruby-lint/virtual_machine/classes/class_methods.rb +21 -0
- data/spec/ruby-lint/virtual_machine/classes/extending.rb +104 -0
- data/spec/ruby-lint/virtual_machine/classes/redefining.rb +24 -0
- data/spec/ruby-lint/virtual_machine/classes/sclass.rb +94 -0
- data/spec/ruby-lint/virtual_machine/classes/scoping.rb +60 -0
- data/spec/ruby-lint/virtual_machine/complex/rails.rb +18 -0
- data/spec/ruby-lint/virtual_machine/complex/rcap.rb +15 -0
- data/spec/ruby-lint/virtual_machine/complex/slop.rb +16 -0
- data/spec/ruby-lint/{definitions_builder → virtual_machine}/for.rb +2 -2
- data/spec/ruby-lint/virtual_machine/freeze.rb +13 -0
- data/spec/ruby-lint/virtual_machine/interpolation.rb +12 -0
- data/spec/ruby-lint/virtual_machine/methods/defining.rb +40 -0
- data/spec/ruby-lint/virtual_machine/methods/exporting.rb +19 -0
- data/spec/ruby-lint/virtual_machine/methods/parameters.rb +77 -0
- data/spec/ruby-lint/virtual_machine/methods/patching.rb +26 -0
- data/spec/ruby-lint/virtual_machine/methods/scoping.rb +63 -0
- data/spec/ruby-lint/virtual_machine/methods/visibility.rb +64 -0
- data/spec/ruby-lint/{definitions_builder → virtual_machine}/modules.rb +16 -16
- data/spec/ruby-lint/virtual_machine/reference_amount.rb +33 -0
- data/spec/ruby-lint/virtual_machine/unused.rb +17 -0
- data/spec/support/bacon.rb +13 -13
- data/spec/support/building.rb +23 -16
- data/spec/support/coveralls.rb +5 -0
- data/spec/support/fixtures.rb +20 -0
- data/spec/support/parsing.rb +3 -5
- data/spec/support/simplecov.rb +5 -3
- data/task/build.rake +1 -1
- data/task/cop.rake +11 -0
- data/task/generate.rake +40 -2
- data/task/profile.rake +27 -0
- data/task/todo.rake +6 -0
- data/task/travis.rake +7 -0
- metadata +160 -75
- metadata.gz.asc +14 -14
- data/doc/build/.gitkeep +0 -0
- data/lib/ruby-lint/analyze/argument_amount.rb +0 -73
- data/lib/ruby-lint/analyze/shadowing_variables.rb +0 -32
- data/lib/ruby-lint/analyze/undefined_methods.rb +0 -68
- data/lib/ruby-lint/analyze/undefined_variables.rb +0 -72
- data/lib/ruby-lint/analyze/unused_variables.rb +0 -48
- data/lib/ruby-lint/base.rb +0 -85
- data/lib/ruby-lint/definitions_builder.rb +0 -692
- data/lib/ruby-lint/helper/conversion.rb +0 -33
- data/lib/ruby-lint/helper/current_scope.rb +0 -98
- data/lib/ruby-lint/helper/methods.rb +0 -91
- data/lib/ruby-lint/node.rb +0 -107
- data/lib/ruby-lint/parser_error.rb +0 -30
- data/spec/ruby-lint/constant_loader.rb +0 -32
- data/spec/ruby-lint/definition/method_calls.rb +0 -26
- data/spec/ruby-lint/definitions_builder/assignments/arrays.rb +0 -71
- data/spec/ruby-lint/definitions_builder/assignments/hashes.rb +0 -65
- data/spec/ruby-lint/definitions_builder/assignments/objects.rb +0 -23
- data/spec/ruby-lint/definitions_builder/assignments/optional.rb +0 -22
- data/spec/ruby-lint/definitions_builder/assignments/variables.rb +0 -71
- data/spec/ruby-lint/definitions_builder/associate_nodes.rb +0 -17
- data/spec/ruby-lint/definitions_builder/blocks.rb +0 -40
- data/spec/ruby-lint/definitions_builder/classes.rb +0 -230
- data/spec/ruby-lint/definitions_builder/methods.rb +0 -147
- data/spec/ruby-lint/definitions_builder/reference_amount.rb +0 -31
- data/spec/ruby-lint/definitions_builder/unused.rb +0 -15
- data/spec/ruby-lint/node.rb +0 -38
- data/spec/ruby-lint/parser/assignments.rb +0 -225
- data/spec/ruby-lint/parser/classes.rb +0 -110
- data/spec/ruby-lint/parser/errors.rb +0 -12
- data/spec/ruby-lint/parser/metadata.rb +0 -17
- data/spec/ruby-lint/parser/method_definitions.rb +0 -111
- data/spec/ruby-lint/parser/methods.rb +0 -217
- data/spec/ruby-lint/parser/modules.rb +0 -70
- data/spec/ruby-lint/parser/operators.rb +0 -40
- data/spec/ruby-lint/parser/statements/begin.rb +0 -55
- data/spec/ruby-lint/parser/statements/case.rb +0 -34
- data/spec/ruby-lint/parser/statements/defined.rb +0 -11
- data/spec/ruby-lint/parser/statements/for.rb +0 -34
- data/spec/ruby-lint/parser/statements/if.rb +0 -46
- data/spec/ruby-lint/parser/statements/return.rb +0 -14
- data/spec/ruby-lint/parser/statements/super.rb +0 -49
- data/spec/ruby-lint/parser/statements/unless.rb +0 -42
- data/spec/ruby-lint/parser/statements/until.rb +0 -25
- data/spec/ruby-lint/parser/statements/while.rb +0 -25
- data/spec/ruby-lint/parser/statements/yield.rb +0 -18
- data/spec/ruby-lint/parser/types/arrays.rb +0 -47
- data/spec/ruby-lint/parser/types/booleans.rb +0 -11
- data/spec/ruby-lint/parser/types/constants.rb +0 -32
- data/spec/ruby-lint/parser/types/hashes.rb +0 -55
- data/spec/ruby-lint/parser/types/nil.rb +0 -7
- data/spec/ruby-lint/parser/types/numbers.rb +0 -11
- data/spec/ruby-lint/parser/types/procs.rb +0 -11
- data/spec/ruby-lint/parser/types/ranges.rb +0 -11
- data/spec/ruby-lint/parser/types/regexp.rb +0 -27
- data/spec/ruby-lint/parser/types/strings.rb +0 -44
- data/spec/ruby-lint/parser/types/symbols.rb +0 -15
- data/task/stdlib.rake +0 -23
@@ -0,0 +1,19 @@
|
|
1
|
+
RubyLint::Configuration.register_names 'analysis' do |names|
|
2
|
+
RubyLint::Analysis.constants.each do |const|
|
3
|
+
next if const == :Base
|
4
|
+
|
5
|
+
names[const.to_s.snake_case] = RubyLint::Analysis.const_get(const)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
RubyLint::Configuration.register_names 'presenters' do |names|
|
10
|
+
RubyLint::Presenter.constants.each do |const|
|
11
|
+
names[const.to_s.snake_case] = RubyLint::Presenter.const_get(const)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
RubyLint::Configuration.register_names 'levels' do |names|
|
16
|
+
RubyLint::Report::DEFAULT_LEVELS.each do |level|
|
17
|
+
names[level.to_s] = level
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module Definition
|
3
|
+
##
|
4
|
+
# {RubyLint::Definition::ConstantProxy} is a proxy class for constant
|
5
|
+
# definitions. The primary use case for this class is inheriting constants
|
6
|
+
# in the pre-generated definitions found in the definitions directory. By
|
7
|
+
# using this class when creating definitions the load order doesn't matter,
|
8
|
+
# as long as the data is there at some point in time.
|
9
|
+
#
|
10
|
+
# @!attribute [r] proxy_source
|
11
|
+
# @return [RubyLint::Definition::RubyObject]
|
12
|
+
#
|
13
|
+
# @!attribute [r] proxy_name
|
14
|
+
# @return [String]
|
15
|
+
#
|
16
|
+
# @!attribut [r] proxy_definition
|
17
|
+
# @return [RubyLint::Definition::RubyObject]
|
18
|
+
#
|
19
|
+
class ConstantProxy
|
20
|
+
attr_reader :proxy_source, :proxy_name, :proxy_definition
|
21
|
+
|
22
|
+
##
|
23
|
+
# @param [RubyLint::Definition::RubyObject] source The source definition
|
24
|
+
# to use for looking up the definition associated with the current
|
25
|
+
# proxy.
|
26
|
+
# @param [String] name The name/constant path of the constant that this
|
27
|
+
# proxy belongs to.
|
28
|
+
#
|
29
|
+
def initialize(source, name)
|
30
|
+
@proxy_source = source
|
31
|
+
@proxy_name = name
|
32
|
+
end
|
33
|
+
|
34
|
+
# Pre-define all the methods of the definition, this is faster than
|
35
|
+
# having to rely on method_missing.
|
36
|
+
RubyObject.instance_methods(false).each do |method|
|
37
|
+
define_method(method) do |*args, &block|
|
38
|
+
lookup_proxy_definition
|
39
|
+
|
40
|
+
proxy_definition.send(method, *args, &block) if proxy_definition
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
##
|
47
|
+
# Looks up the associated definition and stores it if it exists.
|
48
|
+
#
|
49
|
+
def lookup_proxy_definition
|
50
|
+
return if proxy_definition
|
51
|
+
|
52
|
+
@proxy_definition = proxy_source.lookup_constant_path(proxy_name)
|
53
|
+
end
|
54
|
+
end # ConstantProxy
|
55
|
+
end # Definition
|
56
|
+
end # RubyLint
|
@@ -21,119 +21,28 @@ module RubyLint
|
|
21
21
|
# @return [RubyLint::Definition::RubyObject] The rest argument of a
|
22
22
|
# method definition.
|
23
23
|
#
|
24
|
-
# @!attribute [r] more_arguments
|
25
|
-
# @return [Array] A set of "more" arguments of the method definition.
|
26
|
-
#
|
27
24
|
# @!attribute [r] block_argument
|
28
25
|
# @return [RubyLint::Definition::RubyObject] The block argument of a
|
29
26
|
# method definition.
|
30
27
|
#
|
31
|
-
# @!attribute [r] method_type
|
32
|
-
# @return [Symbol] The type of method definition, set to `:method` for
|
33
|
-
# class methods and `:instance_method` for instance methods.
|
34
|
-
#
|
35
28
|
# @!attribute [r] return_value
|
36
29
|
# @return [Mixed] The value that is returned by the method.
|
37
30
|
#
|
38
31
|
class RubyMethod < RubyObject
|
39
|
-
##
|
40
|
-
# Hash that contains the node types and attribute names to store the
|
41
|
-
# arguments in.
|
42
|
-
#
|
43
|
-
# @return [Hash]
|
44
|
-
#
|
45
|
-
ARGUMENT_TYPE_MAPPING = {
|
46
|
-
:argument => :arguments,
|
47
|
-
:optional_argument => :optional_arguments,
|
48
|
-
:rest_argument => :rest_argument,
|
49
|
-
:more_argument => :more_arguments,
|
50
|
-
:block_argument => :block_argument
|
51
|
-
}
|
52
|
-
|
53
32
|
attr_reader :block_argument,
|
54
33
|
:arguments,
|
55
|
-
:method_type,
|
56
|
-
:more_arguments,
|
57
34
|
:optional_arguments,
|
58
35
|
:rest_argument,
|
59
36
|
:return_value,
|
60
37
|
:visibility
|
61
38
|
|
62
39
|
##
|
63
|
-
#
|
64
|
-
#
|
65
|
-
def self.new_from_node(node, options = {})
|
66
|
-
options = default_method_options.merge(options)
|
67
|
-
options = options.merge(gather_arguments(node))
|
68
|
-
receiver = node.receiver
|
69
|
-
|
70
|
-
options[:method_type] ||= node.method_type
|
71
|
-
|
72
|
-
if receiver
|
73
|
-
options[:receiver] = RubyObject.new_from_node(receiver)
|
74
|
-
options[:method_type] = :method
|
75
|
-
end
|
76
|
-
|
77
|
-
return super(node, options)
|
78
|
-
end
|
79
|
-
|
80
|
-
##
|
81
|
-
# Returns a Hash containing all the arguments grouped together based on
|
82
|
-
# their types.
|
83
|
-
#
|
84
|
-
# @param [RubyLint::Node] node
|
85
|
-
# @return [Hash]
|
86
|
-
#
|
87
|
-
def self.gather_arguments(node)
|
88
|
-
arguments = default_arguments
|
89
|
-
|
90
|
-
ARGUMENT_TYPE_MAPPING.each do |from, to|
|
91
|
-
args = node.gather_arguments(from)
|
92
|
-
args = args.map { |n| RubyObject.new_from_node(n, :value => n.value) }
|
93
|
-
|
94
|
-
arguments[to] = arguments[to].is_a?(Array) ? args : args[0]
|
95
|
-
end
|
96
|
-
|
97
|
-
return arguments
|
98
|
-
end
|
99
|
-
|
100
|
-
##
|
101
|
-
# Returns the default Hash for a set of method arguments.
|
102
|
-
#
|
103
|
-
# @return [Hash]
|
104
|
-
#
|
105
|
-
def self.default_arguments
|
106
|
-
return {
|
107
|
-
:arguments => [],
|
108
|
-
:optional_arguments => [],
|
109
|
-
:rest_argument => nil,
|
110
|
-
:more_arguments => [],
|
111
|
-
:block_argument => nil
|
112
|
-
}
|
113
|
-
end
|
114
|
-
|
115
|
-
##
|
116
|
-
# Returns a Hash containing the default options for this class. The name
|
117
|
-
# is different than {RubyLint::Definition::RubyObject#default_options} to
|
118
|
-
# prevent any naming issues.
|
40
|
+
# Called after a new instance is created of this class. This method is
|
41
|
+
# called before calling any supplied blocks.
|
119
42
|
#
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
return {:method_type => :instance_method}
|
124
|
-
end
|
125
|
-
|
126
|
-
##
|
127
|
-
# @see RubyLint::Definition::RubyObject#initialize
|
128
|
-
#
|
129
|
-
def initialize(*args)
|
130
|
-
@arguments = []
|
131
|
-
@optional_arguments = []
|
132
|
-
@more_arguments = []
|
133
|
-
|
134
|
-
super
|
135
|
-
|
136
|
-
define_arguments unless method?
|
43
|
+
def after_initialize
|
44
|
+
@arguments ||= []
|
45
|
+
@optional_arguments ||= []
|
137
46
|
end
|
138
47
|
|
139
48
|
##
|
@@ -161,7 +70,7 @@ module RubyLint
|
|
161
70
|
# @param [String] name The name of the argument.
|
162
71
|
#
|
163
72
|
def define_argument(name)
|
164
|
-
@arguments <<
|
73
|
+
@arguments << create_argument(:arg, name)
|
165
74
|
end
|
166
75
|
|
167
76
|
##
|
@@ -170,7 +79,7 @@ module RubyLint
|
|
170
79
|
# @see RubyLint::Definition::RubyObject#define_argument
|
171
80
|
#
|
172
81
|
def define_optional_argument(name)
|
173
|
-
@optional_arguments <<
|
82
|
+
@optional_arguments << create_argument(:optarg, name)
|
174
83
|
end
|
175
84
|
|
176
85
|
##
|
@@ -179,16 +88,7 @@ module RubyLint
|
|
179
88
|
# @see RubyLint::Definition::RubyObject#define_argument
|
180
89
|
#
|
181
90
|
def define_rest_argument(name)
|
182
|
-
@rest_argument =
|
183
|
-
end
|
184
|
-
|
185
|
-
##
|
186
|
-
# Defines a more argument for the method.
|
187
|
-
#
|
188
|
-
# @see RubyLint::Definition::RubyObject#define_argument
|
189
|
-
#
|
190
|
-
def define_more_argument(name)
|
191
|
-
@more_arguments << create_variable(name)
|
91
|
+
@rest_argument = create_argument(:restarg, name)
|
192
92
|
end
|
193
93
|
|
194
94
|
##
|
@@ -197,51 +97,29 @@ module RubyLint
|
|
197
97
|
# @see RubyLint::Definition::RubyObject#define_argument
|
198
98
|
#
|
199
99
|
def define_block_argument(name)
|
200
|
-
@block_argument =
|
100
|
+
@block_argument = create_argument(:blockarg, name)
|
201
101
|
end
|
202
102
|
|
203
103
|
private
|
204
104
|
|
205
105
|
##
|
206
|
-
# Adds
|
106
|
+
# Adds a new argument to the method as well as adding it as a local
|
107
|
+
# variable. Note that although the argument's variable is saved under a
|
108
|
+
# argument key (e.g. `:arg`) the actual definition type is set to
|
109
|
+
# `:lvar`.
|
110
|
+
#
|
111
|
+
# @param [Symbol] type The type of argument.
|
112
|
+
# @param [String] name The name of the argument.
|
207
113
|
#
|
208
|
-
def define_arguments
|
209
|
-
all_arguments.each do |params|
|
210
|
-
next unless params
|
211
|
-
|
212
|
-
params.each do |param|
|
213
|
-
add(param.type, param.name, param) if param
|
214
|
-
end
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
##
|
219
|
-
# Returns an Array containing all the method arguments. Each arguments
|
220
|
-
# set (even single ones such as the more argument) is returned as an
|
221
|
-
# Array making it easier to iterate over the collection.
|
222
|
-
#
|
223
|
-
# @return [Array]
|
224
|
-
#
|
225
|
-
def all_arguments
|
226
|
-
return [
|
227
|
-
arguments,
|
228
|
-
optional_arguments,
|
229
|
-
[rest_argument],
|
230
|
-
more_arguments,
|
231
|
-
[block_argument]
|
232
|
-
]
|
233
|
-
end
|
234
|
-
|
235
|
-
##
|
236
|
-
# @param [String] name
|
237
114
|
# @return [RubyLint::Definition::RubyObject]
|
238
115
|
#
|
239
|
-
def
|
240
|
-
|
116
|
+
def create_argument(type, name)
|
117
|
+
argument = RubyObject.new(:type => :lvar, :name => name)
|
241
118
|
|
242
|
-
add(
|
119
|
+
add(argument.type, argument.name, argument)
|
120
|
+
add(type, argument.name, argument)
|
243
121
|
|
244
|
-
return
|
122
|
+
return argument
|
245
123
|
end
|
246
124
|
end # RubyMethod
|
247
125
|
end # Definition
|
@@ -16,14 +16,14 @@ module RubyLint
|
|
16
16
|
# Using the RubyObject class one could create a definition for the String
|
17
17
|
# class as following:
|
18
18
|
#
|
19
|
-
# string = RubyObject.new(:name => 'String', :type => :
|
19
|
+
# string = RubyObject.new(:name => 'String', :type => :const)
|
20
20
|
# newline = RubyObject.new(
|
21
21
|
# :name => 'NEWLINE',
|
22
|
-
# :type => :
|
22
|
+
# :type => :const,
|
23
23
|
# :value => "\n"
|
24
24
|
# )
|
25
25
|
#
|
26
|
-
# string.add(:
|
26
|
+
# string.add(:const, newline.name, newline)
|
27
27
|
#
|
28
28
|
# For more information see the documentation of the corresponding methods.
|
29
29
|
#
|
@@ -34,12 +34,7 @@ module RubyLint
|
|
34
34
|
# @return [Mixed] The value of the object.
|
35
35
|
#
|
36
36
|
# @!attribute [r] type
|
37
|
-
# @return [Symbol] The type of object, e.g. `:
|
38
|
-
#
|
39
|
-
# @!attribute [r] ignore
|
40
|
-
# @return [TrueClass|FalseClass] When set to `true` the definition should
|
41
|
-
# be ignored by any analysis related code. This is mostly used when no
|
42
|
-
# meaningful data could be assigned (e.g. block arguments).
|
37
|
+
# @return [Symbol] The type of object, e.g. `:const`.
|
43
38
|
#
|
44
39
|
# @!attribute [r] definitions
|
45
40
|
# @return [Hash] Hash containing all child the definitions.
|
@@ -47,10 +42,6 @@ module RubyLint
|
|
47
42
|
# @!attribute [rw] parents
|
48
43
|
# @return [Array] Array containing the parent definitions.
|
49
44
|
#
|
50
|
-
# @!attribute [rw] receiver
|
51
|
-
# @return [RubyLint::Definition::RubyObject] The receiver on which the
|
52
|
-
# object was defined/called.
|
53
|
-
#
|
54
45
|
# @!attribute [rw] reference_amount
|
55
46
|
# @return [Numeric] The amount of times an object was referenced.
|
56
47
|
# Currently this is only used for variables.
|
@@ -63,6 +54,11 @@ module RubyLint
|
|
63
54
|
# @return [Array] A list of data types to also add to the parent
|
64
55
|
# definitions when adding an object to the current one.
|
65
56
|
#
|
57
|
+
# @!attribute [r] members_as_value
|
58
|
+
# @return [TrueClass|FalseClass] When set to `true` the {#value} getter
|
59
|
+
# returns a collection of the members instead of the manually defined
|
60
|
+
# value.
|
61
|
+
#
|
66
62
|
class RubyObject
|
67
63
|
include VariablePredicates
|
68
64
|
|
@@ -73,101 +69,54 @@ module RubyLint
|
|
73
69
|
# @return [Array]
|
74
70
|
#
|
75
71
|
LOOKUP_PARENT = [
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
72
|
+
:const,
|
73
|
+
:cvar,
|
74
|
+
:gvar,
|
79
75
|
:instance_method,
|
80
|
-
:
|
76
|
+
:ivar,
|
81
77
|
:keyword,
|
82
78
|
:method
|
83
|
-
]
|
79
|
+
].freeze
|
84
80
|
|
85
81
|
##
|
86
82
|
# String used to separate segments in a constant path.
|
87
83
|
#
|
88
84
|
# @return [String]
|
89
85
|
#
|
90
|
-
PATH_SEPARATOR = '::'
|
91
|
-
|
92
|
-
attr_reader :update_parents,
|
93
|
-
:column,
|
94
|
-
:definitions,
|
95
|
-
:ignore,
|
96
|
-
:name,
|
97
|
-
:type,
|
98
|
-
:value
|
99
|
-
|
100
|
-
attr_accessor :instance_type,
|
101
|
-
:parents,
|
102
|
-
:receiver,
|
103
|
-
:reference_amount
|
86
|
+
PATH_SEPARATOR = '::'.freeze
|
104
87
|
|
105
88
|
##
|
106
|
-
#
|
107
|
-
# {RubyLint::Node}. This method is primarily used in
|
108
|
-
# {RubyLint::DefinitionsBuilder}, in most cases third-party code should
|
109
|
-
# not have a need for this method.
|
89
|
+
# Array containing the valid data types that can be stored.
|
110
90
|
#
|
111
|
-
# @
|
112
|
-
# @return [RubyLint::Definition::RubyObject]
|
91
|
+
# @return [Array<Symbol>]
|
113
92
|
#
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
if options[:value]
|
132
|
-
options[:value] = create_value_definitions(options[:value])
|
133
|
-
end
|
93
|
+
VALID_TYPES = [
|
94
|
+
:lvar,
|
95
|
+
:ivar,
|
96
|
+
:cvar,
|
97
|
+
:gvar,
|
98
|
+
:const,
|
99
|
+
:method,
|
100
|
+
:instance_method,
|
101
|
+
:member,
|
102
|
+
:keyword,
|
103
|
+
:arg,
|
104
|
+
:optarg,
|
105
|
+
:restarg,
|
106
|
+
:blockarg
|
107
|
+
].freeze
|
134
108
|
|
135
|
-
|
109
|
+
attr_reader :update_parents,
|
110
|
+
:definitions,
|
111
|
+
:members_as_value,
|
112
|
+
:name,
|
113
|
+
:type
|
136
114
|
|
137
|
-
|
138
|
-
#
|
139
|
-
# TODO: this approach doesn't take existing definitions into account,
|
140
|
-
# instead it will always create a new one for each segment.
|
141
|
-
if !path_segments.empty? and !options[:receiver]
|
142
|
-
path_segments.inject(object) do |source, segment|
|
143
|
-
source.receiver = new_from_node(segment)
|
144
|
-
source.receiver
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
return object
|
149
|
-
end
|
150
|
-
|
151
|
-
##
|
152
|
-
# Converts either a single {RubyLint::Node} instance or a collection of
|
153
|
-
# instances into {RubyObject} instances.
|
154
|
-
#
|
155
|
-
# @param [RubyLint::Node|Array<RubyLint::Node>] value
|
156
|
-
# @return [RubyLint::Node|Array<RubyLint::Node>]
|
157
|
-
#
|
158
|
-
def self.create_value_definitions(value)
|
159
|
-
if value.is_a?(Array)
|
160
|
-
value = value.map { |v| create_value_definitions(v) }
|
161
|
-
elsif value.is_a?(Node)
|
162
|
-
value = RubyObject.new_from_node(value)
|
163
|
-
end
|
164
|
-
|
165
|
-
return value
|
166
|
-
end
|
115
|
+
attr_accessor :instance_type, :parents, :reference_amount
|
167
116
|
|
168
117
|
##
|
169
118
|
# @example
|
170
|
-
# string = RubyObject.new(:name => 'String', :type => :
|
119
|
+
# string = RubyObject.new(:name => 'String', :type => :const)
|
171
120
|
#
|
172
121
|
# @param [Hash] options Hash containing additional options such as the
|
173
122
|
# parent definitions. For a list of available options see the
|
@@ -176,35 +125,61 @@ module RubyLint
|
|
176
125
|
# @yieldparam [RubyLint::Definition::RubyObject]
|
177
126
|
#
|
178
127
|
def initialize(options = {})
|
179
|
-
options = default_options.merge(options)
|
180
|
-
|
181
128
|
options.each do |key, value|
|
182
129
|
instance_variable_set("@#{key}", value)
|
183
130
|
end
|
184
131
|
|
185
|
-
|
132
|
+
@update_parents ||= []
|
133
|
+
@instance_type ||= :class
|
134
|
+
@parents ||= []
|
135
|
+
@reference_amount ||= 0
|
136
|
+
|
137
|
+
@definitions = Hash.new { |hash, key| hash[key] = {} }
|
138
|
+
@value = nil if members_as_value
|
139
|
+
|
140
|
+
after_initialize if respond_to?(:after_initialize)
|
186
141
|
|
187
142
|
yield self if block_given?
|
188
143
|
end
|
189
144
|
|
190
145
|
##
|
191
|
-
#
|
192
|
-
#
|
146
|
+
# Returns the value of the definition. If `members_as_value` is set to
|
147
|
+
# `true` the return value is a Hash containing the names and values of
|
148
|
+
# each member.
|
193
149
|
#
|
194
|
-
# @
|
150
|
+
# @return [Hash|RubyLint::Definition::RubyObject]
|
151
|
+
#
|
152
|
+
def value
|
153
|
+
return members_as_value ? list(:member) : @value
|
154
|
+
end
|
155
|
+
|
156
|
+
##
|
157
|
+
# Sets the value of the definition.
|
158
|
+
#
|
159
|
+
# @param [Mixed] value
|
195
160
|
#
|
196
161
|
def value=(value)
|
197
|
-
@value = value
|
162
|
+
@value = value
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Adds the definition object to the current one.
|
167
|
+
#
|
168
|
+
# @see #add
|
169
|
+
# @param [RubyLint::Definition::RubyObject] definition
|
170
|
+
#
|
171
|
+
def add_definition(definition)
|
172
|
+
add(definition.type, definition.name, definition)
|
198
173
|
end
|
199
174
|
|
200
175
|
##
|
201
176
|
# Adds a new definition to the definitions list.
|
202
177
|
#
|
203
178
|
# @example
|
204
|
-
# string = RubyObject.new(:name => 'String', :type => :
|
179
|
+
# string = RubyObject.new(:name => 'String', :type => :const)
|
205
180
|
# newline = RubyObject.new(
|
206
181
|
# :name => 'NEWLINE',
|
207
|
-
# :type => :
|
182
|
+
# :type => :const,
|
208
183
|
# :value => "\n"
|
209
184
|
# )
|
210
185
|
#
|
@@ -220,13 +195,13 @@ module RubyLint
|
|
220
195
|
# @raise [ArgumentError] Raised when the specified type was invalid.
|
221
196
|
#
|
222
197
|
def add(type, name, value)
|
223
|
-
type =
|
198
|
+
type = type.to_sym
|
224
199
|
|
225
200
|
unless value.is_a?(RubyObject)
|
226
201
|
raise TypeError, "Expected RubyObject but got #{value.class}"
|
227
202
|
end
|
228
203
|
|
229
|
-
unless
|
204
|
+
unless VALID_TYPES.include?(type)
|
230
205
|
raise ArgumentError, ":#{type} is not a valid type of data to add"
|
231
206
|
end
|
232
207
|
|
@@ -244,22 +219,24 @@ module RubyLint
|
|
244
219
|
# If no definition was found `nil` will be returned.
|
245
220
|
#
|
246
221
|
# @example
|
247
|
-
# string = RubyObject.new(:name => 'String', :type => :
|
222
|
+
# string = RubyObject.new(:name => 'String', :type => :const)
|
248
223
|
# newline = RubyObject.new(
|
249
224
|
# :name => 'NEWLINE',
|
250
|
-
# :type => :
|
225
|
+
# :type => :const,
|
251
226
|
# :value => "\n"
|
252
227
|
# )
|
253
228
|
#
|
254
229
|
# string.add(newline.type, newline.name, newline)
|
255
230
|
#
|
256
|
-
# string.lookup(:
|
231
|
+
# string.lookup(:const, 'NEWLINE') # => #<RubyLint::Definition...>
|
257
232
|
#
|
258
233
|
# @param [#to_sym] type
|
259
234
|
# @param [String] name
|
235
|
+
# @param [TrueClass|FalseClass] lookup_parent Whether definitions should
|
236
|
+
# be looked up from parent definitions.
|
260
237
|
# @return [RubyLint::Definition::RubyObject|NilClass]
|
261
238
|
#
|
262
|
-
def lookup(type, name)
|
239
|
+
def lookup(type, name, lookup_parent = true)
|
263
240
|
type, name = prepare_lookup(type, name)
|
264
241
|
found = nil
|
265
242
|
|
@@ -267,7 +244,7 @@ module RubyLint
|
|
267
244
|
found = definitions[type][name]
|
268
245
|
|
269
246
|
# Look up the definition in the parent scope(s) (if any are set).
|
270
|
-
elsif lookup_parent?(type)
|
247
|
+
elsif lookup_parent?(type) and lookup_parent
|
271
248
|
parents.each do |parent|
|
272
249
|
parent_definition = parent.lookup(type, name)
|
273
250
|
|
@@ -282,61 +259,71 @@ module RubyLint
|
|
282
259
|
end
|
283
260
|
|
284
261
|
##
|
285
|
-
# Returns the definition for the given constant path.
|
286
|
-
# segments does not exist an error is raised instead.
|
262
|
+
# Returns the definition for the given constant path.
|
287
263
|
#
|
288
264
|
# @example
|
289
265
|
# example.lookup_constant_path('A::B') # => #<RubyLint::Definition...>
|
290
266
|
#
|
291
267
|
# @param [String|Array<String>] path
|
292
268
|
# @return [RubyLint::Definition::RubyObject]
|
293
|
-
# @raise [ArgumentError] Raised when an invalid constant path is
|
294
|
-
# specified.
|
295
269
|
#
|
296
270
|
def lookup_constant_path(path)
|
297
271
|
constant = self
|
298
272
|
path = path.split(PATH_SEPARATOR) if path.is_a?(String)
|
299
273
|
|
300
274
|
path.each do |segment|
|
301
|
-
found = constant.lookup(:
|
302
|
-
|
303
|
-
if found
|
304
|
-
constant = found
|
305
|
-
else
|
306
|
-
name = path.join(PATH_SEPARATOR)
|
275
|
+
found = constant.lookup(:const, segment)
|
307
276
|
|
308
|
-
|
309
|
-
end
|
277
|
+
found ? constant = found : return
|
310
278
|
end
|
311
279
|
|
312
280
|
return constant
|
313
281
|
end
|
314
282
|
|
315
283
|
##
|
316
|
-
# Mimics a method call
|
317
|
-
#
|
284
|
+
# Mimics a method call by executing the method for the given name. This
|
285
|
+
# method should be defined in the current definition.
|
286
|
+
#
|
287
|
+
# @param [String] name The name of the method.
|
288
|
+
# @return [Mixed]
|
289
|
+
#
|
290
|
+
def call_method(name)
|
291
|
+
method = lookup(method_call_type, name)
|
292
|
+
|
293
|
+
unless method
|
294
|
+
raise NoMethodError, "Undefined method #{name} for #{self.inspect}"
|
295
|
+
end
|
296
|
+
|
297
|
+
return method.call(self)
|
298
|
+
end
|
299
|
+
|
300
|
+
##
|
301
|
+
# Returns `true` if a method is defined, similar to `respond_to?`.
|
302
|
+
#
|
303
|
+
# @return [TrueClass|FalseClass]
|
304
|
+
#
|
305
|
+
def method_defined?(name)
|
306
|
+
return has_definition?(method_call_type, name)
|
307
|
+
end
|
308
|
+
|
309
|
+
##
|
310
|
+
# Performs a method call on the current definition.
|
318
311
|
#
|
319
312
|
# If the return value of a method definition is set to a Proc (or any
|
320
313
|
# other object that responds to `:call`) it will be called and passed the
|
321
314
|
# current instance as an argument.
|
322
315
|
#
|
323
|
-
#
|
324
|
-
#
|
316
|
+
# TODO: add support for specifying method arguments.
|
317
|
+
#
|
318
|
+
# @param [RubyLint::Definition::RubyObject] context The context in which
|
319
|
+
# the method was called.
|
325
320
|
# @return [Mixed]
|
326
321
|
#
|
327
|
-
def call(
|
328
|
-
|
329
|
-
|
322
|
+
def call(context = self)
|
323
|
+
retval = return_value
|
324
|
+
retval = retval.call(context) if retval.respond_to?(:call)
|
330
325
|
|
331
|
-
|
332
|
-
return_value = method.return_value
|
333
|
-
|
334
|
-
if return_value.respond_to?(:call)
|
335
|
-
return_value = return_value.call(self)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
return return_value
|
326
|
+
return retval
|
340
327
|
end
|
341
328
|
|
342
329
|
##
|
@@ -388,14 +375,6 @@ module RubyLint
|
|
388
375
|
return instance_type == :instance
|
389
376
|
end
|
390
377
|
|
391
|
-
##
|
392
|
-
# Updates the definition object so that it represents an instance of a
|
393
|
-
# Ruby value.
|
394
|
-
#
|
395
|
-
def instance!
|
396
|
-
@instance_type = :instance
|
397
|
-
end
|
398
|
-
|
399
378
|
##
|
400
379
|
# Checks if the specified definition is defined in the current object,
|
401
380
|
# ignoring data in any parent definitions.
|
@@ -420,36 +399,17 @@ module RubyLint
|
|
420
399
|
# @return [Array]
|
421
400
|
#
|
422
401
|
def list(type)
|
423
|
-
return definitions[
|
402
|
+
return definitions[type.to_sym].values
|
424
403
|
end
|
425
404
|
|
426
405
|
##
|
427
|
-
# Returns the
|
406
|
+
# Returns the amount of definitions stored for a given type.
|
428
407
|
#
|
429
|
-
# @param [#to_sym]
|
408
|
+
# @param [#to_sym] type
|
430
409
|
# @return [Numeric]
|
431
410
|
#
|
432
|
-
def
|
433
|
-
|
434
|
-
|
435
|
-
return value ? value.length : 0
|
436
|
-
end
|
437
|
-
|
438
|
-
##
|
439
|
-
# Resets the list of definitions for the current RubyObject instance.
|
440
|
-
#
|
441
|
-
def clear!
|
442
|
-
@definitions = {
|
443
|
-
:local_variable => {},
|
444
|
-
:instance_variable => {},
|
445
|
-
:class_variable => {},
|
446
|
-
:global_variable => {},
|
447
|
-
:constant => {},
|
448
|
-
:method => {},
|
449
|
-
:instance_method => {},
|
450
|
-
:member => {},
|
451
|
-
:keyword => {}
|
452
|
-
}
|
411
|
+
def amount(type)
|
412
|
+
return list(type).length
|
453
413
|
end
|
454
414
|
|
455
415
|
##
|
@@ -481,31 +441,6 @@ module RubyLint
|
|
481
441
|
end
|
482
442
|
end
|
483
443
|
|
484
|
-
##
|
485
|
-
# Returns an Array containing all the receivers of the current
|
486
|
-
# definition. These receivers are sorted from left to right. For example,
|
487
|
-
# assume the following:
|
488
|
-
#
|
489
|
-
# a.b.c
|
490
|
-
#
|
491
|
-
# In this case the return value would be as following:
|
492
|
-
#
|
493
|
-
# [a, b, c]
|
494
|
-
#
|
495
|
-
# @return [Array]
|
496
|
-
#
|
497
|
-
def receiver_path
|
498
|
-
receivers = []
|
499
|
-
source = self
|
500
|
-
|
501
|
-
while receiver = source.receiver
|
502
|
-
receivers << receiver
|
503
|
-
source = receiver
|
504
|
-
end
|
505
|
-
|
506
|
-
return receivers << self
|
507
|
-
end
|
508
|
-
|
509
444
|
##
|
510
445
|
# Creates a new definition object based on the current one that
|
511
446
|
# represents an instance of a Ruby value (instead of a class).
|
@@ -531,7 +466,7 @@ module RubyLint
|
|
531
466
|
# @return [TrueClass|FalseClass]
|
532
467
|
#
|
533
468
|
def used?
|
534
|
-
return
|
469
|
+
return reference_amount > 0
|
535
470
|
end
|
536
471
|
|
537
472
|
##
|
@@ -549,9 +484,11 @@ module RubyLint
|
|
549
484
|
target = lookup_constant_path(path[0..-2])
|
550
485
|
definition = target.define_constant(path[-1], &block)
|
551
486
|
else
|
552
|
-
definition = add_child_definition(
|
487
|
+
definition = add_child_definition(:const, name, &block)
|
553
488
|
end
|
554
489
|
|
490
|
+
definition.add(:keyword, 'self', definition)
|
491
|
+
|
555
492
|
return definition
|
556
493
|
end
|
557
494
|
|
@@ -565,7 +502,7 @@ module RubyLint
|
|
565
502
|
# @param [Mixed] value
|
566
503
|
#
|
567
504
|
def define_global_variable(name, value = nil)
|
568
|
-
return add_child_definition(
|
505
|
+
return add_child_definition(:gvar, name, value)
|
569
506
|
end
|
570
507
|
|
571
508
|
##
|
@@ -578,7 +515,7 @@ module RubyLint
|
|
578
515
|
# @return [RubyLint::Definition::RubyMethod]
|
579
516
|
#
|
580
517
|
def define_method(name, &block)
|
581
|
-
return add_child_method(
|
518
|
+
return add_child_method(:method, name, &block)
|
582
519
|
end
|
583
520
|
|
584
521
|
##
|
@@ -590,7 +527,7 @@ module RubyLint
|
|
590
527
|
# @see RubyLint::Definition::RubyObject#define_method
|
591
528
|
#
|
592
529
|
def define_instance_method(name, &block)
|
593
|
-
return add_child_method(
|
530
|
+
return add_child_method(:instance_method, name, &block)
|
594
531
|
end
|
595
532
|
|
596
533
|
##
|
@@ -614,7 +551,7 @@ module RubyLint
|
|
614
551
|
# @param [Array] definitions
|
615
552
|
#
|
616
553
|
def inherits(*definitions)
|
617
|
-
self.parents
|
554
|
+
self.parents.concat(definitions)
|
618
555
|
end
|
619
556
|
|
620
557
|
##
|
@@ -653,12 +590,12 @@ module RubyLint
|
|
653
590
|
##
|
654
591
|
# Adds a new child definition to the current definition.
|
655
592
|
#
|
656
|
-
# @param [String] name The name of the definition.
|
657
593
|
# @param [Symbol] type The definition type.
|
594
|
+
# @param [String] name The name of the definition.
|
658
595
|
# @param [Mixed] value
|
659
596
|
# @return [RubyLint::Definition::RubyObject]
|
660
597
|
#
|
661
|
-
def add_child_definition(
|
598
|
+
def add_child_definition(type, name, value = nil, &block)
|
662
599
|
definition = self.class.new(
|
663
600
|
:name => name,
|
664
601
|
:type => type,
|
@@ -677,16 +614,15 @@ module RubyLint
|
|
677
614
|
#
|
678
615
|
# @see RubyLint::Definition::RubyObject#add_child_definition
|
679
616
|
#
|
680
|
-
def add_child_method(
|
617
|
+
def add_child_method(type, name, &block)
|
681
618
|
definition = RubyMethod.new(
|
682
|
-
:name
|
683
|
-
:type
|
684
|
-
:
|
685
|
-
:parents => [self],
|
619
|
+
:name => name,
|
620
|
+
:type => type,
|
621
|
+
:parents => [self],
|
686
622
|
&block
|
687
623
|
)
|
688
624
|
|
689
|
-
add(definition.
|
625
|
+
add(definition.type, definition.name, definition)
|
690
626
|
|
691
627
|
return definition
|
692
628
|
end
|
@@ -702,22 +638,6 @@ module RubyLint
|
|
702
638
|
return LOOKUP_PARENT.include?(type) && !parents.empty?
|
703
639
|
end
|
704
640
|
|
705
|
-
##
|
706
|
-
# Returns a Hash containing the default options.
|
707
|
-
#
|
708
|
-
# @return [Hash]
|
709
|
-
#
|
710
|
-
def default_options
|
711
|
-
return {
|
712
|
-
:update_parents => [],
|
713
|
-
:instance_type => :class,
|
714
|
-
:parents => [],
|
715
|
-
:receiver => nil,
|
716
|
-
:reference_amount => 0,
|
717
|
-
:value => nil
|
718
|
-
}
|
719
|
-
end
|
720
|
-
|
721
641
|
##
|
722
642
|
# Casts the type and name of data to look up to the correct values.
|
723
643
|
#
|
@@ -726,31 +646,7 @@ module RubyLint
|
|
726
646
|
# @return [Array]
|
727
647
|
#
|
728
648
|
def prepare_lookup(type, name)
|
729
|
-
return
|
730
|
-
end
|
731
|
-
|
732
|
-
##
|
733
|
-
# Prepares the name of a definition.
|
734
|
-
#
|
735
|
-
# @param [#to_s] name
|
736
|
-
# @return [String]
|
737
|
-
#
|
738
|
-
def prepare_name(name)
|
739
|
-
name = name.to_s unless name.is_a?(String)
|
740
|
-
|
741
|
-
return name
|
742
|
-
end
|
743
|
-
|
744
|
-
##
|
745
|
-
# Prepares the data type name.
|
746
|
-
#
|
747
|
-
# @param [#to_sym] type
|
748
|
-
# @return [Symbol]
|
749
|
-
#
|
750
|
-
def prepare_type(type)
|
751
|
-
type = type.to_sym unless type.is_a?(Symbol)
|
752
|
-
|
753
|
-
return type
|
649
|
+
return type.to_sym, name.to_s
|
754
650
|
end
|
755
651
|
end # RubyObject
|
756
652
|
end # Definition
|