ruby-lint 1.0.0 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47ffb8ab07bc9826ae519c992503c8c51659d042
4
- data.tar.gz: bf6192f271bcce9c7db189a62c6eae8771302d6f
3
+ metadata.gz: 5e5bbee286e1be1ba6f024458ccf916d7aaa6f6d
4
+ data.tar.gz: 62be929b8a02f3e9fc701d3a9d5cc979d69614d1
5
5
  SHA512:
6
- metadata.gz: 1497ad0011b0afb381368bd0142cef4c89393a73dbbfd8d1586433c616e6fc5cb05b9309667d56fc79fb2df4e5e8d2b25a369483a358f99e538a3690557b3ab0
7
- data.tar.gz: 3f96aff18f82c1d2814fd46b85f3d263323fb695638e29965fabcd7a046a8c27290e5d470da35247a08ab4df2298641fd7ef68f34310cb99da70bf57dc1f45ce
6
+ metadata.gz: 45574e47f9dcb4017f64f80fd89bc8d7b10bffdbb4648ed3cc42b09373e04e3dd413a3ed4e68e84736082a1c377f0d6ce61b6b8729ef848bb26f0f4b4ce5574e
7
+ data.tar.gz: ab7b40f9108af2d2d6879ccfddf806cff09f413f9fd6adc4d499d874934a266be36d6884eb9629761c8dbc86d14559171cc8ef3863e6a3faffedc4f94e2a2494
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- script: rake travis
2
+ script: bundle exec rake travis
3
3
 
4
4
  rvm:
5
5
  - 1.9.3
@@ -18,3 +18,5 @@ notifications:
18
18
  branches:
19
19
  only:
20
20
  - master
21
+
22
+ cache: bundler
data/MANIFEST CHANGED
@@ -18,6 +18,7 @@ checksum/ruby-lint-0.0.4.gem.sha512
18
18
  checksum/ruby-lint-0.0.5.gem.sha512
19
19
  checksum/ruby-lint-0.9.0.gem.sha512
20
20
  checksum/ruby-lint-0.9.1.gem.sha512
21
+ checksum/ruby-lint-1.0.0.gem.sha512
21
22
  checksum/ruby-lint-1.0.0.pre.preview1.gem.sha512
22
23
  doc/.gitkeep
23
24
  doc/DCO.md
@@ -382,6 +383,8 @@ spec/ruby-lint/definition_builder/primitive_spec.rb
382
383
  spec/ruby-lint/definition_builder/ruby_class_spec.rb
383
384
  spec/ruby-lint/definition_builder/ruby_method_spec.rb
384
385
  spec/ruby-lint/definition_builder/ruby_module_spec.rb
386
+ spec/ruby-lint/definitions/argv_spec.rb
387
+ spec/ruby-lint/definitions/env_spec.rb
385
388
  spec/ruby-lint/definitions/io_spec.rb
386
389
  spec/ruby-lint/docstring/mapping.rb
387
390
  spec/ruby-lint/docstring/parser_spec.rb
@@ -390,6 +393,7 @@ spec/ruby-lint/file_loader_spec.rb
390
393
  spec/ruby-lint/file_scanner_spec.rb
391
394
  spec/ruby-lint/inspector_spec.rb
392
395
  spec/ruby-lint/iterator_spec.rb
396
+ spec/ruby-lint/method_call/assign_member_spec.rb
393
397
  spec/ruby-lint/nested_stack_spec.rb
394
398
  spec/ruby-lint/node_hash_spec.rb
395
399
  spec/ruby-lint/parser_spec.rb
data/README.md CHANGED
@@ -38,21 +38,6 @@ so as following:
38
38
 
39
39
  This builds a new version of the Gem and saves it in the pkg/ directory.
40
40
 
