yaml-validator 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile.lock +1 -1
- data/lib/yaml-validator.rb +24 -2
- data/lib/yaml-validator/version.rb +1 -1
- data/spec/fixtures/bad_chars/en.yml +4 -0
- data/spec/fixtures/bad_chars/he.yml +2 -0
- data/spec/yaml-validator_spec.rb +13 -3
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77d97bf3baf6728ffb9da7c658caa53775fbd621
|
4
|
+
data.tar.gz: e8b5e202a428c260fe0978bf9ef1353cd39c677a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d19beeb8c9657d58c7c279e52d3b5e4c247a0a6639e789aa69851c9622cfce25eba4b72c6a1a2143801b30c47432bac2e7a9f72ba89b8fbf9e1fa9f38202ea8d
|
7
|
+
data.tar.gz: 3ae273ea3a8a7b98f6a4a3a50b284038fb3adec9e115789a17161babba4427b8ea48bc57c046a8d663fd124e653c0f71a2deb02a3de03ac211f4d84ed6aea7ed
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/Gemfile.lock
CHANGED
data/lib/yaml-validator.rb
CHANGED
@@ -53,12 +53,12 @@ class YamlValidator
|
|
53
53
|
yaml_object = yaml_object[yaml_object.keys[0]]
|
54
54
|
yaml_object = Helpers.normalize_yaml(yaml_object)
|
55
55
|
errors += validate_yaml_object('', yaml_object)
|
56
|
-
if @options
|
56
|
+
if @options[:missing]
|
57
57
|
errors.concat find_missing_translations(yaml_object)
|
58
58
|
errors.concat find_missing_pluralizations(filename, yaml_object)
|
59
59
|
end
|
60
60
|
|
61
|
-
if @options
|
61
|
+
if @options[:sanitize]
|
62
62
|
errors.concat find_unsanitized_html(filename, yaml_object)
|
63
63
|
end
|
64
64
|
|
@@ -133,6 +133,28 @@ class YamlValidator
|
|
133
133
|
end
|
134
134
|
|
135
135
|
def validate_item(full_key, value, is_pluralization = false)
|
136
|
+
errors = validate_item_vars(full_key, value, is_pluralization)
|
137
|
+
errors.concat validate_item_characters(full_key, value)
|
138
|
+
errors
|
139
|
+
end
|
140
|
+
|
141
|
+
def validate_item_characters(full_key, value)
|
142
|
+
bad_chars = '⏎'
|
143
|
+
bad_chars_found = []
|
144
|
+
bad_chars.each_char do |ch|
|
145
|
+
if value.include? ch
|
146
|
+
bad_chars_found << ch
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
if bad_chars_found.any?
|
151
|
+
return ["#{full_key}: bad characters (#{bad_chars_found.join(', ')} ) in '#{value}'"]
|
152
|
+
else
|
153
|
+
return []
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def validate_item_vars(full_key, value, is_pluralization = false)
|
136
158
|
real_vars = get_key_en_vars(full_key)
|
137
159
|
if real_vars.nil?
|
138
160
|
if is_pluralization
|
data/spec/yaml-validator_spec.rb
CHANGED
@@ -34,10 +34,20 @@ describe YamlValidator do
|
|
34
34
|
]
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
describe "bad_chars scenario" do
|
39
|
+
it "returns two errors" do
|
40
|
+
validator = YamlValidator.new('spec/fixtures/bad_chars')
|
41
|
+
errors = validator.validate()
|
42
|
+
errors.should == [
|
43
|
+
"he.yml: key1: bad characters (⏎ ) in 'line1 ⏎ line2'",
|
44
|
+
]
|
45
|
+
end
|
46
|
+
end
|
37
47
|
|
38
48
|
describe "inconsistent_types scenario" do
|
39
49
|
it "returns inconsistent type error" do
|
40
|
-
validator = YamlValidator.new('spec/fixtures/inconsistent_types')
|
50
|
+
validator = YamlValidator.new('spec/fixtures/inconsistent_types', missing: true)
|
41
51
|
errors = validator.validate()
|
42
52
|
errors.should == [
|
43
53
|
"he.yml: parent1.key1.subkey1 doesn't exist in en.yml",
|
@@ -63,7 +73,7 @@ describe YamlValidator do
|
|
63
73
|
|
64
74
|
describe "missing translations" do
|
65
75
|
it "returns invalid yaml error" do
|
66
|
-
validator = YamlValidator.new('spec/fixtures/missing_translations')
|
76
|
+
validator = YamlValidator.new('spec/fixtures/missing_translations', missing: true)
|
67
77
|
errors = validator.validate()
|
68
78
|
errors.should == [
|
69
79
|
"he.yml: missing translation for key2 ('value2')",
|
@@ -76,7 +86,7 @@ describe YamlValidator do
|
|
76
86
|
|
77
87
|
describe "weird pluralizations" do
|
78
88
|
it "returns missing pluralizations error" do
|
79
|
-
validator = YamlValidator.new('spec/fixtures/weird_pluralizations')
|
89
|
+
validator = YamlValidator.new('spec/fixtures/weird_pluralizations', missing: true)
|
80
90
|
errors = validator.validate()
|
81
91
|
errors.should == [
|
82
92
|
"ru.yml: missing 'few' pluralization for 'dogs'",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml-validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Elentok
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -89,6 +89,7 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- .rspec
|
92
|
+
- .ruby-version
|
92
93
|
- .travis.yml
|
93
94
|
- Gemfile
|
94
95
|
- Gemfile.lock
|
@@ -102,6 +103,8 @@ files:
|
|
102
103
|
- lib/yaml-validator/version.rb
|
103
104
|
- pkg/yaml-validator-0.0.1.gem
|
104
105
|
- scripts/get-rails-i18n-rules.rb
|
106
|
+
- spec/fixtures/bad_chars/en.yml
|
107
|
+
- spec/fixtures/bad_chars/he.yml
|
105
108
|
- spec/fixtures/inconsistent_types/en.yml
|
106
109
|
- spec/fixtures/inconsistent_types/he.yml
|
107
110
|
- spec/fixtures/invalid_yml/en.yml
|
@@ -144,6 +147,8 @@ signing_key:
|
|
144
147
|
specification_version: 4
|
145
148
|
summary: Validates .yml locale files for Ruby on Rails projects
|
146
149
|
test_files:
|
150
|
+
- spec/fixtures/bad_chars/en.yml
|
151
|
+
- spec/fixtures/bad_chars/he.yml
|
147
152
|
- spec/fixtures/inconsistent_types/en.yml
|
148
153
|
- spec/fixtures/inconsistent_types/he.yml
|
149
154
|
- spec/fixtures/invalid_yml/en.yml
|