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,43 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Base definition builder that provides common methods for individual
|
5
|
+
# builder classes.
|
6
|
+
#
|
7
|
+
# @!attribute [r] node
|
8
|
+
# @return [RubyLint::AST::Node]
|
9
|
+
# @!attribute [r] definitions
|
10
|
+
# @return [RubyLint::Definition::RubyObject]
|
11
|
+
#
|
12
|
+
class Base
|
13
|
+
include Helper::ConstantPaths
|
14
|
+
|
15
|
+
attr_reader :definitions, :node, :options
|
16
|
+
|
17
|
+
##
|
18
|
+
# @param [RubyLint::AST::Node] node
|
19
|
+
# @param [RubyLint::Definition::RubyObject] definitions
|
20
|
+
# @param [Hash] options
|
21
|
+
#
|
22
|
+
def initialize(node, definitions, options = {})
|
23
|
+
@node = node
|
24
|
+
@definitions = definitions
|
25
|
+
@options = options
|
26
|
+
|
27
|
+
after_initialize if respond_to?(:after_initialize)
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
##
|
33
|
+
# Returns the name of a constant node as a String.
|
34
|
+
#
|
35
|
+
# @param [RubyLint::AST::Node] node
|
36
|
+
# @return [String]
|
37
|
+
#
|
38
|
+
def constant_name(node)
|
39
|
+
return node.children[1].to_s
|
40
|
+
end
|
41
|
+
end # Base
|
42
|
+
end # DefinitionBuilder
|
43
|
+
end # RubyLint
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Definition builder used for building primitive Ruby types such as
|
5
|
+
# integers and strings.
|
6
|
+
#
|
7
|
+
class Primitive < Base
|
8
|
+
##
|
9
|
+
# @return [RubyLint::Definition::RubyObject]
|
10
|
+
#
|
11
|
+
def build
|
12
|
+
parents = [definition_for_node(node)]
|
13
|
+
opts = {
|
14
|
+
:type => node.type,
|
15
|
+
:value => node.children[0],
|
16
|
+
:instance_type => :instance,
|
17
|
+
:parents => parents
|
18
|
+
}.merge(options)
|
19
|
+
|
20
|
+
return Definition::RubyObject.new(opts)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Returns a definition for a given node type.
|
25
|
+
#
|
26
|
+
# @param [RubyLint::AST::Node] node
|
27
|
+
# @return [RubyLint::Definition::RubyObject]
|
28
|
+
# @raise ArgumentError Raised when an invalid type was specified.
|
29
|
+
#
|
30
|
+
def definition_for_node(node)
|
31
|
+
ruby_class = node.ruby_class
|
32
|
+
|
33
|
+
raise(ArgumentError, "The type #{type} is invalid") unless ruby_class
|
34
|
+
|
35
|
+
return RubyLint::VirtualMachine.global_constant(ruby_class)
|
36
|
+
end
|
37
|
+
end # Primitive
|
38
|
+
end # DefinitionBuilder
|
39
|
+
end # RubyLint
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Definition builder for building Ruby arrays.
|
5
|
+
#
|
6
|
+
class RubyArray < Base
|
7
|
+
##
|
8
|
+
# Builds the definition for the array and assigns the values as members.
|
9
|
+
#
|
10
|
+
# @return [RubyLint::Definition::RubyObject]
|
11
|
+
#
|
12
|
+
def build
|
13
|
+
definition = create_container
|
14
|
+
|
15
|
+
values.each_with_index do |value, index|
|
16
|
+
member = create_member(index.to_s, value)
|
17
|
+
|
18
|
+
definition.add_definition(member)
|
19
|
+
end
|
20
|
+
|
21
|
+
return definition
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
##
|
27
|
+
# @return [Array]
|
28
|
+
#
|
29
|
+
def values
|
30
|
+
return options[:values] || []
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# @return [Array]
|
35
|
+
#
|
36
|
+
def parents
|
37
|
+
return [RubyLint::VirtualMachine.global_constant('Array')]
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Creates an empty data container for the members.
|
42
|
+
#
|
43
|
+
# @return [RubyLint::Definition::RubyObject]
|
44
|
+
#
|
45
|
+
def create_container
|
46
|
+
return Definition::RubyObject.new(
|
47
|
+
:type => container_type,
|
48
|
+
:instance_type => :instance,
|
49
|
+
:parents => parents,
|
50
|
+
:members_as_value => true
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# @return [Symbol]
|
56
|
+
#
|
57
|
+
def container_type
|
58
|
+
return :array
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Creates a new array member definition.
|
63
|
+
#
|
64
|
+
# @param [String] name
|
65
|
+
# @param [RubyLint::Definition::RubyObject] value
|
66
|
+
# @return [RubyLint::Definition::RubyObject]
|
67
|
+
#
|
68
|
+
def create_member(name, value)
|
69
|
+
return Definition::RubyObject.new(
|
70
|
+
:type => :member,
|
71
|
+
:name => name,
|
72
|
+
:value => value
|
73
|
+
)
|
74
|
+
end
|
75
|
+
end # RubyArray
|
76
|
+
end # DefinitionBuilder
|
77
|
+
end # RubyLint
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Definition builder for building Ruby blocks.
|
5
|
+
#
|
6
|
+
class RubyBlock < Base
|
7
|
+
##
|
8
|
+
# @return [RubyLint::Definition::RubyObject]
|
9
|
+
#
|
10
|
+
def build
|
11
|
+
definition = new_definition([definitions])
|
12
|
+
|
13
|
+
definitions.list(:lvar).each do |variable|
|
14
|
+
definition.add_definition(variable)
|
15
|
+
end
|
16
|
+
|
17
|
+
return definition
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# @param [Array] parents
|
22
|
+
# @return [RubyLint::Definition::RubyObject]
|
23
|
+
#
|
24
|
+
def new_definition(parents)
|
25
|
+
return Definition::RubyObject.new(
|
26
|
+
:name => 'block',
|
27
|
+
:type => :block,
|
28
|
+
:parents => parents,
|
29
|
+
:update_parents => [:lvar, :ivar, :cvar, :gvar]
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end # RubyBlock
|
33
|
+
end # DefinitionBuilder
|
34
|
+
end # RubyLint
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Definition builder used for building Ruby classes.
|
5
|
+
#
|
6
|
+
class RubyClass < RubyModule
|
7
|
+
##
|
8
|
+
# Called after creating a new instance of the class.
|
9
|
+
#
|
10
|
+
def after_initialize
|
11
|
+
options[:parent] ||= RubyLint::VirtualMachine.global_constant('Object')
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Builds the definition for a Ruby class.
|
16
|
+
#
|
17
|
+
# @see RubyLint::DefinitionBuilder::RubyModule#build
|
18
|
+
#
|
19
|
+
def build
|
20
|
+
return new_definition([options[:parent], definitions])
|
21
|
+
end
|
22
|
+
end # RubyClass
|
23
|
+
end # DefinitionBuilder
|
24
|
+
end # RubyLint
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Definition builder for building Ruby hashes.
|
5
|
+
#
|
6
|
+
class RubyHash < RubyArray
|
7
|
+
##
|
8
|
+
# Builds the definition for the Hash and assigns the members.
|
9
|
+
#
|
10
|
+
# @return [RubyLint::Definition::RubyObject]
|
11
|
+
#
|
12
|
+
def build
|
13
|
+
definition = create_container
|
14
|
+
|
15
|
+
values.each do |pair|
|
16
|
+
definition.add_definition(pair)
|
17
|
+
end
|
18
|
+
|
19
|
+
return definition
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# @see RubyLint::DefinitionBuilder::RubyArray#parents
|
24
|
+
#
|
25
|
+
def parents
|
26
|
+
return [RubyLint::VirtualMachine.global_constant('Hash')]
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# @return [Symbol]
|
31
|
+
#
|
32
|
+
def container_type
|
33
|
+
return :hash
|
34
|
+
end
|
35
|
+
end # RubyHash
|
36
|
+
end # DefinitionBuilder
|
37
|
+
end # RubyLint
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Definition builder for building method definitions. Receivers should be
|
5
|
+
# set from the outside (= the VM).
|
6
|
+
#
|
7
|
+
class RubyMethod < Base
|
8
|
+
##
|
9
|
+
# Called after a new instance has been created.
|
10
|
+
#
|
11
|
+
def after_initialize
|
12
|
+
@options[:type] ||= :instance_method
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Builds the definition for the method definition.
|
17
|
+
#
|
18
|
+
# @see #new_definition
|
19
|
+
# @return [RubyLint::Definition::RubyMethod]
|
20
|
+
#
|
21
|
+
def build
|
22
|
+
return new_definition([scope])
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Returns the scope to define the method in.
|
27
|
+
#
|
28
|
+
# @return [RubyLint::Definition::RubyObject]
|
29
|
+
#
|
30
|
+
def scope
|
31
|
+
scope = definitions
|
32
|
+
|
33
|
+
if has_receiver? and options[:receiver]
|
34
|
+
scope = options[:receiver]
|
35
|
+
end
|
36
|
+
|
37
|
+
return scope
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
##
|
43
|
+
# @return [String]
|
44
|
+
#
|
45
|
+
def method_name
|
46
|
+
return node.children[name_index].to_s
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
# @param [Array] parents The parent definitions.
|
51
|
+
# @return [RubyLint::Definition::RubyObject]
|
52
|
+
#
|
53
|
+
def new_definition(parents)
|
54
|
+
type = options[:type]
|
55
|
+
|
56
|
+
if has_receiver?
|
57
|
+
type = :method if options[:receiver].class?
|
58
|
+
end
|
59
|
+
|
60
|
+
return Definition::RubyMethod.new(
|
61
|
+
:name => method_name,
|
62
|
+
:parents => parents,
|
63
|
+
:type => type,
|
64
|
+
:instance_type => :instance,
|
65
|
+
:visibility => options[:visibility]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# @return [TrueClass|FalseClass]
|
71
|
+
#
|
72
|
+
def has_receiver?
|
73
|
+
return node.type == :defs
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# @return [Numeric]
|
78
|
+
#
|
79
|
+
def name_index
|
80
|
+
return has_receiver? ? 1 : 0
|
81
|
+
end
|
82
|
+
end # RubyMethod
|
83
|
+
end # DefinitionBuilder
|
84
|
+
end # RubyLint
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module RubyLint
|
2
|
+
module DefinitionBuilder
|
3
|
+
##
|
4
|
+
# Definition builder used for building Ruby modules as well as providing
|
5
|
+
# the groundwork for building Ruby classes.
|
6
|
+
#
|
7
|
+
class RubyModule < Base
|
8
|
+
##
|
9
|
+
# Creates a new module definition.
|
10
|
+
#
|
11
|
+
# @see #new_definition
|
12
|
+
#
|
13
|
+
def build
|
14
|
+
return new_definition([definitions])
|
15
|
+
end
|
16
|
+
|
17
|
+
##
|
18
|
+
# Determines the scope to define the module in.
|
19
|
+
#
|
20
|
+
# @return [RubyLint::Definition::RubyObject]
|
21
|
+
#
|
22
|
+
def scope
|
23
|
+
scope = definitions
|
24
|
+
name_prefix = node.children[0].children[0]
|
25
|
+
|
26
|
+
# name_prefix contains the constant path leading up to the name. For
|
27
|
+
# example, if the name is `A::B::C` this node would contain `A::B`.
|
28
|
+
if name_prefix
|
29
|
+
found = resolve_constant_path(name_prefix)
|
30
|
+
scope = found if found
|
31
|
+
end
|
32
|
+
|
33
|
+
return scope
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
##
|
39
|
+
# Returns the name of the module.
|
40
|
+
#
|
41
|
+
# @see #constant_name
|
42
|
+
#
|
43
|
+
def module_name
|
44
|
+
return constant_name(node.children[0])
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Creates a new RubyObject definition with the specified parent
|
49
|
+
# definitions.
|
50
|
+
#
|
51
|
+
# @param [Array] parents
|
52
|
+
# @return [RubyLint::Definition::RubyObject]
|
53
|
+
#
|
54
|
+
def new_definition(parents)
|
55
|
+
definition = Definition::RubyObject.new(
|
56
|
+
:name => module_name,
|
57
|
+
:parents => parents,
|
58
|
+
:reference_amount => 1,
|
59
|
+
:type => :const
|
60
|
+
)
|
61
|
+
|
62
|
+
definition.add(:keyword, 'self', definition)
|
63
|
+
|
64
|
+
return definition
|
65
|
+
end
|
66
|
+
end # RubyModule
|
67
|
+
end # DefinitionBuilder
|
68
|
+
end # RubyLint
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'erb'
|
3
3
|
require_relative 'template/scope'
|
4
|
+
require_relative 'generated_constant'
|
4
5
|
|
5
6
|
module RubyLint
|
6
7
|
##
|
@@ -17,10 +18,13 @@ module RubyLint
|
|
17
18
|
#
|
18
19
|
# @!attribute [r] directory
|
19
20
|
# @return [String] The directory to store the generated definitions in.
|
21
|
+
#
|
20
22
|
# @!attribute [r] options
|
21
23
|
# @return [Hash]
|
22
|
-
#
|
23
|
-
#
|
24
|
+
#
|
25
|
+
# @!attribute [r] template
|
26
|
+
# @return [String] The ERB template to use.
|
27
|
+
#
|
24
28
|
# @!attribute [r] inspector
|
25
29
|
# @return [RubyLint::Inspector]
|
26
30
|
#
|
@@ -48,8 +52,8 @@ module RubyLint
|
|
48
52
|
constants = inspector.inspect_constants.sort - options[:ignore]
|
49
53
|
|
50
54
|
group_constants(constants).each do |root, names|
|
51
|
-
filepath
|
52
|
-
|
55
|
+
filepath = File.join(directory, "#{root.snake_case}.rb")
|
56
|
+
constants = []
|
53
57
|
|
54
58
|
if File.file?(filepath) and !options[:overwrite]
|
55
59
|
next
|
@@ -58,21 +62,26 @@ module RubyLint
|
|
58
62
|
names.each do |name|
|
59
63
|
current_inspector = Inspector.new(name)
|
60
64
|
inspected_methods = inspect_methods(current_inspector)
|
61
|
-
|
62
|
-
:methods => method_information(inspected_methods),
|
63
|
-
:constant => current_inspector.constant,
|
64
|
-
:constant_name => current_inspector.constant_name,
|
65
|
-
:superclass => (current_inspector.constant.superclass rescue nil)
|
66
|
-
}
|
65
|
+
superclass = nil
|
67
66
|
|
68
|
-
|
69
|
-
|
67
|
+
if current_inspector.inspect_superclass
|
68
|
+
superclass = current_inspector.inspect_superclass.to_s
|
69
|
+
end
|
70
70
|
|
71
|
-
|
71
|
+
constant = GeneratedConstant.new(
|
72
|
+
:name => current_inspector.constant_name,
|
73
|
+
:constant => current_inspector.constant,
|
74
|
+
:methods => method_information(inspected_methods),
|
75
|
+
:superclass => superclass
|
76
|
+
)
|
77
|
+
|
78
|
+
constants << constant
|
72
79
|
end
|
73
80
|
|
81
|
+
erb = render_template(template, :constants => constants)
|
82
|
+
|
74
83
|
File.open(filepath, 'w') do |handle|
|
75
|
-
handle.write(
|
84
|
+
handle.write(erb)
|
76
85
|
end
|
77
86
|
end
|
78
87
|
end
|
@@ -130,7 +139,7 @@ module RubyLint
|
|
130
139
|
args = []
|
131
140
|
|
132
141
|
method.parameters.each do |arg|
|
133
|
-
args << {:
|
142
|
+
args << {:type => arg_mapping[arg[0]], :name => arg[1]}
|
134
143
|
end
|
135
144
|
|
136
145
|
info[type][method.name] = args
|
@@ -151,5 +160,22 @@ module RubyLint
|
|
151
160
|
:block => :block_argument
|
152
161
|
}
|
153
162
|
end
|
163
|
+
|
164
|
+
##
|
165
|
+
# @param [String] template
|
166
|
+
# @param [Hash] variables
|
167
|
+
#
|
168
|
+
def render_template(template, variables = {})
|
169
|
+
scope = Template::Scope.new(variables)
|
170
|
+
erb = ERB.new(template, nil, '-').result(scope.get_binding)
|
171
|
+
|
172
|
+
# Trim excessive newlines.
|
173
|
+
erb.gsub!(/\n{3,}/, "\n\n")
|
174
|
+
|
175
|
+
# Get rid of the occasional empty newline before `end` tokens.
|
176
|
+
erb.gsub!(/\n{2,}end/, "\nend")
|
177
|
+
|
178
|
+
return erb
|
179
|
+
end
|
154
180
|
end # DefinitionGenerator
|
155
181
|
end # RubyLint
|