gem_lint 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ v0.0.4 (21st December 2010)
2
+ * change output format to be easily machine parsable
3
+ * ruby 1.9.2 compat
4
+ * various new checks
5
+
1
6
  v0.0.3 (10th December 2010)
2
7
  * use pure ruby to unpack gems
3
8
 
@@ -18,7 +18,7 @@ module GemLint
18
18
  #
19
19
  def self.strategies
20
20
  GemLint::Strategies.constants.sort.select { |class_name|
21
- class_name != "AbstractStrategy"
21
+ class_name.to_s != "AbstractStrategy"
22
22
  }.map { |class_name|
23
23
  GemLint::Strategies.const_get(class_name)
24
24
  }
@@ -3,8 +3,8 @@
3
3
  module GemLint
4
4
  class Runner
5
5
 
6
- attr_reader :tags, :tags_with_desc, :tags_with_level
7
- attr_reader :email, :name, :version
6
+ attr_reader :tags
7
+ attr_reader :email, :name, :platform, :version
8
8
 
9
9
  def initialize(filename)
10
10
  raise ArgumentError, "'#{filename}' does not exist" unless File.file?(filename.to_s)
@@ -13,19 +13,39 @@ module GemLint
13
13
  init_vars
14
14
  end
15
15
 
16
+ def to_s(type = :simple)
17
+ if type == :simple
18
+ @tags.map { |t| "- #{t}"}.join("\n")
19
+ else
20
+ lines.join("\n")
21
+ end
22
+ end
23
+
16
24
  private
17
25
 
18
26
  def init_vars
19
27
  unpack_gem
20
- @tags = collect_tags
21
- @tags_with_level = collect_tags_with_level
22
- @tags_with_desc = collect_tags_with_desc
23
- @email = spec ? spec.email : nil
24
- @name = spec ? spec.name : nil
25
- @version = spec ? spec.version.to_s : nil
28
+ @tags = collect_tags
29
+ @email = spec ? spec.email : nil
30
+ @name = spec ? spec.name : nil
31
+ @version = spec ? spec.version.to_s : nil
32
+ @platform = spec ? spec.platform.to_s : nil
33
+ lines
26
34
  cleanup
27
35
  end
28
36
 
37
+ def lines
38
+ if unpack_successful?
39
+ @lines ||= failed_strategies.map { |s|
40
+ [s.level_char, self.name, self.version, self.platform, s.tag, s.description].join(": ")
41
+ }.sort
42
+ else
43
+ @lines ||= [
44
+ ["E", self.name, self.version, self.platform, "unpack-failed", "There was an error unpacking the gem file"].join(": ")
45
+ ]
46
+ end
47
+ end
48
+
29
49
  # returns an array of symbols, each one indicating a test the provided gem
30
50
  # failed. Unpacks the gem to a temporary location and cleans up after
31
51
  # itself.
@@ -40,28 +60,6 @@ module GemLint
40
60
  end
41
61
  end
42
62
 
43
- def collect_tags_with_desc
44
- if unpack_successful?
45
- failed_strategies.map { |s|
46
- ["#{s.level_char}: #{s.tag}", s.description]
47
- }.sort_by { |arr|
48
- arr.first
49
- }
50
- else
51
- ["E: unpack-failed", "There was an error unpacking the gem file"]
52
- end
53
- end
54
-
55
- def collect_tags_with_level
56
- if unpack_successful?
57
- failed_strategies.map { |s|
58
- "#{s.level_char}: #{s.tag}"
59
- }.sort
60
- else
61
- ["E: unpack-failed"]
62
- end
63
- end
64
-
65
63
  def failed_strategies
66
64
  if unpack_successful?
