ruby-lint 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.asc +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
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Analyze
|
|
3
|
-
##
|
|
4
|
-
# The ShadowingVariables class checks for the use of variables in a block
|
|
5
|
-
# that shadow outer variables. "Shadowing" means that a variable is used
|
|
6
|
-
# with the same name as a variable in the surrounding scope. A simple
|
|
7
|
-
# example:
|
|
8
|
-
#
|
|
9
|
-
# number = 10
|
|
10
|
-
#
|
|
11
|
-
# [10, 20, 30].each do |number|
|
|
12
|
-
# puts number # `number` is being shadowed
|
|
13
|
-
# end
|
|
14
|
-
#
|
|
15
|
-
class ShadowingVariables < Iterator
|
|
16
|
-
include Helper::CurrentScope
|
|
17
|
-
|
|
18
|
-
##
|
|
19
|
-
# @param [RubyLint::Node] node
|
|
20
|
-
#
|
|
21
|
-
def on_block(node)
|
|
22
|
-
node.each_argument do |param|
|
|
23
|
-
if current_scope.has_definition?(param.type, param.name)
|
|
24
|
-
warning("shadowing outer local variable #{param.name}", param)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
super
|
|
29
|
-
end
|
|
30
|
-
end # ShadowingVariables
|
|
31
|
-
end # Analyze
|
|
32
|
-
end # RubyLint
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Analyze
|
|
3
|
-
##
|
|
4
|
-
# The UndefinedMethods class checks for the use of undefined methods/local
|
|
5
|
-
# variables and adds errors whenever needed. Based on the receiver of a
|
|
6
|
-
# method call the corresponding error message differs to make it easier to
|
|
7
|
-
# understand what is going on.
|
|
8
|
-
#
|
|
9
|
-
# A simple example:
|
|
10
|
-
#
|
|
11
|
-
# foobar # => undefined method foobar
|
|
12
|
-
# 'test'.foobar # => undefined method foobar on an instance of String
|
|
13
|
-
#
|
|
14
|
-
class UndefinedMethods < Iterator
|
|
15
|
-
include Helper::Methods
|
|
16
|
-
|
|
17
|
-
##
|
|
18
|
-
# @param [RubyLint::Node] node
|
|
19
|
-
#
|
|
20
|
-
def on_method(node)
|
|
21
|
-
# Don't add errors for non existing receivers as these are handled by
|
|
22
|
-
# classes such as UndefinedVariables.
|
|
23
|
-
return if invalid_receiver?(node)
|
|
24
|
-
|
|
25
|
-
valid = method_defined?(node)
|
|
26
|
-
error = "undefined method #{node.name}"
|
|
27
|
-
|
|
28
|
-
# Methods called on block variables should be ignored since these
|
|
29
|
-
# variables don't carry any class information with them.
|
|
30
|
-
if !valid and node.receiver
|
|
31
|
-
receiver = method_receiver(node.receiver)
|
|
32
|
-
valid = receiver && receiver.ignore
|
|
33
|
-
|
|
34
|
-
if receiver.variable? and receiver.value
|
|
35
|
-
receiver = receiver.value
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
if receiver
|
|
39
|
-
error = receiver_error(node.name, receiver)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
error(error, node) unless valid
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
private
|
|
47
|
-
|
|
48
|
-
##
|
|
49
|
-
# Creates an error message for a method call on a receiver.
|
|
50
|
-
#
|
|
51
|
-
# @param [String] name
|
|
52
|
-
# @param [RubyLint::Definition::RubyObject] receiver
|
|
53
|
-
# @return [String]
|
|
54
|
-
#
|
|
55
|
-
def receiver_error(name, receiver)
|
|
56
|
-
error = "undefined method #{name} on #{receiver.name}"
|
|
57
|
-
receiver_name = receiver.ruby_class || receiver.name
|
|
58
|
-
|
|
59
|
-
if receiver.instance?
|
|
60
|
-
error = "undefined method #{name} on an instance " \
|
|
61
|
-
"of #{receiver_name}"
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
return error
|
|
65
|
-
end
|
|
66
|
-
end # UndefinedMethods
|
|
67
|
-
end # Analyze
|
|
68
|
-
end # RubyLint
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Analyze
|
|
3
|
-
##
|
|
4
|
-
# The UndefinedVariables class checks for the use of undefined variables
|
|
5
|
-
# (such as instance variables and constants). The order of definition and
|
|
6
|
-
# use of a variable does not matter.
|
|
7
|
-
#
|
|
8
|
-
# This analysis class does *not* check for undefined local variables. Ruby
|
|
9
|
-
# treats these as method calls and as result they are handled by
|
|
10
|
-
# {RubyLint::Analyze::UndefinedMethods} instead.
|
|
11
|
-
#
|
|
12
|
-
class UndefinedVariables < Iterator
|
|
13
|
-
include Helper::CurrentScope
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# Hash containing the various variable types to add errors for whenever
|
|
17
|
-
# they are used but not defined.
|
|
18
|
-
#
|
|
19
|
-
# @return [Hash]
|
|
20
|
-
#
|
|
21
|
-
VARIABLE_TYPES = {
|
|
22
|
-
:global_variable => 'global variable',
|
|
23
|
-
:instance_variable => 'instance variable',
|
|
24
|
-
:class_variable => 'class variable',
|
|
25
|
-
:constant => 'constant'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
VARIABLE_TYPES.each do |type, label|
|
|
29
|
-
define_method("on_#{type}") do |node|
|
|
30
|
-
if !current_scope.has_definition?(type, node.name) \
|
|
31
|
-
and !@in_constant_path
|
|
32
|
-
error("undefined #{label} #{node.name}", node)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
##
|
|
38
|
-
# Validates each segment of a constant path in the correct scope.
|
|
39
|
-
#
|
|
40
|
-
# @param [RubyLint::Node] node
|
|
41
|
-
#
|
|
42
|
-
def on_constant_path(node)
|
|
43
|
-
definitions = current_scope
|
|
44
|
-
@in_constant_path = true
|
|
45
|
-
|
|
46
|
-
# The first constant check should take data from parent scopes into
|
|
47
|
-
# account. The following segments should not.
|
|
48
|
-
method = :has_definition?
|
|
49
|
-
|
|
50
|
-
node.children.each do |segment|
|
|
51
|
-
name = segment.name
|
|
52
|
-
|
|
53
|
-
unless definitions.send(method, :constant, name)
|
|
54
|
-
error("undefined constant #{name}", segment)
|
|
55
|
-
|
|
56
|
-
break
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
definitions = definitions.lookup(:constant, name)
|
|
60
|
-
method = :defines?
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
##
|
|
65
|
-
# @param [RubyLint::Node] node
|
|
66
|
-
#
|
|
67
|
-
def after_constant_path(node)
|
|
68
|
-
@in_constant_path = false
|
|
69
|
-
end
|
|
70
|
-
end # UndefinedVariables
|
|
71
|
-
end # Analyze
|
|
72
|
-
end # RubyLint
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Analyze
|
|
3
|
-
##
|
|
4
|
-
# The UnusedVariables class checks for variables that are defined but never
|
|
5
|
-
# used. Whenever it finds one of these variables it will add a
|
|
6
|
-
# corresponding warning message.
|
|
7
|
-
#
|
|
8
|
-
class UnusedVariables < Iterator
|
|
9
|
-
include Helper::CurrentScope
|
|
10
|
-
include Helper::ConstantPaths
|
|
11
|
-
|
|
12
|
-
##
|
|
13
|
-
# Hash containing the various variable types for which to add warnings
|
|
14
|
-
# and human readable names for these types.
|
|
15
|
-
#
|
|
16
|
-
# @return [Hash]
|
|
17
|
-
#
|
|
18
|
-
VARIABLE_TYPES = {
|
|
19
|
-
:local_variable => 'local variable',
|
|
20
|
-
:global_variable => 'global variable',
|
|
21
|
-
:instance_variable => 'instance variable',
|
|
22
|
-
:class_variable => 'class variable',
|
|
23
|
-
:constant => 'constant'
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
VARIABLE_TYPES.each do |type, label|
|
|
27
|
-
define_method("on_#{type}") do |node|
|
|
28
|
-
variable = current_scope.lookup(node.type, node.name)
|
|
29
|
-
|
|
30
|
-
if variable and !variable.used?
|
|
31
|
-
warning("unused #{label} #{node.name}", node)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
##
|
|
37
|
-
# @param [RubyLint::Node] node
|
|
38
|
-
#
|
|
39
|
-
def on_constant_path(node)
|
|
40
|
-
iterate_constant_path(node) do |name, segment, definition|
|
|
41
|
-
if definition and !definition.used?
|
|
42
|
-
warning("unused constant #{name}", segment)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end # UnusedVariables
|
|
47
|
-
end # Analyze
|
|
48
|
-
end # RubyLint
|
data/lib/ruby-lint/base.rb
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
##
|
|
3
|
-
# @return [RubyLint::GlobalScope]
|
|
4
|
-
#
|
|
5
|
-
def self.global_scope
|
|
6
|
-
return @global_scope ||= Definition::RubyObject.new(
|
|
7
|
-
:name => 'global',
|
|
8
|
-
:type => :global
|
|
9
|
-
)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
##
|
|
13
|
-
# Looks up the given constant in the global scope. If it does not exist this
|
|
14
|
-
# method will try to load it from one of the existing definitions.
|
|
15
|
-
#
|
|
16
|
-
# @param [String] name
|
|
17
|
-
# @return [RubyLint::Definition::RubyObject]
|
|
18
|
-
#
|
|
19
|
-
def self.global_constant(name)
|
|
20
|
-
found = global_scope.lookup(:constant, name)
|
|
21
|
-
|
|
22
|
-
if !found and !constant_loader.loaded?(name)
|
|
23
|
-
constant_loader.load(name)
|
|
24
|
-
|
|
25
|
-
found = global_scope.lookup(:constant, name)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
return found
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
##
|
|
32
|
-
# Provides a simple DSL for configuring ruby-lint.
|
|
33
|
-
#
|
|
34
|
-
# @yieldparam [RubyLint::Configuration]
|
|
35
|
-
#
|
|
36
|
-
def self.configure
|
|
37
|
-
yield configuration
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
##
|
|
41
|
-
# @return [RubyLint::Configuration]
|
|
42
|
-
#
|
|
43
|
-
def self.configuration
|
|
44
|
-
return @configuration ||= Configuration.new
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
##
|
|
48
|
-
# @param [RubyLint::Configuration] config
|
|
49
|
-
#
|
|
50
|
-
def self.configuration=(config)
|
|
51
|
-
@configuration = config
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
##
|
|
55
|
-
# @return [RubyLint::ConstantLoader]
|
|
56
|
-
#
|
|
57
|
-
def self.constant_loader
|
|
58
|
-
return @constant_loader ||= ConstantLoader.new
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
##
|
|
62
|
-
# Returns an Array of locations from which to load configuration files.
|
|
63
|
-
#
|
|
64
|
-
# @return [Array]
|
|
65
|
-
#
|
|
66
|
-
def self.configuration_files
|
|
67
|
-
return [
|
|
68
|
-
File.join(Dir.pwd, 'ruby-lint.rb'),
|
|
69
|
-
File.expand_path('~/.ruby-lint.rb', __FILE__)
|
|
70
|
-
]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
##
|
|
74
|
-
# Tries to load a configuration file from one of the locations in
|
|
75
|
-
# {RubyLint.configuration_files}.
|
|
76
|
-
#
|
|
77
|
-
def self.load_configuration
|
|
78
|
-
configuration_files.each do |path|
|
|
79
|
-
if File.file?(path)
|
|
80
|
-
require(path)
|
|
81
|
-
break
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end # RubyLint
|
|
@@ -1,692 +0,0 @@
|
|
|
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
|