41
- ## Security
42
-
43
- As a basic form of security ruby-lint provides a set of SHA512 checksums for
44
- every Gem release. These checksums can be found in the `checksum/` directory.
45
- Although these checksums do not prevent malicious users from tampering with a
46
- built Gem they can be used for basic integrity verification purposes.
47
-
48
- The checksum of a file can be checked using the `sha512sum` command. For
49
- example:
50
-
51
- $ sha512sum pkg/ruby-lint-0.9.1.gem
52
- 10a51f27c455e5743fff7fefe29512cff20116b805bec148e09d4bade1727e3beab7f7f9ee97b020d290773edcb7bd1685858ccad0bbd1a35cc0282c00c760c6 pkg/ruby-lint-0.9.1.gem
53
-
54
- In the past Gems were also signed using PGP, this is no longer the case.
55
-
56
41
  ## Usage
57
42
 
58
43
  Using ruby-lint from the CLI is very easy. To analyze a set of files
@@ -88,6 +73,50 @@ the following output:
88
73
  test.rb: warning: line 12, column 1: unused local variable greeting
89
74
  test.rb: error: line 14, column 1: wrong number of arguments (expected 0 but got 1)
90
75
 
76
+ ## Integration
77
+
78
+ * Vim using [Syntastic][syntastic]
79
+ * Emacs using [Flycheck][flycheck]
80
+
81
+ ## ruby-lint versus Rubocop
82
+
83
+ A question commonly asked is what purpose ruby-lint serves compared to other
84
+ tools such as [Rubocop][rubocop]. After all, upon first sight the two tools
85
+ look pretty similar.
86
+
87
+ The big difference between ruby-lint and Rubocop is that ruby-lint focuses
88
+ primarily on technical problems such as the use of undefined methods/variables,
89
+ unused variables/method arguments and more. Rubocop on the other hand focuses
90
+ mostly on style related issues based on a community driven Ruby style guide.
91
+ This means that it will for example warn you about methods written using
92
+ camelCase and method bodies that are considered to be too long.
93
+
94
+ Personally I have little interest in adding style related analysis as Rubocop
95
+ already does that and in my opinion does a far better job at it. I also simply
96
+ think it's too boring to write analysis like this. Having said that, ruby-lint
97
+ has some basic style related analysis (e.g. the use of `BEGIN`) but this mostly
98
+ serves as a simple example on how to write analysis code.
99
+
100
+ In the end it depends on what your needs are. If you have a team that's having
101
+ trouble following a consistent coding style then Rubocop is probably the right
102
+ tool for the job. On the other hand, if you're trying to debug a nasty bug then
103
+ ruby-lint will most likely be more useful.
104
+
105
+ ## Security
106
+
107
+ As a basic form of security ruby-lint provides a set of SHA512 checksums for
108
+ every Gem release. These checksums can be found in the `checksum/` directory.
109
+ Although these checksums do not prevent malicious users from tampering with a
110
+ built Gem they can be used for basic integrity verification purposes.
111
+
112
+ The checksum of a file can be checked using the `sha512sum` command. For
113
+ example:
114
+
115
+ $ sha512sum pkg/ruby-lint-0.9.1.gem
116
+ 10a51f27c455e5743fff7fefe29512cff20116b805bec148e09d4bade1727e3beab7f7f9ee97b020d290773edcb7bd1685858ccad0bbd1a35cc0282c00c760c6 pkg/ruby-lint-0.9.1.gem
117
+
118
+ In the past Gems were also signed using PGP, this is no longer the case.
119
+
91
120
  ## Documentation
92
121
 
93
122
  * {file:contributing Contributing}
@@ -100,3 +129,7 @@ the following output:
100
129
  All source code in this repository is licensed under the MIT license unless
101
130
  specified otherwise. A copy of this license can be found in the file "LICENSE"
102
131
  in the root directory of this repository.
