excellent 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,15 @@
1
1
  =======
2
+ = 1.7.2
3
+
4
+ * fixed Simplabs::Excellent::Checks::Rails::CustomInitializeMethodCheck
5
+ * fixed Simplabs::Excellent::Checks::MethodNameCheck so it allows method names that exist in Ruby itself
6
+ * fixed Simplabs::Excellent::Checks::GlobalVariableCheck so it doesn't report false positives for rescue bodies
7
+
2
8
  = 1.7.1
3
9
 
4
10
  * fixed excellent for Ruby 2.0
5
11
  * some internal cleanup
12
+ * support -v switch on command line
6
13
 
7
14
  = 1.7.0
8
15
 
@@ -1,4 +1,4 @@
1
- ---
1
+ ---
2
2
  :major: 1
3
- :minor: 5
4
- :patch: 4
3
+ :minor: 7
4
+ :patch: 2
@@ -9,7 +9,7 @@ module Simplabs #:nodoc:
9
9
 
10
10
  module Excellent #:nodoc:
11
11
 
12
- VERSION = '1.7.1'
12
+ VERSION = '1.7.2'
13
13
 
14
14
  end
15
15
 
@@ -21,7 +21,9 @@ module Simplabs
21
21
  end
22
22
 
23
23
  def evaluate(context) #:nodoc:
24
- add_warning(context, 'Global variable {{variable}} used.', { :variable => context.full_name })
24
+ if context.is_a?(Parsing::GasgnContext) || !context.reassigned_local_exception_var?
25
+ add_warning(context, 'Global variable {{variable}} used.', { :variable => context.full_name })
26
+ end
25
27
  end
26
28
 
27
29
  end
@@ -17,10 +17,11 @@ module Simplabs
17
17
  class MethodNameCheck < NameCheck
18
18
 
