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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e8456ef2611d6bf089a626ad29353e035ec5064
4
- data.tar.gz: da9122a2e4a22c9f88db778b5c0e3736fe8b9165
3
+ metadata.gz: 77d97bf3baf6728ffb9da7c658caa53775fbd621
4
+ data.tar.gz: e8b5e202a428c260fe0978bf9ef1353cd39c677a
5
5
  SHA512:
6
- metadata.gz: 4f40e01f2e5edbb98aedeba67008c5cb549cf558b102789ad664d8149e6f8d27524578b2969f968c1b1791edfdfea0d9e95650d5d14c916e5bf3aea126a510c8
7
- data.tar.gz: 5f5f42e97a15a02487227322986559d2096b9b1ba7ec73d3c91e76885bfb1b727a41e4501e00e0b1316ac91a38bfb7610e4aaa0724a057aea4e38b4378323776
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yaml-validator (0.1.5)
4
+ yaml-validator (0.1.7)
5
5
  colorize
6
6
  rake
7
7
  rspec
@@ -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.missing?
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.sanitize?
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
@@ -1,3 +1,3 @@
1
1
  class YamlValidator
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -0,0 +1,4 @@
1
+ en:
2
+ key1: |-
3
+ line1
4
+ line2
@@ -0,0 +1,2 @@
1
+ he:
2
+ key1: line1 ⏎ line2
@@ -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.6
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-09-15 00:00:00.000000000 Z
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