bad_encodings-ruby19 0.1.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/VERSION.yml +3 -3
- data/bad_encodings-ruby19.gemspec +7 -6
- data/bin/find_bad_encodings +20 -7
- data/lib/bad_encodings.rb +5 -3
- data/tasks/gemspec.rake +2 -2
- data/test/bad_encodings/ok.yml +1 -1
- data/test/bad_encodings_test.rb +8 -1
- metadata +7 -6
data/README.md
CHANGED
data/VERSION.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
---
|
2
|
-
:major:
|
3
|
-
:minor:
|
4
|
-
:patch:
|
2
|
+
:major: 1
|
3
|
+
:minor: 0
|
4
|
+
:patch: 0
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bad_encodings-ruby19}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Adam Salter"]
|
12
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-10-02}
|
13
13
|
s.default_executable = %q{find_bad_encodings}
|
14
14
|
s.description = %q{Small gem that tries to make the task of finding bad ruby encodings in your project a little easier.}
|
15
15
|
s.email = %q{adam@codebright.net}
|
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
"README.md",
|
22
22
|
"Rakefile",
|
23
23
|
"VERSION.yml",
|
24
|
+
"bad_encodings-ruby19-1.0.0.gem",
|
24
25
|
"bad_encodings-ruby19.gemspec",
|
25
26
|
"bin/find_bad_encodings",
|
26
27
|
"lib/bad_encodings.rb",
|
@@ -38,7 +39,7 @@ Gem::Specification.new do |s|
|
|
38
39
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
40
|
s.require_paths = ["lib"]
|
40
41
|
s.rubygems_version = %q{1.3.5}
|
41
|
-
s.summary = %q{
|
42
|
+
s.summary = %q{Find bad ruby 1.9 encodings in your project.}
|
42
43
|
s.test_files = [
|
43
44
|
"test/bad_encodings/bad1.rb",
|
44
45
|
"test/bad_encodings/bad2.rb",
|
@@ -53,14 +54,14 @@ Gem::Specification.new do |s|
|
|
53
54
|
s.specification_version = 3
|
54
55
|
|
55
56
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
-
s.add_runtime_dependency(%q<
|
57
|
+
s.add_runtime_dependency(%q<clip>, [">= 1.0"])
|
57
58
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
59
|
else
|
59
|
-
s.add_dependency(%q<
|
60
|
+
s.add_dependency(%q<clip>, [">= 1.0"])
|
60
61
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
62
|
end
|
62
63
|
else
|
63
|
-
s.add_dependency(%q<
|
64
|
+
s.add_dependency(%q<clip>, [">= 1.0"])
|
64
65
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
65
66
|
end
|
66
67
|
end
|
data/bin/find_bad_encodings
CHANGED
@@ -1,20 +1,33 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
2
|
+
require 'clip'
|
3
3
|
require 'bad_encodings'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
options = Clip do |p|
|
6
|
+
p.optional 'e', 'file-extensions', :desc => %Q{Set file extensions to search (comma-separated). E.g. 'rb,yml'. To search all files, just pass a comma ','}, :multi => true, :default => "rb,rake,haml,sass,erb"
|
7
|
+
p.flag 'v', 'verbose', :desc => 'Make it chatty.'
|
8
|
+
end
|
9
|
+
|
10
|
+
if options.valid? && !options.remainder.empty?
|
11
|
+
ENV['VERBOSE'] = 'true' if options.verbose?
|
12
|
+
paths = []
|
13
|
+
options.remainder.each do |dir|
|
14
|
+
paths << [File.expand_path(dir), dir] if File.exists?(dir)
|
15
|
+
end
|
7
16
|
else
|
8
|
-
|
17
|
+
$stderr.puts "find_bad_encodings dir1 [dir2 ...] [options]\n" + options.to_s
|
18
|
+
exit
|
9
19
|
end
|
10
20
|
|
11
21
|
raise ArgumentError, "Requires Ruby 1.9" unless RUBY_VERSION > '1.9'
|
12
|
-
|
13
|
-
bad_lines =
|
22
|
+
|
23
|
+
bad_lines = []
|
24
|
+
paths.each do |path|
|
25
|
+
bad_lines += BadEncodings.find_lines_in_path(path[0], options.file_extensions).map! {|bl| [bl[0].sub(path[0],path[1]), bl[1]] }
|
26
|
+
end
|
14
27
|
unless bad_lines.empty?
|
15
28
|
puts 'The following bad encodings were found:'
|
16
29
|
bad_lines.each do |line|
|
17
|
-
puts "[%s:%d]" % [line[0]
|
30
|
+
puts "[%s:%d]" % [line[0], line[1]]
|
18
31
|
end
|
19
32
|
else
|
20
33
|
puts 'No bad encodings found'
|
data/lib/bad_encodings.rb
CHANGED
@@ -2,8 +2,8 @@ require 'find'
|
|
2
2
|
|
3
3
|
class BadEncodings
|
4
4
|
class << self
|
5
|
-
def find_lines_in_path(dir,
|
6
|
-
|
5
|
+
def find_lines_in_path(dir, file_extensions = ["rb|rake|haml|sass|erb"], dir_excludes = nil)
|
6
|
+
regex = /#{file_extensions.join('|')}$/
|
7
7
|
files = []
|
8
8
|
Find.find(dir) do |path|
|
9
9
|
if FileTest.directory?(path)
|
@@ -12,7 +12,7 @@ class BadEncodings
|
|
12
12
|
else
|
13
13
|
next
|
14
14
|
end
|
15
|
-
elsif path =~
|
15
|
+
elsif path =~ regex
|
16
16
|
files << path
|
17
17
|
end
|
18
18
|
end
|
@@ -28,6 +28,7 @@ class BadEncodings
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def find_lines_in_file(file)
|
31
|
+
puts "#{file}" if ENV['VERBOSE']
|
31
32
|
bad_lines = []
|
32
33
|
file = File.open(file, "r:US-ASCII")
|
33
34
|
file.each_line do |line|
|
@@ -40,6 +41,7 @@ class BadEncodings
|
|
40
41
|
# if invalid byte sequence on first line of file
|
41
42
|
end
|
42
43
|
next if line.valid_encoding?
|
44
|
+
puts "Bad encoding found: line #{file.lineno}" if ENV['VERBOSE']
|
43
45
|
bad_lines << [file.path, file.lineno]
|
44
46
|
end
|
45
47
|
bad_lines
|
data/tasks/gemspec.rake
CHANGED
@@ -3,13 +3,13 @@ begin
|
|
3
3
|
Jeweler::Tasks.new do |s|
|
4
4
|
s.name = 'bad_encodings-ruby19'
|
5
5
|
s.executables = ['find_bad_encodings']
|
6
|
-
s.summary = '
|
6
|
+
s.summary = 'Find bad ruby 1.9 encodings in your project.'
|
7
7
|
s.email = 'adam@codebright.net'
|
8
8
|
s.homepage = 'http://github.com/adamsalter/bad_encodings-ruby19'
|
9
9
|
s.description = 'Small gem that tries to make the task of finding bad ruby encodings in your project a little easier.'
|
10
10
|
s.authors = ['Adam Salter']
|
11
11
|
s.files = FileList['*', '{bin,lib,test,tasks}/**/*']
|
12
|
-
s.add_dependency '
|
12
|
+
s.add_dependency 'clip', '>= 1.0'
|
13
13
|
s.add_development_dependency 'shoulda'
|
14
14
|
end
|
15
15
|
end
|
data/test/bad_encodings/ok.yml
CHANGED
data/test/bad_encodings_test.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
|
+
# ENV['VERBOSE'] = 'true'
|
4
|
+
|
3
5
|
class BadEncodingsTest < Test::Unit::TestCase
|
4
6
|
context 'A file with bad encodings' do
|
5
7
|
should 'fail' do
|
@@ -14,8 +16,13 @@ class BadEncodingsTest < Test::Unit::TestCase
|
|
14
16
|
should 'fail' do
|
15
17
|
path = File.dirname(__FILE__)
|
16
18
|
bad_lines = BadEncodings.find_lines_in_path(path)
|
17
|
-
puts bad_lines.inspect
|
18
19
|
assert_equal bad_lines, [[path+"/bad_encodings/bad1.rb", 4], [path+"/bad_encodings/bad2.rb", 1], [path+"/bad_encodings/bad2.rb", 3], [path+"/bad_encodings/bad3.rb", 1]]
|
19
20
|
end
|
21
|
+
|
22
|
+
should 'fail with certain file extensions' do
|
23
|
+
path = File.dirname(__FILE__)
|
24
|
+
bad_lines = BadEncodings.find_lines_in_path(path, ['yml'])
|
25
|
+
assert_equal bad_lines, [[path+"/bad_encodings/ok.yml", 4]]
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bad_encodings-ruby19
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Salter
|
@@ -9,18 +9,18 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-10-02 00:00:00 +10:00
|
13
13
|
default_executable: find_bad_encodings
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: clip
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
|
-
- -
|
21
|
+
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0
|
23
|
+
version: "1.0"
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- README.md
|
45
45
|
- Rakefile
|
46
46
|
- VERSION.yml
|
47
|
+
- bad_encodings-ruby19-1.0.0.gem
|
47
48
|
- bad_encodings-ruby19.gemspec
|
48
49
|
- bin/find_bad_encodings
|
49
50
|
- lib/bad_encodings.rb
|
@@ -83,7 +84,7 @@ rubyforge_project:
|
|
83
84
|
rubygems_version: 1.3.5
|
84
85
|
signing_key:
|
85
86
|
specification_version: 3
|
86
|
-
summary:
|
87
|
+
summary: Find bad ruby 1.9 encodings in your project.
|
87
88
|
test_files:
|
88
89
|
- test/bad_encodings/bad1.rb
|
89
90
|
- test/bad_encodings/bad2.rb
|