67
65
  @failed_strategies ||= GemLint.strategies.map { |s|
@@ -83,7 +81,7 @@ module GemLint
83
81
  end
84
82
 
85
83
  def unpack_successful?
86
- File.directory?(data_path) && File.file?(metadata_file)
84
+ File.directory?(data_path) && File.file?(metadata_file) && File.size(metadata_file) > 0
87
85
  end
88
86
 
89
87
  def data_path
@@ -107,11 +105,15 @@ module GemLint
107
105
  end
108
106
 
109
107
  def unpack_path
110
- @unpack_path ||= File.join(Dir.tmpdir, rand(100000).to_s)
108
+ return @unpack_path if @unpack_path
109
+ while @unpack_path.nil? || File.directory?(@unpack_path)
110
+ @unpack_path = File.join(Dir.tmpdir, rand(100000).to_s)
111
+ end
112
+ Dir.mkdir(@unpack_path)
113
+ @unpack_path
111
114
  end
112
115
 
113
116
  def unpack_gem
114
- Dir.mkdir(unpack_path)
115
117
  Dir.mkdir(data_path)
116
118
 
117
119
  format = Gem::Format.from_file_by_path(@filename)
@@ -119,12 +121,14 @@ module GemLint
119
121
  format.file_entries.each do |entry, file_data|
120
122
  path = entry['path']
121
123
  path = File.expand_path File.join(data_path, path)
122
- raise "Can't install files there" unless path[0, data_path.size] == data_path
124
+ return false unless path[0, data_path.size] == data_path
123
125
  FileUtils.mkdir_p File.dirname(path)
124
126
  File.open(path, "wb") { |out| out.write file_data }
125
127
  end
126
128
 
127
129
  true
130
+ rescue
131
+ false
128
132
  end
129
133
 
130
134
  def cleanup
@@ -16,7 +16,7 @@ module GemLint
16
16
 
17
17
  def fail?
18
18
  yaml.authors.is_a?(Array) &&
19
- (yaml.authors.first.include?(",") || yaml.authors.first.include?(";"))
19
+ (yaml.authors.first.to_s.include?(",") || yaml.authors.first.to_s.include?(";"))
20
20
  end
21
21
 
22
22
  private
@@ -16,7 +16,7 @@ module GemLint
16
16
 
17
17
  def fail?
18
18
  (yaml.email.is_a?(String) && (yaml.email.include?(",") || yaml.email.include?(";"))) ||
19
- (yaml.email.is_a?(Array) && (yaml.email.first.include?(",") || yaml.email.first.include?(";")))
19
+ (yaml.email.is_a?(Array) && (yaml.email.first.to_s.include?(",") || yaml.email.first.to_s.include?(";")))
20
20
  end
21
21
 
22
22
  private
@@ -0,0 +1,29 @@
1
+ module GemLint
2
+ module Strategies
3
+ class EmptyAuthorsStrategy < AbstractStrategy
4
+
5
+ def description
6
+ "Authors field is empty"
7
+ end
8
+
9
+ def tag
10
+ :"empty-authors"
11
+ end
12
+
13
+ def level
14
+ :warning
15
+ end
16
+
17
+ def fail?
18
+ yaml.authors.is_a?(Array) && yaml.authors.empty?
19
+ end
20
+
21
+ private
22
+
23
+ def yaml
24
+ @yaml ||= YAML.load(File.read(@metadata_path))
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module GemLint
2
+ module Strategies
3
+ class EmptyEmailStrategy < AbstractStrategy
4
+
5
+ def description
6
+ "Email field in spec is empty"
7
+ end
8
+
9
+ def tag
10
+ :"empty-email"
11
+ end
12
+
13
+ def level
14
+ :error
15
+ end
16
+
17
+ def fail?
18
+ yaml.email.is_a?(Array) && yaml.email.empty?
19
+ end
20
+
21
+ private
22
+
23
+ def yaml
24
+ @yaml ||= YAML.load(File.read(@metadata_path))
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module GemLint
2
+ module Strategies
3
+ class NoFilesStrategy < AbstractStrategy
4
+
5
+ def description
6
+ "Gem containts no files"
7
+ end
8
+
9
+ def tag
10
+ :"no-files"
11
+ end
12
+
13
+ def level
14
+ :warning
15
+ end
16
+
17
+ def fail?
18
+ yaml.files.empty?
19
+ end
20
+
21
+ private
22
+
23
+ def yaml
24
+ @yaml ||= YAML.load(File.read(@metadata_path))
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -5,7 +5,7 @@ module GemLint
5
5
  class RequireMatchesGemnameStrategy < AbstractStrategy
6
6
 
7
7
  def description
8
- "Gem cannot be loaded by require '#{preferred_basename}'"
8
+ "Gem cannot be loaded by require '#{preferred_basename.gsub(/^lib\//,'')}'"
9
9
  end
10
10
 
11
11
  def tag
@@ -28,7 +28,7 @@ class Gem::Commands::LintCommand < Gem::Command
28
28
  if options[:detailed]
29
29
  detailed_output(runner)
30
30
  else
31
- short_output(runner)
31
+ simple_output(runner)
32
32
  end
33
33
  end
34
34
 
@@ -39,23 +39,18 @@ class Gem::Commands::LintCommand < Gem::Command
39
39
  puts "No test failures!"
40
40
  puts
41
41
  else
42
- runner.tags_with_desc.each do |tag, desc|
43
- puts "- #{tag}"
44
- puts " #{desc}"
45
- end
42
+ puts runner.to_s(:detailed)
46
43
  puts
47
44
  exit 1
48
45
  end
49
46
  end
50
47
 
51
- def short_output(runner)
48
+ def simple_output(runner)
52
49
  if runner.tags.empty?
53
50
  puts "No test failures!"
54
51
  puts
55
52
  else
56
- runner.tags_with_level.each do |tag|
57
- puts "- #{tag}"
58
- end
53
+ puts runner.to_s(:simple)
59
54
  puts
60
55
  exit 1
61
56
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_lint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Healy
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-10 00:00:00 +11:00
18
+ date: 2010-12-21 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -33,7 +33,7 @@ dependencies:
33
33
  type: :development
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: rcov
36
+ name: roodi
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
@@ -46,24 +46,10 @@ dependencies:
46
46
  version: "0"
47
47
  type: :development
48
48
  version_requirements: *id002
49
- - !ruby/object:Gem::Dependency
50
- name: roodi
51
- prerelease: false
52
- requirement: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- type: :development
62
- version_requirements: *id003
63
49
  - !ruby/object:Gem::Dependency
64
50
  name: rspec
65
51
  prerelease: false
66
- requirement: &id004 !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
67
53
  none: false
68
54
  requirements:
69
55
  - - ~>
@@ -74,7 +60,7 @@ dependencies:
74
60
  - 0
75
61
  version: "2.0"
76
62
  type: :development
77
- version_requirements: *id004
63
+ version_requirements: *id003
78
64
  description: Adds a 'lint' command rubygems that will print a list of possible errors in a gem
79
65
  email:
80
66
  - james@yob.id.au
@@ -93,12 +79,15 @@ files:
93
79
  - lib/gem_lint/strategies/utf8_metadata_strategy.rb
94
80
  - lib/gem_lint/strategies/readme_strategy.rb
95
81
  - lib/gem_lint/strategies/changelog_strategy.rb
82
+ - lib/gem_lint/strategies/empty_authors_strategy.rb
96
83
  - lib/gem_lint/strategies/duplicate_authors_strategy.rb
84
+ - lib/gem_lint/strategies/empty_email_strategy.rb
97
85
  - lib/gem_lint/strategies/bin_ends_with_rb_strategy.rb
98
86
  - lib/gem_lint/strategies/bin_without_shebang_strategy.rb
99
87
  - lib/gem_lint/strategies/csv_email_strategy.rb
100
88
  - lib/gem_lint/strategies/abstract_strategy.rb
101
89
  - lib/gem_lint/strategies/pkg_dir_strategy.rb
90
+ - lib/gem_lint/strategies/no_files_strategy.rb
102
91
  - lib/gem_lint/strategies/capitals_in_name_strategy.rb
103
92
  - lib/gem_lint/strategies/test_files_in_files_attribute_strategy.rb
104
93
  - lib/gem_lint/strategies/string_email_strategy.rb