132
+
133
+ [syntastic]: https://github.com/scrooloose/syntastic
134
+ [flycheck]: https://github.com/flycheck/flycheck/
135
+ [rubocop]: https://github.com/bbatsov/rubocop
@@ -0,0 +1 @@
1
+ d02899dc114e6065d64bb5e8aed5735876740209d30c5549511d88d8966b3c0794f0bb16ed33a430829b918eba56e2764f91a51c299da47393c6256cf3cc9f62
data/doc/changelog.md CHANGED
@@ -5,6 +5,21 @@ This document contains a short summary of the various releases of ruby-lint.
5
5
  For a full list of commits included in each release see the corresponding Git
6
6
  tags (named after the versions).
7
7
 
8
+ ## 1.0.1 - 2013-12-15
9
+
10
+ A small bugfix release that contains the following changes/fixes:
11
+
12
+ * Anonymous splat arguments (`def foo(_); end`) are now ignored by the
13
+ `UnusedVariables` class.
14
+ * Frozen definitions no longer have their members updated, see
15
+ <https://github.com/YorickPeterse/ruby-lint/issues/75> for more information.
16
+ * ENV is now treated as an instance.
17
+ * When re-assigning a variable the VM now updates the corresponding definition
18
+ instead of overwriting it. This was added to fix
19
+ <https://github.com/YorickPeterse/ruby-lint/issues/77>.
20
+ * Global variables are stored in the global scope opposed to the current scope.
21
+ * ARGV is now treated as an instance and extends Array.
22
+
8
23
  ## 1.0.0 - 2013-12-01
9
24
 
10
25
  The first stable release of ruby-lint. The 1.0 series will not introduce any
@@ -82,7 +82,15 @@ module RubyLint
82
82
  # @return [TrueClass|FalseClass]
83
83
  #
84
84
  def add_warning?(variable)
85
- return variable && !variable.used? && variable.name[0] != '_'
85
+ return variable && !variable.used? && !ignore_variable?(variable.name)
86
+ end
87
+
88
+ ##
89
+ # @param [String] name
90
+ # @return [TrueClass|FalseClass]
91
+ #
92
+ def ignore_variable?(name)
93
+ return name[0] == '_' || name.empty?
86
94
  end
87
95
  end # UnusedVariables
88
96
  end # Analysis
@@ -4,6 +4,8 @@
4
4
  # Platform: rbx 2.0.0.rc1
5
5
  #
6
6
  RubyLint::GlobalScope.definitions.define_constant('ARGV') do |klass|
7
+ klass.inherits(RubyLint::GlobalScope.constant_proxy('Array'))
8
+ klass.instance!
7
9
  end
8
10
 
9
- RubyLint::GlobalScope.definitions.lookup(:const, 'ARGV').deep_freeze
11
+ RubyLint::GlobalScope.definitions.lookup(:const, 'ARGV').deep_freeze
@@ -5,6 +5,8 @@
5
5
  #
6
6
  RubyLint::GlobalScope.definitions.define_constant('ENV') do |klass|
7
7
  klass.inherits(RubyLint::GlobalScope.constant_proxy('Hash'))
8
+
9
+ klass.instance!
8
10
  end
9
11
 
10
12
  RubyLint::GlobalScope.definitions.lookup(:const, 'ENV').deep_freeze
@@ -12,6 +12,8 @@ module RubyLint
12
12
  # @see Base#evaluate
13
13
  #
14
14
  def evaluate(arguments, context, block = nil)
15
+ return if context.frozen?
16
+
15
17
  *members, values = arguments
16
18
  member_values = prepare_values(values)
17
19
 
@@ -1,3 +1,3 @@
1
1
  module RubyLint
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end # RubyLint
@@ -141,6 +141,13 @@ module RubyLint
141
141
  #
142
142
  EXPORT_VARIABLES = [:ivar, :cvar, :const]
143
143
 
144
+ ##
145
+ # List of variable types that should be assigned in the global scope.
146
+ #
147
+ # @return [Array]
148
+ #
149
+ ASSIGN_GLOBAL = [:gvar]
150
+
144
151
  ##