19
19
  DEFAULT_PATTERN = /^[_a-z<>=\[|+-\/\*\~\%\&`\|\^]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/
20
+ WHITELIST = %w([] ! != !~ % & * ** + +@ - -@ / < << <= <=> == === =~ > >= >> ^ ` | ~)
20
21
 
21
22
  def initialize(options = {}) #:nodoc:
22
23
  pattern = options['pattern'] || DEFAULT_PATTERN
23
- super([Parsing::MethodContext, Parsing::SingletonMethodContext], pattern)
24
+ super([Parsing::MethodContext, Parsing::SingletonMethodContext], pattern, WHITELIST)
24
25
  end
25
26
 
26
27
  protected
@@ -8,14 +8,18 @@ module Simplabs
8
8
 
9
9
  class NameCheck < Base #:nodoc:
10
10
 
11
- def initialize(interesting_contexts, pattern)
11
+ def initialize(interesting_contexts, pattern, whitelist = [])
12
12
  super()
13
13
  @interesting_contexts = interesting_contexts
14
14
  @pattern = pattern
15
+ @whitelist = whitelist
15
16
  end
16
17
 
17
18
  def evaluate(context)
18
- add_warning(*warning_args(context)) unless context.name.to_s =~ @pattern
19
+ name = context.name.to_s
20
+ if !@whitelist.include?(name) && !(name =~ @pattern)
21
+ add_warning(*warning_args(context))
22
+ end
19
23
  end
20
24
 
21
25
  end
@@ -23,7 +23,7 @@ module Simplabs
23
23
  end
24
24
 
25
25
  def evaluate(context) #:nodoc:
26
- add_warning(context, '{{class}} defines initialize method.', { :class => context.full_name }) if context.active_record_model? && !context.defines_initializer?
26
+ add_warning(context, '{{class}} defines initialize method.', { :class => context.full_name }) if context.active_record_model? && context.defines_initializer?
27
27
  end
28
28
 
29
29
  end
@@ -70,7 +70,7 @@ module Simplabs
70
70
  end
71
71
 
72
72
  def process_defn(exp)
73
- @initializer = true if exp[2] == :initialize
73
+ @initializer = exp[1] == :initialize
74
74
  super
75
75
  end
76
76
 
@@ -12,7 +12,7 @@ module Simplabs
12
12
 
13
13
  def contains_parameter?
14
14
  return false unless @parent.is_a?(MethodContext)
15
- return @exp[1][1] if @exp[1][0] == :lvar and @parent.has_parameter?(@exp[1][1])
15
+ return @exp[1][1] if !!@exp[1] && @exp[1][0] == :lvar and @parent.has_parameter?(@exp[1][1])
16
16
  false
17
17
  end
18
18
 
@@ -15,8 +15,12 @@ module Simplabs
15
15
  return @name if !@parent
16
16
  full_name = @name
17
17
  parent = @parent
18
- parent = parent.parent until parent.is_a?(ClassContext) || parent.is_a?(ModuleContext)
19
- full_name = "#{parent.full_name}.#{full_name}"
18
+ parent = parent.parent until parent.is_a?(ClassContext) || parent.is_a?(ModuleContext) rescue nil
19
+ if !!parent
20
+ "#{parent.full_name}.#{full_name}"
21
+ else
22
+ full_name
23
+ end
20
24
  end
21
25
 
22
26
  end
@@ -12,6 +12,14 @@ module Simplabs
12
12
  @full_name = @name
13
13
  end
14
14
 
15
+ def reassigned_local_exception_var?
16
+ if self.parent.is_a?(Simplabs::Excellent::Parsing::ResbodyContext)
17
+ @name == '!' && self.parent.assigns_exception_to_local_variable?.inspect
18
+ else
19
+ false
20
+ end
21
+ end
22
+
15
23
  end
16
24
 
17
25
  end
@@ -17,6 +17,12 @@ module Simplabs
17
17
  @contains_statements
18
18
  end
19
19
 
20
+ def assigns_exception_to_local_variable?
21
+ @exp[1][2].node_type == :lasgn && @exp[1][2][2].to_a == [:gvar, :$!]
22
+ rescue
23
+ false
24
+ end
25
+
20
26
  private
21
27
 
22
28
  def contains_statements?(exp = @exp)
metadata CHANGED
@@ -1,61 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: excellent
3
- version: !ruby/object:Gem::Version
4
- hash: 9
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.7.2
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 7
9
- - 1
10
- version: 1.7.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Marco Otte-Witte
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2009-08-05 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2009-08-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: ruby_parser
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
- version: "3.0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: sexp_processor
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sexp_processor
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 27
44
- segments:
45
- - 4
46
- - 0
47
- version: "4.0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '4.0'
48
38
  type: :runtime
49
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '4.0'
50
46
  description:
51
47
  email: marco.otte-witte@simplabs.com
52
- executables:
48
+ executables:
53
49
  - excellent
54
50
  extensions: []
55
-
56
51
  extra_rdoc_files: []
57
-
58
- files:
52
+ files:
59
53
  - History.txt
60
54
  - README.rdoc
61
55
  - VERSION.yml
@@ -164,37 +158,29 @@ files:
164
158
  - spec/spec_helper.rb
165
159
  homepage: http://github.com/simplabs/excellent
166
160
  licenses: []
167
-
168
161
  post_install_message:
169
- rdoc_options:
162
+ rdoc_options:
170
163
  - --inline-source
171
164
  - --charset=UTF-8
172
- require_paths:
165
+ require_paths:
173
166
  - lib
174
- required_ruby_version: !ruby/object:Gem::Requirement
167
+ required_ruby_version: !ruby/object:Gem::Requirement
175
168
  none: false
176
- requirements:
177
- - - ">="
178
- - !ruby/object:Gem::Version
179
- hash: 3
180
- segments:
181
- - 0
182
- version: "0"
183
- required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ! '>='
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
174
  none: false
185
- requirements:
186
- - - ">="
187
- - !ruby/object:Gem::Version
188
- hash: 3
189
- segments:
190
- - 0
191
- version: "0"
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
192
179
  requirements: []
193
-
194
180
  rubyforge_project:
195
- rubygems_version: 1.8.15
181
+ rubygems_version: 1.8.23
196
182
  signing_key:
197
183
  specification_version: 2
198
184
  summary: Source Code analysis gem for Ruby and Rails
199
185
  test_files: []
200
-
186
+ has_rdoc: true