ruby-lint 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data.tar.gz.asc +17 -0
- data/.gitignore +1 -0
- data/.travis.yml +25 -0
- data/.yardopts +4 -0
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/MANIFEST +238 -49
- data/README.md +84 -131
- data/Rakefile +6 -0
- data/bin/ruby-lint +2 -2
- data/checksum/.gitkeep +0 -0
- data/doc/DCO.md +26 -0
- data/doc/architecture.md +63 -0
- data/doc/code_analysis.md +90 -0
- data/doc/configuration.md +86 -0
- data/doc/contributing.md +16 -0
- data/doc/graphviz/flow.dot +7 -0
- data/doc/images/.gitkeep +0 -0
- data/doc/images/flow.png +0 -0
- data/lib/ruby-lint.rb +35 -35
- data/lib/ruby-lint/analyze/argument_amount.rb +73 -0
- data/lib/ruby-lint/analyze/shadowing_variables.rb +19 -24
- data/lib/ruby-lint/analyze/undefined_methods.rb +68 -0
- data/lib/ruby-lint/analyze/undefined_variables.rb +42 -69
- data/lib/ruby-lint/analyze/unused_variables.rb +23 -78
- data/lib/ruby-lint/base.rb +85 -0
- data/lib/ruby-lint/cli.rb +23 -167
- data/lib/ruby-lint/cli/analyze.rb +99 -0
- data/lib/ruby-lint/cli/ast.rb +35 -0
- data/lib/ruby-lint/cli/base.rb +120 -0
- data/lib/ruby-lint/configuration.rb +112 -0
- data/lib/ruby-lint/constant_loader.rb +92 -0
- data/lib/ruby-lint/definition/ruby_method.rb +248 -0
- data/lib/ruby-lint/definition/ruby_object.rb +757 -0
- data/lib/ruby-lint/definition_generator.rb +155 -0
- data/lib/ruby-lint/definitions/core.rb +5 -0
- data/lib/ruby-lint/definitions/core/arg0.rb +7 -0
- data/lib/ruby-lint/definitions/core/argf.rb +7 -0
- data/lib/ruby-lint/definitions/core/argument_error.rb +12 -0
- data/lib/ruby-lint/definitions/core/argv.rb +7 -0
- data/lib/ruby-lint/definitions/core/array.rb +414 -0
- data/lib/ruby-lint/definitions/core/autoload.rb +39 -0
- data/lib/ruby-lint/definitions/core/basic_object.rb +46 -0
- data/lib/ruby-lint/definitions/core/bignum.rb +128 -0
- data/lib/ruby-lint/definitions/core/binding.rb +52 -0
- data/lib/ruby-lint/definitions/core/class.rb +23 -0
- data/lib/ruby-lint/definitions/core/comparable.rb +38 -0
- data/lib/ruby-lint/definitions/core/complex.rb +195 -0
- data/lib/ruby-lint/definitions/core/condition_variable.rb +19 -0
- data/lib/ruby-lint/definitions/core/continuation.rb +8 -0
- data/lib/ruby-lint/definitions/core/data.rb +8 -0
- data/lib/ruby-lint/definitions/core/date.rb +706 -0
- data/lib/ruby-lint/definitions/core/date_time.rb +381 -0
- data/lib/ruby-lint/definitions/core/default_record_separator.rb +7 -0
- data/lib/ruby-lint/definitions/core/digest.rb +166 -0
- data/lib/ruby-lint/definitions/core/dir.rb +496 -0
- data/lib/ruby-lint/definitions/core/encoding.rb +2030 -0
- data/lib/ruby-lint/definitions/core/encoding_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/enumerable.rb +352 -0
- data/lib/ruby-lint/definitions/core/enumerator.rb +37 -0
- data/lib/ruby-lint/definitions/core/env.rb +7 -0
- data/lib/ruby-lint/definitions/core/eoferror.rb +8 -0
- data/lib/ruby-lint/definitions/core/erb.rb +304 -0
- data/lib/ruby-lint/definitions/core/errno.rb +3331 -0
- data/lib/ruby-lint/definitions/core/etc.rb +138 -0
- data/lib/ruby-lint/definitions/core/exception.rb +72 -0
- data/lib/ruby-lint/definitions/core/false.rb +7 -0
- data/lib/ruby-lint/definitions/core/false_class.rb +30 -0
- data/lib/ruby-lint/definitions/core/fatal_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/fiber.rb +35 -0
- data/lib/ruby-lint/definitions/core/fiber_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/file.rb +1277 -0
- data/lib/ruby-lint/definitions/core/file_list.rb +727 -0
- data/lib/ruby-lint/definitions/core/file_test.rb +106 -0
- data/lib/ruby-lint/definitions/core/file_utils.rb +1027 -0
- data/lib/ruby-lint/definitions/core/fixnum.rb +156 -0
- data/lib/ruby-lint/definitions/core/float.rb +307 -0
- data/lib/ruby-lint/definitions/core/float_domain_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/gc.rb +57 -0
- data/lib/ruby-lint/definitions/core/gem.rb +3161 -0
- data/lib/ruby-lint/definitions/core/hash.rb +512 -0
- data/lib/ruby-lint/definitions/core/immediate_value.rb +19 -0
- data/lib/ruby-lint/definitions/core/index_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/integer.rb +100 -0
- data/lib/ruby-lint/definitions/core/interrupt.rb +14 -0
- data/lib/ruby-lint/definitions/core/io.rb +928 -0
- data/lib/ruby-lint/definitions/core/ioerror.rb +8 -0
- data/lib/ruby-lint/definitions/core/kernel.rb +504 -0
- data/lib/ruby-lint/definitions/core/key_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/load_error.rb +28 -0
- data/lib/ruby-lint/definitions/core/local_jump_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/main.rb +25 -0
- data/lib/ruby-lint/definitions/core/marshal.rb +466 -0
- data/lib/ruby-lint/definitions/core/match_data.rb +73 -0
- data/lib/ruby-lint/definitions/core/math.rb +205 -0
- data/lib/ruby-lint/definitions/core/memory_segmention_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/method.rb +61 -0
- data/lib/ruby-lint/definitions/core/module.rb +262 -0
- data/lib/ruby-lint/definitions/core/monitor.rb +39 -0
- data/lib/ruby-lint/definitions/core/monitor_mixin.rb +59 -0
- data/lib/ruby-lint/definitions/core/mutex.rb +32 -0
- data/lib/ruby-lint/definitions/core/name_error.rb +16 -0
- data/lib/ruby-lint/definitions/core/nil.rb +7 -0
- data/lib/ruby-lint/definitions/core/nil_class.rb +46 -0
- data/lib/ruby-lint/definitions/core/no_memory_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/no_method_error.rb +18 -0
- data/lib/ruby-lint/definitions/core/not_implemented_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/numeric.rb +123 -0
- data/lib/ruby-lint/definitions/core/object.rb +31 -0
- data/lib/ruby-lint/definitions/core/object_space.rb +41 -0
- data/lib/ruby-lint/definitions/core/open_struct.rb +49 -0
- data/lib/ruby-lint/definitions/core/option_parser.rb +1355 -0
- data/lib/ruby-lint/definitions/core/precision.rb +21 -0
- data/lib/ruby-lint/definitions/core/primitive_failure.rb +8 -0
- data/lib/ruby-lint/definitions/core/proc.rb +109 -0
- data/lib/ruby-lint/definitions/core/process.rb +602 -0
- data/lib/ruby-lint/definitions/core/psych.rb +2231 -0
- data/lib/ruby-lint/definitions/core/queue.rb +44 -0
- data/lib/ruby-lint/definitions/core/rake.rb +4784 -0
- data/lib/ruby-lint/definitions/core/rake_file_utils.rb +203 -0
- data/lib/ruby-lint/definitions/core/rakeversion.rb +7 -0
- data/lib/ruby-lint/definitions/core/random.rb +38 -0
- data/lib/ruby-lint/definitions/core/range.rb +104 -0
- data/lib/ruby-lint/definitions/core/range_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/rational.rb +96 -0
- data/lib/ruby-lint/definitions/core/rb_config.rb +36 -0
- data/lib/ruby-lint/definitions/core/regexp.rb +396 -0
- data/lib/ruby-lint/definitions/core/regexp_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/rubinius.rb +16637 -0
- data/lib/ruby-lint/definitions/core/ruby_copyright.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_description.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_engine.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_lint.rb +93 -0
- data/lib/ruby-lint/definitions/core/ruby_patchlevel.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_platform.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_release_date.rb +7 -0
- data/lib/ruby-lint/definitions/core/ruby_version.rb +7 -0
- data/lib/ruby-lint/definitions/core/runtime_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/scan_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/script_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/security_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/shellwords.rb +37 -0
- data/lib/ruby-lint/definitions/core/signal.rb +37 -0
- data/lib/ruby-lint/definitions/core/signal_exception.rb +19 -0
- data/lib/ruby-lint/definitions/core/singleton.rb +37 -0
- data/lib/ruby-lint/definitions/core/sized_queue.rb +42 -0
- data/lib/ruby-lint/definitions/core/standard_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/stderr.rb +7 -0
- data/lib/ruby-lint/definitions/core/stdin.rb +7 -0
- data/lib/ruby-lint/definitions/core/stdout.rb +7 -0
- data/lib/ruby-lint/definitions/core/stop_iteration.rb +8 -0
- data/lib/ruby-lint/definitions/core/string.rb +713 -0
- data/lib/ruby-lint/definitions/core/string_io.rb +287 -0
- data/lib/ruby-lint/definitions/core/string_scanner.rb +158 -0
- data/lib/ruby-lint/definitions/core/struct.rb +357 -0
- data/lib/ruby-lint/definitions/core/syck.rb +30 -0
- data/lib/ruby-lint/definitions/core/symbol.rb +90 -0
- data/lib/ruby-lint/definitions/core/syntax_error.rb +44 -0
- data/lib/ruby-lint/definitions/core/system_call_error.rb +31 -0
- data/lib/ruby-lint/definitions/core/system_exit.rb +19 -0
- data/lib/ruby-lint/definitions/core/system_stack_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/thread.rb +209 -0
- data/lib/ruby-lint/definitions/core/thread_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/thread_group.rb +22 -0
- data/lib/ruby-lint/definitions/core/time.rb +233 -0
- data/lib/ruby-lint/definitions/core/toplevel_binding.rb +7 -0
- data/lib/ruby-lint/definitions/core/true.rb +7 -0
- data/lib/ruby-lint/definitions/core/true_class.rb +30 -0
- data/lib/ruby-lint/definitions/core/type_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/unbound_method.rb +51 -0
- data/lib/ruby-lint/definitions/core/unmarshalable.rb +13 -0
- data/lib/ruby-lint/definitions/core/unsupported_library_error.rb +8 -0
- data/lib/ruby-lint/definitions/core/weak_ref.rb +42 -0
- data/lib/ruby-lint/definitions/core/zero_division_error.rb +8 -0
- data/lib/ruby-lint/definitions_builder.rb +692 -0
- data/lib/ruby-lint/extensions/string.rb +15 -0
- data/lib/ruby-lint/helper/constant_paths.rb +41 -0
- data/lib/ruby-lint/helper/conversion.rb +33 -0
- data/lib/ruby-lint/helper/current_scope.rb +98 -0
- data/lib/ruby-lint/helper/methods.rb +91 -0
- data/lib/ruby-lint/inspector.rb +191 -0
- data/lib/ruby-lint/iterator.rb +187 -127
- data/lib/ruby-lint/node.rb +107 -0
- data/lib/ruby-lint/parser.rb +510 -1137
- data/lib/ruby-lint/parser_error.rb +15 -27
- data/lib/ruby-lint/presenter/json.rb +19 -0
- data/lib/ruby-lint/presenter/text.rb +37 -0
- data/lib/ruby-lint/report.rb +95 -53
- data/lib/ruby-lint/report/entry.rb +71 -0
- data/lib/ruby-lint/template/definition.erb +24 -0
- data/lib/ruby-lint/template/scope.rb +25 -0
- data/lib/ruby-lint/variable_predicates.rb +109 -0
- data/lib/ruby-lint/version.rb +1 -1
- data/ruby-lint.gemspec +19 -8
- data/spec/helper.rb +10 -2
- data/spec/ruby-lint/analyze/argument_amount.rb +91 -0
- data/spec/ruby-lint/analyze/shadowing_variables.rb +69 -14
- data/spec/ruby-lint/analyze/undefined_methods.rb +174 -0
- data/spec/ruby-lint/analyze/undefined_variables.rb +70 -179
- data/spec/ruby-lint/analyze/unused_variables.rb +63 -183
- data/spec/ruby-lint/configuration.rb +15 -0
- data/spec/ruby-lint/constant_loader.rb +32 -0
- data/spec/ruby-lint/definition/dsl.rb +142 -0
- data/spec/ruby-lint/definition/method_calls.rb +26 -0
- data/spec/ruby-lint/definition/ruby_method.rb +175 -0
- data/spec/ruby-lint/definition/ruby_object.rb +228 -0
- data/spec/ruby-lint/definitions_builder/assignments/arrays.rb +71 -0
- data/spec/ruby-lint/definitions_builder/assignments/hashes.rb +65 -0
- data/spec/ruby-lint/definitions_builder/assignments/objects.rb +23 -0
- data/spec/ruby-lint/definitions_builder/assignments/optional.rb +22 -0
- data/spec/ruby-lint/definitions_builder/assignments/return_values.rb +78 -0
- data/spec/ruby-lint/definitions_builder/assignments/variables.rb +71 -0
- data/spec/ruby-lint/definitions_builder/associate_nodes.rb +17 -0
- data/spec/ruby-lint/definitions_builder/blocks.rb +40 -0
- data/spec/ruby-lint/definitions_builder/classes.rb +230 -0
- data/spec/ruby-lint/definitions_builder/for.rb +16 -0
- data/spec/ruby-lint/definitions_builder/methods.rb +147 -0
- data/spec/ruby-lint/definitions_builder/modules.rb +175 -0
- data/spec/ruby-lint/definitions_builder/reference_amount.rb +31 -0
- data/spec/ruby-lint/definitions_builder/unused.rb +15 -0
- data/spec/ruby-lint/extensions/string.rb +7 -0
- data/spec/ruby-lint/iterator.rb +42 -417
- data/spec/ruby-lint/node.rb +38 -0
- data/spec/ruby-lint/parser/assignments.rb +225 -0
- data/spec/ruby-lint/parser/classes.rb +80 -122
- data/spec/ruby-lint/parser/errors.rb +7 -14
- data/spec/ruby-lint/parser/metadata.rb +17 -0
- data/spec/ruby-lint/parser/method_definitions.rb +111 -0
- data/spec/ruby-lint/parser/methods.rb +184 -216
- data/spec/ruby-lint/parser/modules.rb +54 -33
- data/spec/ruby-lint/parser/operators.rb +30 -65
- data/spec/ruby-lint/parser/statements/begin.rb +55 -0
- data/spec/ruby-lint/parser/statements/case.rb +34 -0
- data/spec/ruby-lint/parser/statements/defined.rb +11 -0
- data/spec/ruby-lint/parser/statements/for.rb +34 -0
- data/spec/ruby-lint/parser/statements/if.rb +46 -0
- data/spec/ruby-lint/parser/statements/return.rb +14 -0
- data/spec/ruby-lint/parser/statements/super.rb +49 -0
- data/spec/ruby-lint/parser/statements/unless.rb +42 -0
- data/spec/ruby-lint/parser/statements/until.rb +25 -0
- data/spec/ruby-lint/parser/statements/while.rb +25 -0
- data/spec/ruby-lint/parser/statements/yield.rb +18 -0
- data/spec/ruby-lint/parser/types/arrays.rb +47 -0
- data/spec/ruby-lint/parser/types/booleans.rb +11 -0
- data/spec/ruby-lint/parser/types/constants.rb +32 -0
- data/spec/ruby-lint/parser/types/hashes.rb +55 -0
- data/spec/ruby-lint/parser/types/nil.rb +7 -0
- data/spec/ruby-lint/parser/types/numbers.rb +11 -0
- data/spec/ruby-lint/parser/types/procs.rb +11 -0
- data/spec/ruby-lint/parser/types/ranges.rb +11 -0
- data/spec/ruby-lint/parser/types/regexp.rb +27 -0
- data/spec/ruby-lint/parser/types/strings.rb +44 -0
- data/spec/ruby-lint/parser/types/symbols.rb +15 -0
- data/spec/ruby-lint/presenter/json.rb +31 -0
- data/spec/ruby-lint/presenter/text.rb +22 -0
- data/spec/ruby-lint/report.rb +45 -15
- data/spec/ruby-lint/report/entry.rb +24 -0
- data/spec/support/bacon.rb +33 -0
- data/spec/support/building.rb +43 -0
- data/spec/support/definitions.rb +23 -0
- data/spec/support/parsing.rb +23 -0
- data/spec/support/simplecov.rb +16 -0
- data/task/build.rake +9 -0
- data/task/checksum.rake +13 -0
- data/task/coverage.rake +6 -0
- data/task/doc.rake +5 -0
- data/task/generate.rake +34 -0
- data/task/graphviz.rake +12 -0
- data/task/stdlib.rake +2 -9
- data/task/tag.rake +6 -0
- metadata +337 -68
- metadata.gz.asc +17 -0
- data/.rbenv-version +0 -1
- data/lib/ruby-lint/analyze/coding_style.rb +0 -407
- data/lib/ruby-lint/analyze/definitions.rb +0 -244
- data/lib/ruby-lint/analyze/method_validation.rb +0 -104
- data/lib/ruby-lint/callback.rb +0 -67
- data/lib/ruby-lint/constant_importer.rb +0 -112
- data/lib/ruby-lint/definition.rb +0 -230
- data/lib/ruby-lint/formatter/text.rb +0 -54
- data/lib/ruby-lint/helper/definition_resolver.rb +0 -143
- data/lib/ruby-lint/helper/scoping.rb +0 -138
- data/lib/ruby-lint/options.rb +0 -58
- data/lib/ruby-lint/token/assignment_token.rb +0 -35
- data/lib/ruby-lint/token/begin_rescue_token.rb +0 -57
- data/lib/ruby-lint/token/block_token.rb +0 -26
- data/lib/ruby-lint/token/case_token.rb +0 -44
- data/lib/ruby-lint/token/class_token.rb +0 -24
- data/lib/ruby-lint/token/keyword_token.rb +0 -43
- data/lib/ruby-lint/token/method_definition_token.rb +0 -64
- data/lib/ruby-lint/token/method_token.rb +0 -56
- data/lib/ruby-lint/token/parameters_token.rb +0 -99
- data/lib/ruby-lint/token/regexp_token.rb +0 -15
- data/lib/ruby-lint/token/statement_token.rb +0 -69
- data/lib/ruby-lint/token/token.rb +0 -176
- data/lib/ruby-lint/token/variable_token.rb +0 -18
- data/spec/benchmarks/memory.rb +0 -52
- data/spec/benchmarks/parse_parser.rb +0 -16
- data/spec/fixtures/stdlib/un.rb +0 -348
- data/spec/ruby-lint/analyze/coding_style.rb +0 -224
- data/spec/ruby-lint/analyze/complex/un.rb +0 -29
- data/spec/ruby-lint/analyze/definitions/classes.rb +0 -114
- data/spec/ruby-lint/analyze/definitions/methods.rb +0 -91
- data/spec/ruby-lint/analyze/definitions/modules.rb +0 -207
- data/spec/ruby-lint/analyze/definitions/variables.rb +0 -103
- data/spec/ruby-lint/analyze/method_validation.rb +0 -177
- data/spec/ruby-lint/callback.rb +0 -28
- data/spec/ruby-lint/constant_importer.rb +0 -27
- data/spec/ruby-lint/definition.rb +0 -96
- data/spec/ruby-lint/formatter/text.rb +0 -21
- data/spec/ruby-lint/parser/arrays.rb +0 -147
- data/spec/ruby-lint/parser/expander_assignments.rb +0 -183
- data/spec/ruby-lint/parser/hashes.rb +0 -136
- data/spec/ruby-lint/parser/keywords.rb +0 -89
- data/spec/ruby-lint/parser/objects.rb +0 -39
- data/spec/ruby-lint/parser/procs.rb +0 -113
- data/spec/ruby-lint/parser/ranges.rb +0 -49
- data/spec/ruby-lint/parser/regexp.rb +0 -31
- data/spec/ruby-lint/parser/scalars.rb +0 -93
- data/spec/ruby-lint/parser/statements.rb +0 -591
- data/spec/ruby-lint/parser/variables.rb +0 -230
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Formatter
|
|
3
|
-
##
|
|
4
|
-
# {RubyLint::Formatter::Text} is a formatter class that formats a report in a
|
|
5
|
-
# format similar to the one used by Ruby when validating a Ruby file using
|
|
6
|
-
# the `ruby` executable. An example of this format is the following:
|
|
7
|
-
#
|
|
8
|
-
# b.rb: error: line 1, column 1: test error
|
|
9
|
-
# b.rb: info: line 3, column 1: test info b.rb
|
|
10
|
-
#
|
|
11
|
-
# Basic usage of this formatter is as following:
|
|
12
|
-
#
|
|
13
|
-
# report = RubyLint::Report.new
|
|
14
|
-
# formatter = RubyLint::Formatter::Text.new
|
|
15
|
-
#
|
|
16
|
-
# # Add some data to the report.
|
|
17
|
-
# # ...
|
|
18
|
-
#
|
|
19
|
-
# puts formatter.format(report)
|
|
20
|
-
#
|
|
21
|
-
class Text
|
|
22
|
-
##
|
|
23
|
-
# A short description of the class.
|
|
24
|
-
#
|
|
25
|
-
# @return [String]
|
|
26
|
-
#
|
|
27
|
-
DESCRIPTION = 'Formats a report in a human readable format.'
|
|
28
|
-
|
|
29
|
-
##
|
|
30
|
-
# Formats the specified report.
|
|
31
|
-
#
|
|
32
|
-
# @param [RubyLint::Report] report The report to format.
|
|
33
|
-
# @return [String]
|
|
34
|
-
#
|
|
35
|
-
def format(report)
|
|
36
|
-
lines = []
|
|
37
|
-
|
|
38
|
-
report.messages.sort.each do |level, messages|
|
|
39
|
-
messages.each do |message|
|
|
40
|
-
lines << '%s: %s: line %s, column %s: %s' % [
|
|
41
|
-
report.file,
|
|
42
|
-
level,
|
|
43
|
-
message[:line],
|
|
44
|
-
message[:column],
|
|
45
|
-
message[:message]
|
|
46
|
-
]
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
return lines.join("\n")
|
|
51
|
-
end
|
|
52
|
-
end # Text
|
|
53
|
-
end # Formatter
|
|
54
|
-
end # RubyLint
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Helper
|
|
3
|
-
##
|
|
4
|
-
# {RubyLint::Helper::DefinitionResolver} is a helper module that can be used
|
|
5
|
-
# to work with scoping information similar to {RubyLint::Helper::Scoping}.
|
|
6
|
-
#
|
|
7
|
-
# This module depends on {RubyLint::Helper::Scoping} and will include it
|
|
8
|
-
# automatically.
|
|
9
|
-
#
|
|
10
|
-
# ## Methods
|
|
11
|
-
#
|
|
12
|
-
# This module defines a set of methods that are called before and after a
|
|
13
|
-
# method, class or module is defined. These methods take care of retrieving
|
|
14
|
-
# the scope for each definition.
|
|
15
|
-
#
|
|
16
|
-
# These methods will also call two special callback methods that make it
|
|
17
|
-
# easier to run code whenever the scope changes:
|
|
18
|
-
#
|
|
19
|
-
# * `on_new_scope`: called when a new scope has been set.
|
|
20
|
-
# * `after_new_scope`: called when the code has reached the end of the
|
|
21
|
-
# current scope.
|
|
22
|
-
#
|
|
23
|
-
# Using these methods classes including this module don't have to redefine
|
|
24
|
-
# methods such as `on_class` (unless explicitly needed of course). Both of
|
|
25
|
-
# these methods are called *after* the current scope has been updated.
|
|
26
|
-
#
|
|
27
|
-
module DefinitionResolver
|
|
28
|
-
include Scoping
|
|
29
|
-
|
|
30
|
-
##
|
|
31
|
-
# Called before processing all the tokens.
|
|
32
|
-
#
|
|
33
|
-
def on_start
|
|
34
|
-
call_method(:on_new_scope)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
##
|
|
38
|
-
# Called after all the tokens have been processed.
|
|
39
|
-
#
|
|
40
|
-
def on_finish
|
|
41
|
-
call_method(:after_new_scope)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
##
|
|
45
|
-
# Sets the scope for the current method definition.
|
|
46
|
-
#
|
|
47
|
-
# @param [RubyLint::Token::MethodDefinitionToken] token
|
|
48
|
-
#
|
|
49
|
-
def on_method_definition(token)
|
|
50
|
-
@scopes << scope.lookup(
|
|
51
|
-
token.receiver ? :method : :instance_method,
|
|
52
|
-
token.name
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
@call_types << :instance_method
|
|
56
|
-
|
|
57
|
-
call_method(:on_new_scope)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
##
|
|
61
|
-
# Resets the scope back to the one used before the method definition.
|
|
62
|
-
#
|
|
63
|
-
# @see RubyLint::Helper::DefinitionResolver#on_method_definition
|
|
64
|
-
#
|
|
65
|
-
def after_method_definition(token)
|
|
66
|
-
@scopes.pop
|
|
67
|
-
@call_types.pop
|
|
68
|
-
|
|
69
|
-
call_method(:after_new_scope)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
##
|
|
73
|
-
# Sets the scope for the current class.
|
|
74
|
-
#
|
|
75
|
-
# @param [RubyLint::Token::ClassToken] token
|
|
76
|
-
#
|
|
77
|
-
def on_class(token)
|
|
78
|
-
name = token.name.join('::')
|
|
79
|
-
|
|
80
|
-
@scopes << scope.lookup(:constant, name)
|
|
81
|
-
@namespace << name
|
|
82
|
-
@call_types << :method
|
|
83
|
-
|
|
84
|
-
call_method(:on_new_scope)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
##
|
|
88
|
-
# Resets the scope back to the one used before the class definition.
|
|
89
|
-
#
|
|
90
|
-
# @see RubyLint::Helper::DefinitionResolver#on_class
|
|
91
|
-
#
|
|
92
|
-
def after_class(token)
|
|
93
|
-
@scopes.pop
|
|
94
|
-
@namespace.pop
|
|
95
|
-
@call_types.pop
|
|
96
|
-
|
|
97
|
-
call_method(:after_new_scope)
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
##
|
|
101
|
-
# Sets the scope for the current module.
|
|
102
|
-
#
|
|
103
|
-
# @param [RubyLint::Token::Token] token
|
|
104
|
-
#
|
|
105
|
-
def on_module(token)
|
|
106
|
-
name = token.name.join('::')
|
|
107
|
-
|
|
108
|
-
@scopes << scope.lookup(:constant, name)
|
|
109
|
-
@namespace << name
|
|
110
|
-
@call_types << :method
|
|
111
|
-
|
|
112
|
-
call_method(:on_new_scope)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
##
|
|
116
|
-
# Resets the scope back to the one used before the module definition.
|
|
117
|
-
#
|
|
118
|
-
# @see RubyLint::Helper::DefinitionResolver#on_module
|
|
119
|
-
#
|
|
120
|
-
def after_module(token)
|
|
121
|
-
@scopes.pop
|
|
122
|
-
@namespace.pop
|
|
123
|
-
@call_types.pop
|
|
124
|
-
|
|
125
|
-
call_method(:after_new_scope)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
private
|
|
129
|
-
|
|
130
|
-
##
|
|
131
|
-
# Calls the specified method if it exists.
|
|
132
|
-
#
|
|
133
|
-
# @param [String|Symbol] method The name of the method to call.
|
|
134
|
-
# @param [Array] args Array of arguments to pass to the method that is
|
|
135
|
-
# being called.
|
|
136
|
-
# @return [Mixed]
|
|
137
|
-
#
|
|
138
|
-
def call_method(method, *args)
|
|
139
|
-
return send(method, *args) if respond_to?(method)
|
|
140
|
-
end
|
|
141
|
-
end # DefinitionResolver
|
|
142
|
-
end # Helper
|
|
143
|
-
end # RubyLint
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Helper
|
|
3
|
-
##
|
|
4
|
-
# {RubyLint::Helper::Scoping} is a helper module that can be used to more
|
|
5
|
-
# easily access scoping related information in subclasses of
|
|
6
|
-
# {RubyLint::Callback}.
|
|
7
|
-
#
|
|
8
|
-
# Note that unlike {RubyLint::Helper::DefinitionResolver} this method does not
|
|
9
|
-
# automatically update the `@scopes` array mentioned below, it merely
|
|
10
|
-
# creates the required variables and provides a few helper methods.
|
|
11
|
-
#
|
|
12
|
-
# ## Methods
|
|
13
|
-
#
|
|
14
|
-
# This module provides two methods:
|
|
15
|
-
#
|
|
16
|
-
# * scope: a method that can be used to retrieve the current
|
|
17
|
-
# scope/definition.
|
|
18
|
-
# * resolve_definition: a method that can be used to retrieve the
|
|
19
|
-
# scope/definition for the last constant in a constant path.
|
|
20
|
-
#
|
|
21
|
-
# ## Variables
|
|
22
|
-
#
|
|
23
|
-
# The following instance variables are created upon initializing a class
|
|
24
|
-
# that includes this module:
|
|
25
|
-
#
|
|
26
|
-
# * `@scopes`: an array that should be updated with instance of
|
|
27
|
-
# {RubyLint::Definition} based on the current scope.
|
|
28
|
-
# * `@namespace`: array containing the constant names for the current
|
|
29
|
-
# namespace.
|
|
30
|
-
#
|
|
31
|
-
# The following keys are set in the `@storage` instance variable:
|
|
32
|
-
#
|
|
33
|
-
# * `:scope`: an instance of {RubyLint::Definition} that will contain the
|
|
34
|
-
# definition list of the current block of code that's being analyzed.
|
|
35
|
-
#
|
|
36
|
-
module Scoping
|
|
37
|
-
##
|
|
38
|
-
# @see RubyLint::Callback#initialize
|
|
39
|
-
#
|
|
40
|
-
def initialize(*args)
|
|
41
|
-
super
|
|
42
|
-
|
|
43
|
-
@scopes = []
|
|
44
|
-
@namespace = []
|
|
45
|
-
@call_types = []
|
|
46
|
-
|
|
47
|
-
unless @storage[:scope].is_a?(Definition)
|
|
48
|
-
@storage[:scope] = Definition.new(nil, :lazy => true, :kernel => true)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
##
|
|
55
|
-
# Returns the scope/definition for the last segment in the specified
|
|
56
|
-
# constant path.
|
|
57
|
-
#
|
|
58
|
-
# @param [Array] path The constant path.
|
|
59
|
-
# @return [RubyLint::Definition]
|
|
60
|
-
#
|
|
61
|
-
def resolve_definition(path)
|
|
62
|
-
current = scope
|
|
63
|
-
|
|
64
|
-
path.each do |segment|
|
|
65
|
-
found = current.lookup(:constant, segment)
|
|
66
|
-
current = found if found
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
return current
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
##
|
|
73
|
-
# Checks if the specified token's name is a valid constant path.
|
|
74
|
-
#
|
|
75
|
-
# @param [RubyLint::Token::VariableToken] token The token to validate.
|
|
76
|
-
# @return [TrueClass|FalseClass]
|
|
77
|
-
#
|
|
78
|
-
def valid_constant_path?(token)
|
|
79
|
-
current = scope
|
|
80
|
-
|
|
81
|
-
token.name.each do |segment|
|
|
82
|
-
found = current.lookup(:constant, segment)
|
|
83
|
-
|
|
84
|
-
if found and token.line > found.token.line
|
|
85
|
-
current = found
|
|
86
|
-
else
|
|
87
|
-
return false
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
return true
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
##
|
|
95
|
-
# Checks if the specified type and token result in a valid
|
|
96
|
-
# {RubyLint::Definition} instance.
|
|
97
|
-
#
|
|
98
|
-
# @param [#to_sym] type The type of data to look up.
|
|
99
|
-
# @param [RubyLint::Token::VariableToken] token The token containing details
|
|
100
|
-
# about the variable.
|
|
101
|
-
# @param [RubyLint::Definition] scope The scope to use for looking up the
|
|
102
|
-
# data.
|
|
103
|
-
# @return [TrueClass|FalseClass]
|
|
104
|
-
#
|
|
105
|
-
def definition_exists?(type, token, scope = scope)
|
|
106
|
-
found = scope.lookup(type, token.name)
|
|
107
|
-
has_line = found.respond_to?(:token) \
|
|
108
|
-
&& !found.token.nil? \
|
|
109
|
-
&& !found.token.line.nil?
|
|
110
|
-
|
|
111
|
-
if !found or (has_line and found.token.line > token.line)
|
|
112
|
-
return false
|
|
113
|
-
else
|
|
114
|
-
return true
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
##
|
|
119
|
-
# Returns the call type to use for method calls.
|
|
120
|
-
#
|
|
121
|
-
# @return [Symbol]
|
|
122
|
-
#
|
|
123
|
-
def call_type
|
|
124
|
-
return !@call_types.empty? ? @call_types[-1] : :instance_method
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
##
|
|
128
|
-
# Returns the current scope. This method is primarily used to make the
|
|
129
|
-
# code in this class a bit more pleasant to read.
|
|
130
|
-
#
|
|
131
|
-
# @return [RubyLint::Definition]
|
|
132
|
-
#
|
|
133
|
-
def scope
|
|
134
|
-
return !@scopes.empty? ? @scopes[-1] : @storage[:scope]
|
|
135
|
-
end
|
|
136
|
-
end # Scoping
|
|
137
|
-
end # Helper
|
|
138
|
-
end # RubyLint
|
data/lib/ruby-lint/options.rb
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
##
|
|
3
|
-
# {RubyLint::Options} is a class that can be used to configure various parts of
|
|
4
|
-
# RubyLint such as what formatter to use, the reporting levels, etc.
|
|
5
|
-
#
|
|
6
|
-
class Options
|
|
7
|
-
##
|
|
8
|
-
# Array containing the analyzer classes that are always enabled. The order
|
|
9
|
-
# of these classes is preserved.
|
|
10
|
-
#
|
|
11
|
-
# @return [Array]
|
|
12
|
-
#
|
|
13
|
-
REQUIRED_ANALYZERS = [Analyze::Definitions]
|
|
14
|
-
|
|
15
|
-
##
|
|
16
|
-
# The reporting formatter to use, set to {RubyLint::Formatter::Text} by
|
|
17
|
-
# default.
|
|
18
|
-
#
|
|
19
|
-
# @return [RubyLint::Formatter]
|
|
20
|
-
#
|
|
21
|
-
attr_accessor :formatter
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
# The enabled reporting levels. See {RubyLint::Report#levels} and
|
|
25
|
-
# {RubyLint::Report#initialize} for more information.
|
|
26
|
-
#
|
|
27
|
-
# @return [Array]
|
|
28
|
-
#
|
|
29
|
-
attr_accessor :levels
|
|
30
|
-
|
|
31
|
-
##
|
|
32
|
-
# Array of classes to use for analyzing code. By default all the classes
|
|
33
|
-
# defined under {RubyLint::Analyze} are used.
|
|
34
|
-
#
|
|
35
|
-
# @return [Array]
|
|
36
|
-
#
|
|
37
|
-
attr_accessor :analyzers
|
|
38
|
-
|
|
39
|
-
##
|
|
40
|
-
# Sets the default values for various options.
|
|
41
|
-
#
|
|
42
|
-
def initialize
|
|
43
|
-
@formatter = Formatter::Text
|
|
44
|
-
@levels = Report::DEFAULT_LEVELS
|
|
45
|
-
@analyzers = REQUIRED_ANALYZERS.dup
|
|
46
|
-
|
|
47
|
-
Analyze.constants.each do |c|
|
|
48
|
-
const = Analyze.const_get(c)
|
|
49
|
-
|
|
50
|
-
@analyzers << const unless @analyzers.include?(const)
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end # Options
|
|
54
|
-
|
|
55
|
-
@options = Options.new
|
|
56
|
-
|
|
57
|
-
class << self; attr_reader :options; end
|
|
58
|
-
end # RubyLint
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Token
|
|
3
|
-
##
|
|
4
|
-
# Token class that is used whenever a value is assigned to a variable,
|
|
5
|
-
# object attribute or similar.
|
|
6
|
-
#
|
|
7
|
-
class AssignmentToken < Token
|
|
8
|
-
##
|
|
9
|
-
# The object receiver, set when a value is assigned to an object
|
|
10
|
-
# attribute.
|
|
11
|
-
#
|
|
12
|
-
# @return [RubyLint::Token::Token]
|
|
13
|
-
#
|
|
14
|
-
attr_accessor :receiver
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
# Symbol containing the operator that was used to separate the receiver
|
|
18
|
-
# and attribute name.
|
|
19
|
-
#
|
|
20
|
-
# @return [Symbol]
|
|
21
|
-
#
|
|
22
|
-
attr_accessor :operator
|
|
23
|
-
|
|
24
|
-
##
|
|
25
|
-
# @see RubyLint::Token::Token#initialize
|
|
26
|
-
#
|
|
27
|
-
def initialize(*args)
|
|
28
|
-
super
|
|
29
|
-
|
|
30
|
-
@type = :local_variable if @type == :identifier
|
|
31
|
-
@event = :assignment
|
|
32
|
-
end
|
|
33
|
-
end # AssignmentToken
|
|
34
|
-
end # Token
|
|
35
|
-
end # RubyLint
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
module RubyLint
|
|
2
|
-
module Token
|
|
3
|
-
##
|
|
4
|
-
# Token class used for storing information about begin/rescue/ensure
|
|
5
|
-
# statements.
|
|
6
|
-
#
|
|
7
|
-
class BeginRescueToken < Token
|
|
8
|
-
##
|
|
9
|
-
# Array of rescue statements. Each item is an instance of
|
|
10
|
-
# {RubyLint::Token::StatementToken}.
|
|
11
|
-
#
|
|
12
|
-
# @return [Array]
|
|
13
|
-
#
|
|
14
|
-
attr_accessor :rescue
|
|
15
|
-
|
|
16
|
-
##
|
|
17
|
-
# Attribute containing details about the ensure statement.
|
|
18
|
-
#
|
|
19
|
-
# @return [RubyLint::Token::StatementToken]
|
|
20
|
-
#
|
|
21
|
-
attr_accessor :ensure
|
|
22
|
-
|
|
23
|
-
##
|
|
24
|
-
# Attribute containing details about the else statement.
|
|
25
|
-
#
|
|
26
|
-
# @return [RubyLint::Token::StatementToken]
|
|
27
|
-
#
|
|
28
|
-
attr_accessor :else
|
|
29
|
-
|
|
30
|
-
##
|
|
31
|
-
# @see RubyLint::Token#initialize
|
|
32
|
-
#
|
|
33
|
-
def initialize(*args)
|
|
34
|
-
@type = :begin_rescue
|
|
35
|
-
|
|
36
|
-
super
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
##
|
|
40
|
-
# @see RubyLint::Token::Token#child_nodes
|
|
41
|
-
#
|
|
42
|
-
def child_nodes
|
|
43
|
-
nodes = [@rescue]
|
|
44
|
-
|
|
45
|
-
if @ensure
|
|
46
|
-
nodes << [@ensure]
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
if @else
|
|
50
|
-
nodes << [@else]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
return super + nodes
|
|
54
|
-
end
|
|
55
|
-
end # BeginRescueToken
|
|
56
|
-
end # Token
|
|
57
|
-
end # RubyLint
|