145
152
  # The available method visibilities.
146
153
  #
@@ -874,28 +881,48 @@ Received: #{arguments.length}
874
881
  # @param [RubyLint::AST::Node] node
875
882
  #
876
883
  def assign_variable(type, name, value, node)
877
- existing = current_scope.lookup(type, name)
878
- ref_amount = existing ? existing.reference_amount + 1 : 0
879
- variable = Definition::RubyObject.new(
880
- :type => type,
881
- :name => name,
882
- :value => value,
883
- :instance_type => :instance,
884
- :reference_amount => ref_amount,
885
- :line => node.line,
886
- :column => node.column,
887
- :file => node.file
888
- )
884
+ scope = assignment_scope(type)
885
+ variable = scope.lookup(type, name)
886
+
887
+ # If there's already a variable we'll just update it.
888
+ if variable
889
+ variable.reference_amount += 1
890
+
891
+ # `value` is not for conditional assignments as those are handled
892
+ # manually.
893
+ variable.value = value if value
894
+ else
895
+ variable = Definition::RubyObject.new(
896
+ :type => type,
897
+ :name => name,
898
+ :value => value,
899
+ :instance_type => :instance,
900
+ :reference_amount => 0,
901
+ :line => node.line,
902
+ :column => node.column,
903
+ :file => node.file
904
+ )
905
+ end
889
906
 
890
- buffer_assignment_value(variable.value)
907
+ buffer_assignment_value(value)
891
908
 
892
909
  # Primarily used by #after_send to support variable assignments as method
893
910
  # call arguments.
894
911
  if value and !value_stack.empty?
895
- value_stack.push(value)
912
+ value_stack.push(variable.value)
896
913
  end
897
914
 
898
- add_variable(variable)
915
+ add_variable(variable, scope)
916
+ end
917
+
918
+ ##
919
+ # Determines the scope to use for a variable assignment.
920
+ #
921
+ # @param [Symbol] type
922
+ # @return [RubyLint::Definition::RubyObject]
923
+ #
924
+ def assignment_scope(type)
925
+ return ASSIGN_GLOBAL.include?(type) ? definitions : current_scope
899
926
  end
900
927
 
901
928
  ##
@@ -227,6 +227,17 @@ end
227
227
 
228
228
  report.entries.empty?.should == true
229
229
  end
230
+
231
+ example 'do not warn for unused anonymous splat arguments' do
232
+ code = <<-CODE
233
+ def example(*)
234
+ end
235
+ CODE
236
+
237
+ report = build_report(code, RubyLint::Analysis::UnusedVariables)
238
+
239
+ report.entries.empty?.should == true
240
+ end
230
241
  end
231
242
 
232
243
  context 'block arguments' do
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ruby-lint definitions' do
4
+ context 'ARGV' do
5
+ before do
6
+ @const = RubyLint::GlobalScope.global_constant('ARGV')
7
+ end
8
+
9
+ example 'treat ARGV as an instance' do
10
+ @const.instance?.should == true
11
+ end
12
+
13
+ example 'ARGV should be an Array' do
14
+ @const.has_definition?(:instance_method, 'each').should == true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'ruby-lint definitions' do
4
+ context 'ENV' do
5
+ example 'treat ENV as an instance' do
6
+ const = RubyLint::GlobalScope.global_constant('ENV')
7
+
8
+ const.instance?.should == true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe RubyLint::MethodCall::AssignMember do
4
+ before do
5
+ @vm = RubyLint::VirtualMachine.new
6
+ @node = s(:send,
7
+ s(:const, nil, :ENV), :[]=, s(:str, 'FOO'), s(:str, 'bar')
8
+ )
9
+
10
+ @method_call = RubyLint::MethodCall::AssignMember.new(@node, @vm)
11
+ @arguments = [
12
+ ruby_object.new(:type => :str, :value => 'FOO'),
13
+ ruby_object.new(:type => :str, :value => 'bar')
14
+ ]
15
+
16
+ @context = ruby_object.new(:type => :hash)
17
+ @context.deep_freeze
18
+ end
19
+
20
+ example 'do not update members of frozen definitions' do
21
+ @method_call.evaluate(@arguments, @context)
22
+
23
+ @context.has_definition?(:member, 'FOO').should == false
24
+ end
25
+ end
@@ -112,5 +112,19 @@ d = c
112
112
 
