flog 3.0.0 → 3.1.0

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.sig CHANGED
Binary file
@@ -1,3 +1,17 @@
1
+ === 3.1.0 / 2012-11-16
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * --quiet option is now false by default, and changed to silence parse warnings.
6
+ * Added max_score and max_method. (aselder)
7
+ * FlogTask can now take a method to use to figure out score, allowing for total or max_score.
8
+ * Switched to capturing RubyParser::SyntaxError (RP 3.0 change).
9
+
10
+ * 2 bug fixes:
11
+
12
+ * Avoid redefined warning for File::RUBY19. (svendahlstrand)
13
+ * Fixed flog to default to RubyParser if not specified. Allows cleaner programmatic access.
14
+
1
15
  === 3.0.0 / 2012-11-02
2
16
 
3
17
  * 1 minor enhancement:
data/Rakefile CHANGED
@@ -17,6 +17,9 @@ Hoe.spec 'flog' do
17
17
 
18
18
  self.rubyforge_name = 'seattlerb'
19
19
 
20
+ self.flog_method = :max_method
21
+ self.flog_threshold = timebomb 150, 50, '2013-11-01', '2012-11-01'
22
+
20
23
  dependency 'sexp_processor', '~> 4.0'
21
24
  dependency 'ruby_parser', '~> 3.0.0'
22
25
  end
@@ -5,7 +5,7 @@ require 'optparse'
5
5
  require 'timeout'
6
6
 
7
7
  class File
8
- RUBY19 = "<3".respond_to? :encoding
8
+ RUBY19 = "<3".respond_to? :encoding unless defined? RUBY19
9
9
 
10
10
  class << self
11
11
  alias :binread :read unless RUBY19
@@ -13,7 +13,7 @@ class File
13
13
  end
14
14
 
15
15
  class Flog < SexpProcessor
16
- VERSION = '3.0.0'
16
+ VERSION = '3.1.0'
17
17
 
18
18
  THRESHOLD = 0.60
19
19
  SCORES = Hash.new 1
@@ -132,7 +132,7 @@ class Flog < SexpProcessor
132
132
 
133
133
  def self.parse_options args = ARGV
134
134
  option = {
135
- :quiet => true,
135
+ :quiet => false,
136
136
  :continue => false,
137
137
  :parser => RubyParser,
138
138
  }
@@ -175,7 +175,7 @@ class Flog < SexpProcessor
175
175
  option[:methods] = true
176
176
  end
177
177
 
178
- opts.on("-q", "--quiet", "Don't show method details. [default]") do
178
+ opts.on("-q", "--quiet", "Don't show parse errors.") do
179
179
  option[:quiet] = true
180
180
  end
181
181
 
@@ -256,7 +256,7 @@ class Flog < SexpProcessor
256
256
  ruby = file == '-' ? $stdin.read : File.binread(file)
257
257
  warn "** flogging #{file}" if option[:verbose]
258
258
 
259
- @parser = option[:parser].new
259
+ @parser = (option[:parser] || RubyParser).new
260
260
 
261
261
  begin
262
262
  ast = @parser.process(ruby, file)
@@ -267,18 +267,21 @@ class Flog < SexpProcessor
267
267
  next unless ast
268
268
  mass[file] = ast.mass
269
269
  process ast
270
- rescue RegexpError, SyntaxError, Racc::ParseError => e
270
+ rescue RubyParser::SyntaxError, Racc::ParseError => e
271
+ q = option[:quiet]
271
272
  if e.inspect =~ /<\%|%\>/ or ruby =~ /<\%|%\>/ then
273
+ return if q
272
274
  warn "#{e.inspect} at #{e.backtrace.first(5).join(', ')}"
273
275
  warn "\n...stupid lemmings and their bad erb templates... skipping"
274
276
  else
275
- warn "ERROR: parsing ruby file #{file}"
277
+ warn "ERROR: parsing ruby file #{file}" unless q
276
278
  unless option[:continue] then
277
279
  warn "ERROR! Aborting. You may want to run with --continue."
278
280
  raise e
279
281
  end
280
- warn "#{e.class}: #{e.message.strip} at:"
281
- warn " #{e.backtrace.first(5).join("\n ")}"
282
+ return if q
283
+ warn "%s: %s at:\n %s" % [e.class, e.message.strip,
284
+ e.backtrace.first(5).join("\n ")]
282
285
  end
283
286
  end
284
287
  end
@@ -487,6 +490,14 @@ class Flog < SexpProcessor
487
490
  @total_score
488
491
  end
489
492
 
