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
data/lib/ruby-lint/version.rb
CHANGED
data/ruby-lint.gemspec
CHANGED
|
@@ -3,10 +3,10 @@ require File.expand_path('../lib/ruby-lint/version', __FILE__)
|
|
|
3
3
|
Gem::Specification.new do |s|
|
|
4
4
|
s.name = 'ruby-lint'
|
|
5
5
|
s.version = RubyLint::VERSION
|
|
6
|
-
s.date = '
|
|
6
|
+
s.date = '2013-04-22'
|
|
7
7
|
s.authors = ['Yorick Peterse']
|
|
8
8
|
s.email = 'yorickpeterse@gmail.com'
|
|
9
|
-
s.summary = '
|
|
9
|
+
s.summary = 'A linter and static code analysis tool for Ruby.'
|
|
10
10
|
s.homepage = 'https://github.com/yorickpeterse/ruby-lint/'
|
|
11
11
|
s.description = s.summary
|
|
12
12
|
s.executables = ['ruby-lint']
|
|
@@ -14,11 +14,22 @@ Gem::Specification.new do |s|
|
|
|
14
14
|
s.files = File.read(File.expand_path('../MANIFEST', __FILE__)).split("\n")
|
|
15
15
|
|
|
16
16
|
s.has_rdoc = 'yard'
|
|
17
|
-
s.required_ruby_version = '>= 1.9.
|
|
17
|
+
s.required_ruby_version = '>= 1.9.3'
|
|
18
18
|
|
|
19
|
-
s.
|
|
20
|
-
s.
|
|
21
|
-
|
|
22
|
-
s.add_development_dependency
|
|
23
|
-
s.add_development_dependency
|
|
19
|
+
s.add_dependency 'ast'
|
|
20
|
+
s.add_dependency 'slop'
|
|
21
|
+
|
|
22
|
+
s.add_development_dependency 'rake'
|
|
23
|
+
s.add_development_dependency 'bacon', ['>= 1.2.0']
|
|
24
|
+
s.add_development_dependency 'yard'
|
|
25
|
+
s.add_development_dependency 'pry-rescue'
|
|
26
|
+
s.add_development_dependency 'bacon-colored_output'
|
|
27
|
+
s.add_development_dependency 'simplecov'
|
|
28
|
+
s.add_development_dependency 'rubygems-openpgp'
|
|
29
|
+
|
|
30
|
+
# NOTE: This is to prevent Travis CI from soiling its pants. It's not a
|
|
31
|
+
# really nice solution but it seems to be the only way (at least for now).
|
|
32
|
+
if RUBY_PLATFORM != 'java'
|
|
33
|
+
s.add_development_dependency 'redcarpet', ['>= 2.1.1']
|
|
34
|
+
end
|
|
24
35
|
end
|
data/spec/helper.rb
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
require File.expand_path('../../lib/ruby-lint', __FILE__)
|
|
2
1
|
require 'bacon'
|
|
2
|
+
require 'bacon/colored_output'
|
|
3
|
+
require_relative 'support/bacon'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
if ENV['COVERAGE']
|
|
6
|
+
require_relative 'support/simplecov'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
require_relative '../lib/ruby-lint'
|
|
10
|
+
require_relative 'support/building'
|
|
11
|
+
require_relative 'support/parsing'
|
|
12
|
+
require_relative 'support/definitions'
|
|
5
13
|
|
|
6
14
|
Bacon.summary_on_exit
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require File.expand_path('../../../helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe RubyLint::Analyze::ArgumentAmount do
|
|
4
|
+
should 'validate the amount of required arguments' do
|
|
5
|
+
code = <<-CODE
|
|
6
|
+
def example(first, second)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
example
|
|
10
|
+
CODE
|
|
11
|
+
|
|
12
|
+
report = build_report(code, RubyLint::Analyze::ArgumentAmount)
|
|
13
|
+
entry = report.entries[0]
|
|
14
|
+
|
|
15
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
16
|
+
|
|
17
|
+
entry.line.should == 4
|
|
18
|
+
entry.column.should == 0
|
|
19
|
+
entry.message.should == 'wrong number of arguments (expected 2 but got 0)'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should 'validate argument amounts when using optional arguments' do
|
|
23
|
+
code = <<-CODE
|
|
24
|
+
def example(first, second, third = nil)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
example
|
|
28
|
+
CODE
|
|
29
|
+
|
|
30
|
+
report = build_report(code, RubyLint::Analyze::ArgumentAmount)
|
|
31
|
+
entry = report.entries[0]
|
|
32
|
+
|
|
33
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
34
|
+
|
|
35
|
+
entry.line.should == 4
|
|
36
|
+
entry.column.should == 0
|
|
37
|
+
entry.message.should == 'wrong number of arguments ' \
|
|
38
|
+
'(expected 2..3 but got 0)'
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
should 'validate argument amounts when using rest arguments' do
|
|
42
|
+
code = <<-CODE
|
|
43
|
+
def example(first, second, *args)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
example
|
|
47
|
+
CODE
|
|
48
|
+
|
|
49
|
+
report = build_report(code, RubyLint::Analyze::ArgumentAmount)
|
|
50
|
+
entry = report.entries[0]
|
|
51
|
+
|
|
52
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
53
|
+
|
|
54
|
+
entry.line.should == 4
|
|
55
|
+
entry.column.should == 0
|
|
56
|
+
entry.message.should == 'wrong number of arguments ' \
|
|
57
|
+
'(expected 2 but got 0)'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
should 'validate argument amounts when using a required and rest argument' do
|
|
61
|
+
code = <<-CODE
|
|
62
|
+
def example(required, *numbers)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
example(10, 20, 30)
|
|
66
|
+
CODE
|
|
67
|
+
|
|
68
|
+
report = build_report(code, RubyLint::Analyze::ArgumentAmount)
|
|
69
|
+
|
|
70
|
+
report.entries.length.should == 0
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
should 'take variable assignments into account' do
|
|
74
|
+
code = <<-CODE
|
|
75
|
+
name = 'Ruby'
|
|
76
|
+
|
|
77
|
+
name.downcase
|
|
78
|
+
CODE
|
|
79
|
+
|
|
80
|
+
report = build_report(code, RubyLint::Analyze::ArgumentAmount)
|
|
81
|
+
|
|
82
|
+
report.entries.empty?.should == true
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
should 'not validate methods called on undefined receivers' do
|
|
86
|
+
code = 'A.example_method'
|
|
87
|
+
report = build_report(code, RubyLint::Analyze::ArgumentAmount)
|
|
88
|
+
|
|
89
|
+
report.entries.empty?.should == true
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
|
|
3
|
+
describe RubyLint::Analyze::ShadowingVariables do
|
|
4
|
+
should 'warn for shadowing outer variables' do
|
|
5
5
|
code = <<-CODE
|
|
6
6
|
number = 10
|
|
7
7
|
|
|
@@ -10,21 +10,76 @@ number = 10
|
|
|
10
10
|
end
|
|
11
11
|
CODE
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
iterator = RubyLint::Iterator.new(report)
|
|
13
|
+
report = build_report(code, RubyLint::Analyze::ShadowingVariables)
|
|
14
|
+
entry = report.entries[0]
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
iterator.bind(RubyLint::Analyze::ShadowingVariables)
|
|
19
|
-
iterator.run(tokens)
|
|
16
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
entry.line.should == 3
|
|
19
|
+
entry.column.should == 18
|
|
20
|
+
entry.message.should == 'shadowing outer local variable number'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
should 'not warn for shadowed variables in a new scope' do
|
|
24
|
+
code = <<-CODE
|
|
25
|
+
number = 10
|
|
26
|
+
|
|
27
|
+
def example
|
|
28
|
+
[10, 20].each do |number|
|
|
29
|
+
puts number
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
CODE
|
|
33
|
+
|
|
34
|
+
report = build_report(code, RubyLint::Analyze::ShadowingVariables)
|
|
35
|
+
|
|
36
|
+
report.entries.empty?.should == true
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
should 'warn when shadowing variables after a new scope' do
|
|
40
|
+
code = <<-CODE
|
|
41
|
+
number = 10
|
|
42
|
+
|
|
43
|
+
def example; end
|
|
44
|
+
|
|
45
|
+
[10, 20].each do |number|
|
|
46
|
+
puts number
|
|
47
|
+
end
|
|
48
|
+
CODE
|
|
49
|
+
|
|
50
|
+
report = build_report(code, RubyLint::Analyze::ShadowingVariables)
|
|
51
|
+
entry = report.entries[0]
|
|
52
|
+
|
|
53
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
54
|
+
|
|
55
|
+
entry.line.should == 5
|
|
56
|
+
entry.column.should == 18
|
|
57
|
+
entry.message.should == 'shadowing outer local variable number'
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
should 'not fail when re-using the same block' do
|
|
61
|
+
code = <<-CODE
|
|
62
|
+
number = 10
|
|
63
|
+
|
|
64
|
+
A::B.example do |number|
|
|
65
|
+
number
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
A::B.example do |number|
|
|
69
|
+
number
|
|
70
|
+
end
|
|
71
|
+
CODE
|
|
72
|
+
|
|
73
|
+
report = build_report(code, RubyLint::Analyze::ShadowingVariables)
|
|
74
|
+
|
|
75
|
+
report.entries.length.should == 2
|
|
76
|
+
|
|
77
|
+
first, second = report.entries
|
|
23
78
|
|
|
24
|
-
|
|
79
|
+
first.line.should == 3
|
|
80
|
+
first.column.should == 17
|
|
25
81
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
warning[:column].should == 18
|
|
82
|
+
second.line.should == 7
|
|
83
|
+
second.column.should == 17
|
|
29
84
|
end
|
|
30
85
|
end
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
require File.expand_path('../../../helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe RubyLint::Analyze::UndefinedMethods do
|
|
4
|
+
should 'add an error for calling an undefined method' do
|
|
5
|
+
report = build_report('example_method', RubyLint::Analyze::UndefinedMethods)
|
|
6
|
+
entry = report.entries[0]
|
|
7
|
+
|
|
8
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
9
|
+
|
|
10
|
+
entry.line.should == 1
|
|
11
|
+
entry.column.should == 0
|
|
12
|
+
entry.message.should == 'undefined method example_method'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
should 'add an error for calling an undefined method with a receiver' do
|
|
16
|
+
code = <<-CODE
|
|
17
|
+
class << self
|
|
18
|
+
def example_method
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
String.example_method
|
|
23
|
+
CODE
|
|
24
|
+
|
|
25
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
26
|
+
entry = report.entries[0]
|
|
27
|
+
|
|
28
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
29
|
+
|
|
30
|
+
entry.line.should == 6
|
|
31
|
+
entry.column.should == 7
|
|
32
|
+
entry.message.should == 'undefined method example_method on String'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should 'add an error for calling an undefined method on a receiver instance' do
|
|
36
|
+
code = '"hello".example_method'
|
|
37
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
38
|
+
entry = report.entries[0]
|
|
39
|
+
|
|
40
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
41
|
+
|
|
42
|
+
entry.line.should == 1
|
|
43
|
+
entry.column.should == 8
|
|
44
|
+
entry.message.should == 'undefined method example_method ' \
|
|
45
|
+
'on an instance of String'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
should 'add an error when calling a method defined in a different scope' do
|
|
49
|
+
code = <<-CODE
|
|
50
|
+
class Person
|
|
51
|
+
def name
|
|
52
|
+
return 'name'
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def greet
|
|
56
|
+
name
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
name
|
|
61
|
+
CODE
|
|
62
|
+
|
|
63
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
64
|
+
|
|
65
|
+
report.entries.length.should == 1
|
|
66
|
+
|
|
67
|
+
entry = report.entries[0]
|
|
68
|
+
|
|
69
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
70
|
+
|
|
71
|
+
entry.line.should == 11
|
|
72
|
+
entry.column.should == 0
|
|
73
|
+
entry.message.should == 'undefined method name'
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
describe 'core Ruby types' do
|
|
77
|
+
should 'not add errors for calling defined methods on a Fixnum' do
|
|
78
|
+
report = build_report('10.to_s', RubyLint::Analyze::UndefinedMethods)
|
|
79
|
+
|
|
80
|
+
report.entries.empty?.should == true
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
should 'not add errors for calling defined methods on a Float' do
|
|
84
|
+
report = build_report('(10.0).to_s', RubyLint::Analyze::UndefinedMethods)
|
|
85
|
+
|
|
86
|
+
report.entries.empty?.should == true
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
should 'not add errors for calling defined methods on a String' do
|
|
90
|
+
report = build_report('"10".to_s', RubyLint::Analyze::UndefinedMethods)
|
|
91
|
+
|
|
92
|
+
report.entries.empty?.should == true
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
should 'not add errors for calling defined methods on a Hash' do
|
|
96
|
+
report = build_report('{}.to_s', RubyLint::Analyze::UndefinedMethods)
|
|
97
|
+
|
|
98
|
+
report.entries.empty?.should == true
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
should 'not add errors for calling defined methods on an Array' do
|
|
102
|
+
report = build_report('[].to_s', RubyLint::Analyze::UndefinedMethods)
|
|
103
|
+
|
|
104
|
+
report.entries.empty?.should == true
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
should 'not add errors for variables created using blocks' do
|
|
109
|
+
code = <<-CODE
|
|
110
|
+
[10, 20].each do |number|
|
|
111
|
+
number.to_s
|
|
112
|
+
end
|
|
113
|
+
CODE
|
|
114
|
+
|
|
115
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
116
|
+
|
|
117
|
+
report.entries.empty?.should == true
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
should 'take variable assignments into account' do
|
|
121
|
+
code = <<-CODE
|
|
122
|
+
name = 'Ruby'
|
|
123
|
+
|
|
124
|
+
name.downcase
|
|
125
|
+
name.downcasex
|
|
126
|
+
CODE
|
|
127
|
+
|
|
128
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
129
|
+
|
|
130
|
+
report.entries.length.should == 1
|
|
131
|
+
|
|
132
|
+
entry = report.entries[0]
|
|
133
|
+
|
|
134
|
+
entry.line.should == 4
|
|
135
|
+
entry.column.should == 5
|
|
136
|
+
entry.message.should == 'undefined method downcasex on an instance of String'
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
should 'not add errors when calling a method on an undefined constant' do
|
|
140
|
+
code = 'A.example_method'
|
|
141
|
+
|
|
142
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
143
|
+
|
|
144
|
+
report.entries.empty?.should == true
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
should 'not add errors for methods called on variables without values' do
|
|
148
|
+
code = <<-CODE
|
|
149
|
+
def example(number)
|
|
150
|
+
number.to_s
|
|
151
|
+
end
|
|
152
|
+
CODE
|
|
153
|
+
|
|
154
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
155
|
+
|
|
156
|
+
report.entries.empty?.should == true
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
should 'report the right receiver name in multiple variable assignments' do
|
|
160
|
+
code = <<-CODE
|
|
161
|
+
number = 10
|
|
162
|
+
|
|
163
|
+
first = second = number.foobar
|
|
164
|
+
CODE
|
|
165
|
+
|
|
166
|
+
report = build_report(code, RubyLint::Analyze::UndefinedMethods)
|
|
167
|
+
|
|
168
|
+
report.entries.length.should == 1
|
|
169
|
+
|
|
170
|
+
entry = report.entries[0]
|
|
171
|
+
|
|
172
|
+
entry.message.should == 'undefined method foobar on an instance of Fixnum'
|
|
173
|
+
end
|
|
174
|
+
end
|
|
@@ -1,230 +1,121 @@
|
|
|
1
1
|
require File.expand_path('../../../helper', __FILE__)
|
|
2
2
|
|
|
3
|
-
describe
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
puts numberx
|
|
9
|
-
puts @number
|
|
10
|
-
puts @@number
|
|
11
|
-
puts $number
|
|
12
|
-
puts NUMBER
|
|
13
|
-
|
|
14
|
-
# The code below should not add any errors.
|
|
15
|
-
numberx = 10
|
|
16
|
-
@number = 10
|
|
17
|
-
@@number = 10
|
|
18
|
-
$number = 10
|
|
19
|
-
NUMBER = 10
|
|
20
|
-
|
|
21
|
-
puts numberx
|
|
22
|
-
puts @number
|
|
23
|
-
puts @@number
|
|
24
|
-
puts $number
|
|
25
|
-
puts NUMBER
|
|
26
|
-
CODE
|
|
27
|
-
|
|
28
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
29
|
-
report = RubyLint::Report.new
|
|
30
|
-
iterator = RubyLint::Iterator.new(report)
|
|
3
|
+
describe RubyLint::Analyze::UndefinedVariables do
|
|
4
|
+
should 'add an error for using an undefined instance variable' do
|
|
5
|
+
report = build_report('@number', RubyLint::Analyze::UndefinedVariables)
|
|
6
|
+
entry = report.entries[0]
|
|
31
7
|
|
|
32
|
-
|
|
33
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
34
|
-
iterator.run(tokens)
|
|
8
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
35
9
|
|
|
36
|
-
|
|
37
|
-
|
|
10
|
+
entry.line.should == 1
|
|
11
|
+
entry.column.should == 0
|
|
12
|
+
entry.message.should == 'undefined instance variable @number'
|
|
13
|
+
end
|
|
38
14
|
|
|
39
|
-
|
|
15
|
+
should 'add an error for using an undefined class variable' do
|
|
16
|
+
report = build_report('@@number', RubyLint::Analyze::UndefinedVariables)
|
|
17
|
+
entry = report.entries[0]
|
|
40
18
|
|
|
41
|
-
|
|
42
|
-
errors[0][:line].should == 3
|
|
43
|
-
errors[0][:column].should == 5
|
|
19
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
44
20
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
entry.line.should == 1
|
|
22
|
+
entry.column.should == 0
|
|
23
|
+
entry.message.should == 'undefined class variable @@number'
|
|
24
|
+
end
|
|
48
25
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
26
|
+
should 'add an error for using an undefined global variable' do
|
|
27
|
+
report = build_report('$number', RubyLint::Analyze::UndefinedVariables)
|
|
28
|
+
entry = report.entries[0]
|
|
52
29
|
|
|
53
|
-
|
|
54
|
-
errors[3][:line].should == 6
|
|
55
|
-
errors[3][:column].should == 5
|
|
30
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
56
31
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
32
|
+
entry.line.should == 1
|
|
33
|
+
entry.column.should == 0
|
|
34
|
+
entry.message.should == 'undefined global variable $number'
|
|
60
35
|
end
|
|
61
36
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
report = RubyLint::Report.new
|
|
66
|
-
iterator = RubyLint::Iterator.new(report)
|
|
37
|
+
should 'add an error for using an undefined constant' do
|
|
38
|
+
report = build_report('NUMBER', RubyLint::Analyze::UndefinedVariables)
|
|
39
|
+
entry = report.entries[0]
|
|
67
40
|
|
|
68
|
-
|
|
69
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
70
|
-
iterator.run(tokens)
|
|
41
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
71
42
|
|
|
72
|
-
|
|
43
|
+
entry.line.should == 1
|
|
44
|
+
entry.column.should == 0
|
|
45
|
+
entry.message.should == 'undefined constant NUMBER'
|
|
73
46
|
end
|
|
74
47
|
|
|
75
|
-
|
|
48
|
+
should 'add an error for using an undefined constant in a constant path' do
|
|
76
49
|
code = <<-CODE
|
|
77
|
-
|
|
78
|
-
|
|
50
|
+
# This is to ensure that the on_constant() callback isn't used to check for "B"
|
|
51
|
+
# in the global scope.
|
|
52
|
+
B = 10
|
|
79
53
|
|
|
80
|
-
|
|
81
|
-
b = 10
|
|
82
|
-
|
|
83
|
-
puts @a # @a should be available as it's an instance method
|
|
84
|
-
puts a # a is defined outside of this scope
|
|
85
|
-
puts c # c simply doesn't exist
|
|
54
|
+
module A
|
|
86
55
|
end
|
|
87
56
|
|
|
88
|
-
|
|
89
|
-
puts b # b was defined inside the method and isn't available outside it
|
|
57
|
+
A::B
|
|
90
58
|
CODE
|
|
91
59
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
iterator = RubyLint::Iterator.new(report)
|
|
95
|
-
|
|
96
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
97
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
98
|
-
iterator.run(tokens)
|
|
99
|
-
|
|
100
|
-
report.messages[:error].class.should == Array
|
|
101
|
-
report.messages[:error].length.should == 3
|
|
60
|
+
report = build_report(code, RubyLint::Analyze::UndefinedVariables)
|
|
61
|
+
entry = report.entries[0]
|
|
102
62
|
|
|
103
|
-
|
|
63
|
+
entry.is_a?(RubyLint::Report::Entry).should == true
|
|
104
64
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
errors[1][:message].should == 'undefined local variable or method c'
|
|
110
|
-
errors[1][:line].should == 9
|
|
111
|
-
errors[1][:column].should == 7
|
|
112
|
-
|
|
113
|
-
errors[2][:message].should == 'undefined local variable or method b'
|
|
114
|
-
errors[2][:line].should == 13
|
|
115
|
-
errors[2][:column].should == 5
|
|
65
|
+
entry.line.should == 8
|
|
66
|
+
entry.column.should == 3
|
|
67
|
+
entry.message.should == 'undefined constant B'
|
|
116
68
|
end
|
|
117
69
|
|
|
118
|
-
|
|
119
|
-
code
|
|
120
|
-
|
|
121
|
-
@number = 10
|
|
122
|
-
end
|
|
70
|
+
should 'add an error when the entire constant path does not exist' do
|
|
71
|
+
code = 'A::B::C'
|
|
72
|
+
report = build_report(code, RubyLint::Analyze::UndefinedVariables)
|
|
123
73
|
|
|
124
|
-
|
|
125
|
-
CODE
|
|
74
|
+
report.entries.length.should == 1
|
|
126
75
|
|
|
127
|
-
|
|
128
|
-
report = RubyLint::Report.new
|
|
129
|
-
iterator = RubyLint::Iterator.new(report)
|
|
76
|
+
entry = report.entries[0]
|
|
130
77
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
report.messages[:error].nil?.should == true
|
|
78
|
+
entry.line.should == 1
|
|
79
|
+
entry.column.should == 0
|
|
80
|
+
entry.message.should == 'undefined constant A'
|
|
136
81
|
end
|
|
137
82
|
|
|
138
|
-
|
|
83
|
+
should 'not depend on the order of variable definitions' do
|
|
139
84
|
code = <<-CODE
|
|
140
85
|
class Person
|
|
141
|
-
def
|
|
142
|
-
@
|
|
86
|
+
def first
|
|
87
|
+
@number = 10
|
|
143
88
|
end
|
|
144
89
|
|
|
145
|
-
def
|
|
146
|
-
@
|
|
147
|
-
@namex.upcase
|
|
90
|
+
def second
|
|
91
|
+
return @number
|
|
148
92
|
end
|
|
149
93
|
end
|
|
150
94
|
CODE
|
|
151
95
|
|
|
152
|
-
|
|
153
|
-
report = RubyLint::Report.new
|
|
154
|
-
iterator = RubyLint::Iterator.new(report)
|
|
155
|
-
|
|
156
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
157
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
158
|
-
iterator.run(tokens)
|
|
159
|
-
|
|
160
|
-
report.messages[:error].class.should == Array
|
|
161
|
-
report.messages[:error].length.should == 1
|
|
162
|
-
|
|
163
|
-
error = report.messages[:error][0]
|
|
96
|
+
report = build_report(code, RubyLint::Analyze::UndefinedVariables)
|
|
164
97
|
|
|
165
|
-
|
|
166
|
-
error[:line].should == 8
|
|
167
|
-
error[:column].should == 4
|
|
98
|
+
report.entries.empty?.should == true
|
|
168
99
|
end
|
|
169
100
|
|
|
170
|
-
|
|
171
|
-
code
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
module A
|
|
175
|
-
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
puts A::B
|
|
179
|
-
CODE
|
|
180
|
-
|
|
181
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
182
|
-
report = RubyLint::Report.new
|
|
183
|
-
iterator = RubyLint::Iterator.new(report)
|
|
184
|
-
|
|
185
|
-
iterator.bind(RubyLint::Analyze::Definitions)
|
|
186
|
-
iterator.bind(RubyLint::Analyze::UndefinedVariables)
|
|
187
|
-
iterator.run(tokens)
|
|
101
|
+
should 'not add errors when autoloading constants' do
|
|
102
|
+
code = 'Encoding::BIG5'
|
|
103
|
+
report = build_report(code, RubyLint::Analyze::UndefinedVariables)
|
|
188
104
|
|
|
189
|
-
report.
|
|
190
|
-
report.messages[:error].length.should == 2
|
|
191
|
-
|
|
192
|
-
errors = report.messages[:error]
|
|
193
|
-
|
|
194
|
-
errors[0][:message].should == 'undefined constant A'
|
|
195
|
-
errors[0][:line].should == 1
|
|
196
|
-
errors[0][:column].should == 0
|
|
197
|
-
|
|
198
|
-
errors[1][:message].should == 'undefined constant A::B'
|
|
199
|
-
errors[1][:line].should == 7
|
|
200
|
-
errors[1][:column].should == 5
|
|
105
|
+
report.entries.empty?.should == true
|
|
201
106
|
end
|
|
202
107
|
|
|
203
|
-
|
|
108
|
+
should 'not error when inheriting data in a block' do
|
|
204
109
|
code = <<-CODE
|
|
205
|
-
|
|
206
|
-
module Derp
|
|
207
|
-
Foobar.name
|
|
208
|
-
ConstantImporter.name
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
CODE
|
|
212
|
-
|
|
213
|
-
tokens = RubyLint::Parser.new(code).parse
|
|
214
|
-
report = RubyLint::Report.new
|
|
215
|
-
iterator = RubyLint::Iterator.new(report)
|
|
110
|
+
NUMBER = 10
|
|
216
111
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
report.messages[:error].class.should == Array
|
|
222
|
-
report.messages[:error].length.should == 1
|
|
112
|
+
example_method do
|
|
113
|
+
NUMBER
|
|
114
|
+
end
|
|
115
|
+
CODE
|
|
223
116
|
|
|
224
|
-
|
|
117
|
+
report = build_report(code, RubyLint::Analyze::UndefinedVariables)
|
|
225
118
|
|
|
226
|
-
|
|
227
|
-
error[:line].should == 3
|
|
228
|
-
error[:column].should == 4
|
|
119
|
+
report.entries.empty?.should == true
|
|
229
120
|
end
|
|
230
121
|
end
|