113
113
  value.type.should == :unknown
114
114
  end
115
+
116
+ example 'global variables should be assigned in the global scope' do
117
+ code = <<-CODE
118
+ class Foo
119
+ def foo
120
+ $bar = 10
121
+ end
122
+ end
123
+ CODE
124
+
125
+ defs = build_definitions(code)
126
+
127
+ defs.lookup(:gvar, '$bar').value.value.should == 10
128
+ end
115
129
  end
116
130
  end
@@ -57,5 +57,25 @@ number = 20
57
57
 
58
58
  defs.lookup(:lvar, 'number').reference_amount.should == 1
59
59
  end
60
+
61
+ example 'track ivar references in parent scopes' do
62
+ code = <<-CODE
63
+ def first
64
+ @number = 10
65
+ end
66
+
67
+ def second
68
+ @number = 20
69
+ @number
70
+ end
71
+ CODE
72
+
73
+ defs = build_definitions(code)
74
+ first = defs.lookup(:instance_method, 'first').lookup(:ivar, '@number')
75
+ second = defs.lookup(:instance_method, 'second').lookup(:ivar, '@number')
76
+
77
+ first.reference_amount.should == 2
78
+ second.reference_amount.should == 2
79
+ end
60
80
  end
61
81
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yorick Peterse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-01 00:00:00.000000000 Z
11
+ date: 2013-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -211,6 +211,7 @@ files:
211
211
  - checksum/ruby-lint-0.0.5.gem.sha512
212
212
  - checksum/ruby-lint-0.9.0.gem.sha512
213
213
  - checksum/ruby-lint-0.9.1.gem.sha512
214
+ - checksum/ruby-lint-1.0.0.gem.sha512
214
215
  - checksum/ruby-lint-1.0.0.pre.preview1.gem.sha512
215
216
  - doc/.gitkeep
216
217
  - doc/DCO.md
@@ -575,6 +576,8 @@ files:
575
576
  - spec/ruby-lint/definition_builder/ruby_class_spec.rb
576
577
  - spec/ruby-lint/definition_builder/ruby_method_spec.rb
577
578
  - spec/ruby-lint/definition_builder/ruby_module_spec.rb
579
+ - spec/ruby-lint/definitions/argv_spec.rb
580
+ - spec/ruby-lint/definitions/env_spec.rb
578
581
  - spec/ruby-lint/definitions/io_spec.rb
579
582
  - spec/ruby-lint/docstring/mapping.rb
580
583
  - spec/ruby-lint/docstring/parser_spec.rb
@@ -583,6 +586,7 @@ files:
583
586
  - spec/ruby-lint/file_scanner_spec.rb
584
587
  - spec/ruby-lint/inspector_spec.rb
585
588
  - spec/ruby-lint/iterator_spec.rb
589
+ - spec/ruby-lint/method_call/assign_member_spec.rb
586
590
  - spec/ruby-lint/nested_stack_spec.rb
587
591
  - spec/ruby-lint/node_hash_spec.rb
588
592
  - spec/ruby-lint/parser_spec.rb
@@ -680,7 +684,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
680
684
  version: '0'
681
685
  requirements: []
682
686
  rubyforge_project:
683
- rubygems_version: 2.1.11
687
+ rubygems_version: 2.0.14
684
688
  signing_key:
685
689
  specification_version: 4
686
690
  summary: A linter and static code analysis tool for Ruby.