493
+ def max_score
494
+ max_method.last
495
+ end
496
+
497
+ def max_method
498
+ totals.max_by { |_, score| score }
499
+ end
500
+
490
501
  ##
491
502
  # Return the total score and populates @totals.
492
503
 
@@ -3,11 +3,13 @@ class FlogTask < Rake::TaskLib
3
3
  attr_accessor :dirs
4
4
  attr_accessor :threshold
5
5
  attr_accessor :verbose
6
+ attr_accessor :method
6
7
 
7
- def initialize name = :flog, threshold = 200, dirs = nil
8
+ def initialize name = :flog, threshold = 200, dirs = nil, method = nil
8
9
  @name = name
9
10
  @dirs = dirs || %w(app bin lib spec test)
10
11
  @threshold = threshold
12
+ @method = method || :total
11
13
  @verbose = Rake.application.options.trace
12
14
 
13
15
  yield self if block_given?
@@ -21,13 +23,18 @@ class FlogTask < Rake::TaskLib
21
23
  desc "Analyze for code complexity in: #{dirs.join(', ')}"
22
24
  task name do
23
25
  require "flog"
24
- flog = Flog.new
26
+ flog = Flog.new :continue => true, :quiet => true
25
27
  flog.flog(*dirs)
28
+
29
+ desc, score = flog.send method
30
+ desc, score = "total", desc unless score # total only returns a number
31
+
26
32
  flog.report if verbose
27
33
 
28
- raise "Flog total too high! #{flog.total} > #{threshold}" if
29
- flog.total > threshold
34
+ raise "Flog score for #{desc} is too high! #{score} > #{threshold}" if
35
+ score > threshold
30
36
  end
37
+
31
38
  self
32
39
  end
33
40
  end
@@ -1,6 +1,10 @@
1
1
  require 'minitest/autorun'
2
2
  require 'flog'
3
3
 
4
+ class Flog
5
+ attr_writer :calls
6
+ end
7
+
4
8
  class TestFlog < MiniTest::Unit::TestCase
5
9
  def setup
6
10
  @flog = Flog.new :parser => RubyParser
@@ -37,7 +41,7 @@ class TestFlog < MiniTest::Unit::TestCase
37
41
  def test_cls_parse_options
38
42
  # defaults
39
43
  opts = Flog.parse_options
40
- assert_equal true, opts[:quiet]
44
+ assert_equal false, opts[:quiet]
41
45
  assert_equal false, opts[:continue]
42
46
 
43
47
  {
@@ -672,6 +676,26 @@ class TestFlog < MiniTest::Unit::TestCase
672
676
  assert_equal 2.0, @flog.total
673
677
  end
674
678
 
679
+ def test_max_method
680
+ @flog.calls = {
681
+ "main#none" => {"foo" => 2.0, "bar" => 4.0},
682
+ "main#meth_one" => {"foo" => 1.0, "bar" => 1.0},
683
+ "main#meth_two" => {"foo" => 2.0, "bar" => 14.0},
684
+ }
685
+
686
+ assert_equal ["main#meth_two", 16.0], @flog.max_method
687
+ end
688
+
689
+ def test_max_score
690
+ @flog.calls = {
691
+ "main#none" => {"foo" => 2.0, "bar" => 4.0},
692
+ "main#meth_one" => {"foo" => 1.0, "bar" => 1.0},
693
+ "main#meth_two" => {"foo" => 2.0, "bar" => 14.0},
694
+ }
695
+
696
+ assert_equal 16.0, @flog.max_score
697
+ end
698
+
675
699
  def util_process sexp, score = -1, hash = {}
676
700
  setup
677
701
  @flog.process sexp
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 3.0.0
10
+ version: 3.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2012-11-02 00:00:00 Z
39
+ date: 2012-11-17 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sexp_processor
@@ -77,11 +77,11 @@ dependencies:
77
77
  requirements:
78
78
  - - ~>
79
79
  - !ruby/object:Gem::Version
80
- hash: 25
80
+ hash: 31
81
81
  segments:
82
82
  - 4
83
- - 1
84
- version: "4.1"
83
+ - 2
84
+ version: "4.2"
85
85
  type: :development
86
86
  version_requirements: *id003
87
87
  - !ruby/object:Gem::Dependency
@@ -107,11 +107,11 @@ dependencies:
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
- hash: 5
110
+ hash: 1
111
111
  segments:
112
112
  - 3
113
- - 1
114
- version: "3.1"
113
+ - 3
114
+ version: "3.3"
115
115
  type: :development
116
116
  version_requirements: *id005
117
117
  description: |-
metadata.gz.sig CHANGED
Binary file