ruby-appraiser 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.
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/README.md CHANGED
@@ -67,6 +67,11 @@ class Foo < RubyAppraiser::Adapter
67
67
  end
68
68
  ```
69
69
 
70
+ This project uses the [git-flow][] branching model, which means every commit
71
+ on `master` is by definition a release. Security-related fixes should be
72
+ submitted as hotfix branches off of `master`; all other features and fixes
73
+ **must** be based on `develop`.
74
+
70
75
  License
71
76
  -------
72
77
  See [LICENSE][]
@@ -75,3 +80,5 @@ See [LICENSE][]
75
80
  [rubocop]: https://github.com/bbatslov/rubocop
76
81
  [reek]: https://github.com/troessner/reek
77
82
  [flog]: https://github.com/seattlerb/flog
83
+
84
+ [git-flow]: http://nvie.com/git-model
data/Rakefile CHANGED
@@ -1,2 +1,10 @@
1
1
  # encoding: utf-8
2
2
  require 'bundler/gem_tasks'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.warning = true
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -6,10 +6,10 @@ class RubyAppraiser::Adapter::LineLength < RubyAppraiser::Adapter
6
6
  def appraise
7
7
  source_files.each do |source_file|
8
8
  File.open(source_file) do |source|
9
- source.lines.each_with_index do |line, number|
9
+ source.each_line do |line|
10
10
  line_length = line.chomp.length
11
11
  if line_length > 80
12
- add_defect(source_file, number,
12
+ add_defect(source_file, source.lineno,
13
13
  "Line too long [#{line_length}/80]")
14
14
  end
15
15
  end
@@ -94,6 +94,7 @@ class RubyAppraiser
94
94
  when 'staged' then staged_authored_lines
95
95
  when 'authored' then authored_lines
96
96
  when 'touched' then all_lines_in touched_files
97
+ when 'last' then last_commit_lines
97
98
  when 'all' then all_lines_in source_files
98
99
  else raise ArgumentError, "Unsupported mode #{mode}."
99
100
  end
@@ -109,6 +110,15 @@ class RubyAppraiser
109
110
  end
110
111
  end
111
112
 
113
+ def last_commit_lines
114
+ unless authored_lines.empty?
115
+ raise ArgumentError, 'mode=last only works on *clean* checkout. ' +
116
+ 'git-stash your changes and try again.'
117
+ end
118
+ @last_commit_lines ||=
119
+ RubyAppraiser::Git::authored_lines(range:'HEAD~1..HEAD')
120
+ end
121
+
112
122
  def touched_files
113
123
  @touched_files ||= authored_lines.keys
114
124
  end
@@ -8,6 +8,9 @@ class RubyAppraiser
8
8
  class CLI
9
9
  def initialize(args = ARGV)
10
10
  @argv = ARGV.dup
11
+ end
12
+
13
+ def configure
11
14
  args = @argv.dup # needed for --git-hook
12
15
  @options = {}
13
16
  adapters = Set.new
@@ -21,12 +24,13 @@ class RubyAppraiser
21
24
  puts available_adapters
22
25
  exit 1
23
26
  end
27
+ opts.on('-t', '--trace', 'Enable backtrace')
24
28
  opts.on('--silent', 'Silence output') do |silent|
25
29
  @options[:silent] = true
26
30
  end
27
31
  opts.on('--mode=MODE',
28
32
  'Set the mode. ' +
29
- '[staged,authored,touched,all]') do |mode|
33
+ '[staged,authored,touched,last,all]') do |mode|
30
34
  @options[:mode] = mode
31
35
  end
32
36
  opts.on('--git-hook',
@@ -83,12 +87,18 @@ class RubyAppraiser
83
87
  end
84
88
 
85
89
  def run
90
+ self.configure
86
91
  @appraisal.run!
87
92
  puts @appraisal unless @options[:silent]
88
93
  puts @appraisal.summary if @options[:verbose]
89
94
  @appraisal.success?
90
- rescue Object
91
- puts "#{@appraisal.class.name} caught #{$!} at #{$!.backtrace.first}."
95
+ rescue Exception
96
+ $stderr.puts $!.message
97
+ unless (@argv & ['--trace','-t']).empty?
98
+ $stderr.puts $!.inspect
99
+ $stderr.puts $!.backtrace
100
+ end
101
+ nil
92
102
  end
93
103
 
94
104
  def available_adapters
@@ -5,14 +5,24 @@ class RubyAppraiser
5
5
  extend self
6
6
 
7
7
  def authored_lines(options = {})
8
- diff_command = ['git diff']
8
+ diff_command = ['git', 'diff']
9
9
  if options[:range]
10
10
  diff_command << options[:range]
11
11
  else
12
12
  diff_command << (options[:staged] ? '--cached' : 'HEAD')
13
13
  end
14
14
 
15
- diff_output = IO.popen(diff_command.join(' ')) { |io| io.read }
15
+ diff_io = IO.popen(diff_command << {err: [:child, :out]})
16
+ diff_output = diff_io.read
17
+
18
+ case diff_output
19
+ when /^fatal: Not a git/i
20
+ then raise 'ruby-appraiser only works in git repos.'
21
+ when /^fatal: ambiguous argument 'HEAD'/i
22
+ then raise 'this ruby-appraiser mode only works with previous ' +
23
+ 'commits, and your repository doesn\t appear to have ' +
24
+ 'any. Make some commits first, or try a different mode.'
25
+ end
16
26
 
17
27
  current_path, current_line = nil, nil
18
28
  authored_lines = Hash.new { |hash, key| hash[key] = [] }
@@ -0,0 +1,26 @@
1
+ namespace :appraise do
2
+ def appraise_task(mode = 'all')
3
+ task mode do
4
+ require 'ruby-appraiser'
5
+ @appraisal = RubyAppraiser::Appraisal.new(mode: mode.to_s)
6
+ RubyAppraiser::Adapter::all.each do |adapter|
7
+ @appraisal.add_adapter adapter.adapter_type
8
+ end
9
+ @appraisal.run!
10
+ puts @appraisal
11
+ @appraisal.success? || fail('appraisal found defects')
12
+ end
13
+ end
14
+
15
+ {
16
+ all: 'show all defects',
17
+ staged: 'show staged defects',
18
+ authored: 'show uncommitted defects',
19
+ touched: 'show defects in all files that have been touched',
20
+ }.each do |mode, description|
21
+ desc description
22
+ appraise_task mode
23
+ end
24
+ end
25
+
26
+ task appraise: 'appraise:all'
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  class RubyAppraiser
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -16,4 +16,8 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
+
20
+ gem.add_development_dependency 'rake'
21
+ gem.add_development_dependency 'bundler'
22
+ gem.add_development_dependency 'minitest', '>= 5'
19
23
  end
data/test/test_cli.rb ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby -w
2
+ # test_cli.rb: verify RubyAppraiser::CLI works as designed
3
+
4
+ require 'pathname'
5
+
6
+ # add lib to loadpath
7
+ lib_path = Pathname.new(__FILE__).join('../../lib').expand_path
8
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include? lib_path
9
+
10
+ require 'minitest/autorun'
11
+ require 'minitest/benchmark'
12
+
13
+ require 'ruby-appraiser/cli'
14
+
15
+ class TestCLI < Minitest::Test
16
+ def test_empty_options
17
+ cli = RubyAppraiser::CLI.new("")
18
+ assert_equal({}, cli.options)
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-appraiser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,56 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-01 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-06-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '5'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '5'
14
62
  description: Run multiple code-quality tools against staged changes
15
63
  email:
16
64
  - ryan@simplymeasured.com
@@ -20,6 +68,7 @@ extensions: []
20
68
  extra_rdoc_files: []
21
69
  files:
22
70
  - .gitignore
71
+ - .travis.yml
23
72
  - Gemfile
24
73
  - LICENSE-APACHE.md
25
74
  - LICENSE-MIT.md
@@ -34,8 +83,10 @@ files:
34
83
  - lib/ruby-appraiser/cli.rb
35
84
  - lib/ruby-appraiser/defect.rb
36
85
  - lib/ruby-appraiser/git.rb
86
+ - lib/ruby-appraiser/rake.rb
37
87
  - lib/ruby-appraiser/version.rb
38
88
  - ruby-appraiser.gemspec
89
+ - test/test_cli.rb
39
90
  homepage: https://github.com/simplymeasured
40
91
  licenses: []
41
92
  post_install_message:
@@ -60,5 +111,6 @@ rubygems_version: 1.8.24
60
111
  signing_key:
61
112
  specification_version: 3
62
113
  summary: A Common interface/executor for code quality tools
63
- test_files: []
114
+ test_files:
115
+ - test/test_cli.rb
64
116
  has_rdoc: