adamsalter-bad_encodings-ruby19 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +47 -0
- data/VERSION.yml +1 -1
- data/bad_encodings-ruby19.gemspec +6 -4
- data/lib/bad_encodings.rb +10 -3
- data/test/bad_encodings/bad3.rb +4 -0
- data/test/bad_encodings_test.rb +7 -8
- metadata +6 -4
- data/README.rdoc +0 -5
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
BadEncodings
|
2
|
+
================
|
3
|
+
|
4
|
+
Small gem that tries to make the task of finding bad ruby encodings in your project a little easier. e.g. 'find_bad_encodings .'
|
5
|
+
|
6
|
+
It basically iterates over the regular 'ruby' files it can find and tries each line for 'valid_encoding' and then returns a list of all lines that failed.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
=======
|
10
|
+
|
11
|
+
Install gem as normal
|
12
|
+
|
13
|
+
gem install adamsalter-bad_encodings-ruby19
|
14
|
+
|
15
|
+
|
16
|
+
Usage
|
17
|
+
-----
|
18
|
+
|
19
|
+
You can either use it as a binary:
|
20
|
+
|
21
|
+
~/my_unencoded_dir/$ find_bad_encodings .
|
22
|
+
# => various wrongly encoded files.
|
23
|
+
|
24
|
+
or add it as a rake task to your (rails) project:
|
25
|
+
|
26
|
+
# put this in your project Rakefile
|
27
|
+
require 'bad_encodings/tasks'
|
28
|
+
|
29
|
+
~/my_unencoded_project/$ rake find_bad_encodings
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
Known Bugs
|
34
|
+
========
|
35
|
+
|
36
|
+
None. (well actually the detection of ruby encoding is pretty simple and probably not 100% accurate, certainly works for everything I've tried it on... patches welcome.)
|
37
|
+
|
38
|
+
|
39
|
+
Follow me on:
|
40
|
+
-------
|
41
|
+
|
42
|
+
> Twitter: [twitter.com/adamsalter](http://twitter.com/adamsalter)
|
43
|
+
> Github: [github.com/adamsalter](http://github.com/adamsalter)
|
44
|
+
|
45
|
+
Copyright (c) 2009 Adam @ [Codebright.net][cb], released under the MIT license
|
46
|
+
|
47
|
+
[cb]:http://codebright.net "http://codebright.net"
|
data/VERSION.yml
CHANGED
@@ -5,20 +5,20 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bad_encodings-ruby19}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
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-09-
|
12
|
+
s.date = %q{2009-09-11}
|
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}
|
16
16
|
s.executables = ["find_bad_encodings"]
|
17
17
|
s.extra_rdoc_files = [
|
18
|
-
"README.
|
18
|
+
"README.md"
|
19
19
|
]
|
20
20
|
s.files = [
|
21
|
-
"README.
|
21
|
+
"README.md",
|
22
22
|
"Rakefile",
|
23
23
|
"VERSION.yml",
|
24
24
|
"bad_encodings-ruby19.gemspec",
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
|
|
28
28
|
"tasks/gemspec.rake",
|
29
29
|
"test/bad_encodings/bad1.rb",
|
30
30
|
"test/bad_encodings/bad2.rb",
|
31
|
+
"test/bad_encodings/bad3.rb",
|
31
32
|
"test/bad_encodings/ok.rb",
|
32
33
|
"test/bad_encodings/ok.yml",
|
33
34
|
"test/bad_encodings_test.rb",
|
@@ -41,6 +42,7 @@ Gem::Specification.new do |s|
|
|
41
42
|
s.test_files = [
|
42
43
|
"test/bad_encodings/bad1.rb",
|
43
44
|
"test/bad_encodings/bad2.rb",
|
45
|
+
"test/bad_encodings/bad3.rb",
|
44
46
|
"test/bad_encodings/ok.rb",
|
45
47
|
"test/bad_encodings_test.rb",
|
46
48
|
"test/test_helper.rb"
|
data/lib/bad_encodings.rb
CHANGED
@@ -16,7 +16,7 @@ class BadEncodings
|
|
16
16
|
files << path
|
17
17
|
end
|
18
18
|
end
|
19
|
-
find_lines_in_files(files)
|
19
|
+
find_lines_in_files(files.reverse)
|
20
20
|
end
|
21
21
|
|
22
22
|
def find_lines_in_files(files)
|
@@ -29,9 +29,16 @@ class BadEncodings
|
|
29
29
|
|
30
30
|
def find_lines_in_file(file)
|
31
31
|
bad_lines = []
|
32
|
-
|
33
|
-
file = File.open(file, "r:#{file_encoding}")
|
32
|
+
file = File.open(file, "r:US-ASCII")
|
34
33
|
file.each_line do |line|
|
34
|
+
begin
|
35
|
+
if (file.lineno == 1 || file.lineno == 2) && line =~ /^#.*coding:\s([\w-]+)/
|
36
|
+
file.set_encoding($1)
|
37
|
+
end
|
38
|
+
rescue ArgumentError
|
39
|
+
# regex match will fail with 'invalid byte sequence in US-ASCII'
|
40
|
+
# if invalid byte sequence on first line of file
|
41
|
+
end
|
35
42
|
next if line.valid_encoding?
|
36
43
|
bad_lines << [file.path, file.lineno]
|
37
44
|
end
|
data/test/bad_encodings_test.rb
CHANGED
@@ -3,20 +3,19 @@ require File.dirname(__FILE__) + '/test_helper'
|
|
3
3
|
class BadEncodingsTest < Test::Unit::TestCase
|
4
4
|
context 'A file with bad encodings' do
|
5
5
|
should 'fail' do
|
6
|
-
|
6
|
+
path = File.dirname(__FILE__)
|
7
|
+
bad_file = path + '/bad_encodings/bad1.rb'
|
7
8
|
bad_lines = BadEncodings.find_lines_in_file(bad_file)
|
8
|
-
assert_equal bad_lines.
|
9
|
-
assert_equal bad_lines[0][1], 4
|
9
|
+
assert_equal bad_lines, [[path+"/bad_encodings/bad1.rb", 4]]
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
context 'A path with bad encodings' do
|
14
14
|
should 'fail' do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
assert_equal bad_lines[
|
19
|
-
assert_equal bad_lines[2][1], 4
|
15
|
+
path = File.dirname(__FILE__)
|
16
|
+
bad_lines = BadEncodings.find_lines_in_path(path)
|
17
|
+
puts bad_lines.inspect
|
18
|
+
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]]
|
20
19
|
end
|
21
20
|
end
|
22
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adamsalter-bad_encodings-ruby19
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Salter
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
13
13
|
default_executable: find_bad_encodings
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -39,9 +39,9 @@ executables:
|
|
39
39
|
extensions: []
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
|
-
- README.
|
42
|
+
- README.md
|
43
43
|
files:
|
44
|
-
- README.
|
44
|
+
- README.md
|
45
45
|
- Rakefile
|
46
46
|
- VERSION.yml
|
47
47
|
- bad_encodings-ruby19.gemspec
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- tasks/gemspec.rake
|
52
52
|
- test/bad_encodings/bad1.rb
|
53
53
|
- test/bad_encodings/bad2.rb
|
54
|
+
- test/bad_encodings/bad3.rb
|
54
55
|
- test/bad_encodings/ok.rb
|
55
56
|
- test/bad_encodings/ok.yml
|
56
57
|
- test/bad_encodings_test.rb
|
@@ -84,6 +85,7 @@ summary: Small gem that tries to make the task of finding bad ruby encodings in
|
|
84
85
|
test_files:
|
85
86
|
- test/bad_encodings/bad1.rb
|
86
87
|
- test/bad_encodings/bad2.rb
|
88
|
+
- test/bad_encodings/bad3.rb
|
87
89
|
- test/bad_encodings/ok.rb
|
88
90
|
- test/bad_encodings_test.rb
|
89
91
|
- test/test_helper.rb
|