polint 0.2.0 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d183c6f2819c7036fef793ace5644f76349b3f24
4
- data.tar.gz: e8a9bcda101105ce78e492790021fae4643cc015
2
+ SHA256:
3
+ metadata.gz: f744d2e7bb0a9fc647d2c748156c429eaafd19a3a64be8108d014847036692db
4
+ data.tar.gz: b59ef6a71f426e6e450965cf310b2d266876f7324428c2ffe1f6500692316b27
5
5
  SHA512:
6
- metadata.gz: 0dbb533fad098c6a220f317b8e88c910e2c80fa8fee04902b934c0f067b66d1f278b77c99319d1f3566d35329362ec5e30d22d14fada4e16b93706eb5b002ce4
7
- data.tar.gz: 14b55b4f3a1d6078fe003ff097d6a574c7a77a483b2bcc7d513d8654b565258c375715531c82ccc420753d3bb4e30cde10788986e2a57811bd259948d5c72772
6
+ metadata.gz: c21194377b3172e5c21d23986122edbbd7f770ecb3d8382b9243e3c85d62160b9ad34249970d3df58c57914215c55abb33bc3bbf02bf054b42f08127b1f5f003
7
+ data.tar.gz: 1bc81e36b32b77cde0aff2bdf4585beb42462b8b369b2533d2d7866d6767d9318f697244ce89d72611ef171f9af9d8dc7f9f4217919312f0d57b92085c50ac99
data/Gemfile.lock CHANGED
@@ -1,86 +1,82 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- polint (0.1.0)
5
- parslet (~> 1.7, >= 1.7.1)
4
+ polint (0.2.3)
5
+ parslet (~> 1.8)
6
6
  term-ansicolor
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- blankslate (3.1.3)
12
- byebug (9.0.5)
13
- coderay (1.1.1)
14
- diff-lcs (1.2.5)
15
- ffi (1.9.10)
16
- formatador (0.2.5)
17
- guard (2.14.0)
11
+ byebug (11.1.3)
12
+ coderay (1.1.3)
13
+ diff-lcs (1.5.0)
14
+ ffi (1.15.5)
15
+ formatador (1.1.0)
16
+ guard (2.18.0)
18
17
  formatador (>= 0.2.4)
19
18
  listen (>= 2.7, < 4.0)
20
- lumberjack (~> 1.0)
19
+ lumberjack (>= 1.0.12, < 2.0)
21
20
  nenv (~> 0.1)
22
21
  notiffany (~> 0.0)
23
- pry (>= 0.9.12)
22
+ pry (>= 0.13.0)
24
23
  shellany (~> 0.0)
25
24
  thor (>= 0.18.1)
26
25
  guard-compat (1.2.1)
27
- guard-rspec (4.7.2)
26
+ guard-rspec (4.7.3)
28
27
  guard (~> 2.1)
29
28
  guard-compat (~> 1.1)
30
29
  rspec (>= 2.99.0, < 4.0)
31
- listen (3.1.5)
32
- rb-fsevent (~> 0.9, >= 0.9.4)
33
- rb-inotify (~> 0.9, >= 0.9.7)
34
- ruby_dep (~> 1.2)
35
- lumberjack (1.0.10)
36
- method_source (0.8.2)
30
+ listen (3.7.1)
31
+ rb-fsevent (~> 0.10, >= 0.10.3)
32
+ rb-inotify (~> 0.9, >= 0.9.10)
33
+ lumberjack (1.2.8)
34
+ method_source (1.0.0)
37
35
  nenv (0.3.0)
38
- notiffany (0.1.0)
36
+ notiffany (0.1.3)
39
37
  nenv (~> 0.1)
40
38
  shellany (~> 0.0)
41
- parslet (1.7.1)
42
- blankslate (>= 2.0, <= 4.0)
43
- pry (0.10.3)
44
- coderay (~> 1.1.0)
45
- method_source (~> 0.8.1)
46
- slop (~> 3.4)
47
- pry-byebug (3.4.0)
48
- byebug (~> 9.0)
49
- pry (~> 0.10)
50
- rake (10.5.0)
51
- rb-fsevent (0.9.7)
52
- rb-inotify (0.9.7)
53
- ffi (>= 0.5.0)
54
- rspec (3.4.0)
55
- rspec-core (~> 3.4.0)
56
- rspec-expectations (~> 3.4.0)
57
- rspec-mocks (~> 3.4.0)
58
- rspec-core (3.4.4)
59
- rspec-support (~> 3.4.0)
60
- rspec-expectations (3.4.0)
39
+ parslet (1.8.2)
40
+ pry (0.14.1)
41
+ coderay (~> 1.1)
42
+ method_source (~> 1.0)
43
+ pry-byebug (3.10.1)
44
+ byebug (~> 11.0)
45
+ pry (>= 0.13, < 0.15)
46
+ rake (13.0.6)
47
+ rb-fsevent (0.11.1)
48
+ rb-inotify (0.10.1)
49
+ ffi (~> 1.0)
50
+ rspec (3.11.0)
51
+ rspec-core (~> 3.11.0)
52
+ rspec-expectations (~> 3.11.0)
53
+ rspec-mocks (~> 3.11.0)
54
+ rspec-core (3.11.0)
55
+ rspec-support (~> 3.11.0)
56
+ rspec-expectations (3.11.0)
61
57
  diff-lcs (>= 1.2.0, < 2.0)
62
- rspec-support (~> 3.4.0)
63
- rspec-mocks (3.4.1)
58
+ rspec-support (~> 3.11.0)
59
+ rspec-mocks (3.11.1)
64
60
  diff-lcs (>= 1.2.0, < 2.0)
65
- rspec-support (~> 3.4.0)
66
- rspec-support (3.4.1)
67
- ruby_dep (1.3.1)
61
+ rspec-support (~> 3.11.0)
62
+ rspec-support (3.11.0)
68
63
  shellany (0.0.1)
69
- slop (3.6.0)
70
- term-ansicolor (1.3.2)
64
+ sync (0.5.0)
65
+ term-ansicolor (1.7.1)
71
66
  tins (~> 1.0)
72
- thor (0.19.1)
73
- tins (1.10.2)
67
+ thor (1.2.1)
68
+ tins (1.31.1)
69
+ sync
74
70
 
75
71
  PLATFORMS
76
- ruby
72
+ x86_64-linux
77
73
 
78
74
  DEPENDENCIES
79
- bundler (~> 1.7)
75
+ bundler (~> 2.3)
80
76
  guard-rspec
81
77
  polint!
82
78
  pry-byebug
83
- rake (~> 10.0)
79
+ rake (~> 13.0)
84
80
 
85
81
  BUNDLED WITH
86
- 1.12.5
82
+ 2.3.6
data/lib/polint/parser.rb CHANGED
@@ -33,7 +33,8 @@ module Polint
33
33
  rule(:flag) { str(',') >> lwsp >> match(/[a-z\-]/).repeat(1).as(:flag) >> lwsp }
34
34
  rule(:flag_comment) { start_comment >> flag.repeat(1).as(:flags) >> endl }
35
35
  rule(:reference_comment) { start_comment >> str(':') >> lwsp >> match(/[^\n]/).repeat.as(:reference) >> endl }
36
- rule(:comment) { flag_comment | reference_comment }
36
+ rule(:unparsed_comment) { start_comment >> match(/[^~]/) >> lwsp >> match(/[^\n]/).repeat.as(:comment) >> endl }
37
+ rule(:comment) { flag_comment | reference_comment | unparsed_comment }
37
38
  rule(:comments) { comment.repeat }
38
39
 
39
40
  rule(:msgid) { str('msgid') >> lwsp >> quoted_strings.as(:msgid) }
@@ -42,10 +43,14 @@ module Polint
42
43
  rule(:index) { str('[') >> match(/[0-9]/).repeat(1).as(:index) >> str(']') }
43
44
  rule(:msgstr) { str('msgstr') >> (index.maybe >> lwsp >> quoted_strings).as(:msgstr) }
44
45
 
45
- rule(:translation) { (comments >> msgid >> msgid_plural.maybe >> msgstr.repeat(1)).as(:translation) >> blank_line }
46
+ rule(:translation) { (comments >> msgid >> msgid_plural.repeat(0, 1) >> msgstr.repeat(1)).as(:translation) >> blank_line }
46
47
  rule(:translations) { translation.repeat }
47
48
 
48
- rule(:file) { (headers >> translations).as(:file) }
49
+ rule(:obsolete_line) { start_comment >> str('~') >> lwsp >> match(/[^\n]/).repeat >> endl }
50
+ rule(:obsolete_translation) { (comment.repeat >> obsolete_line.repeat(1).as(:text)).as(:obsolete_translation) >> blank_line }
51
+ rule(:obsolete_translations) { obsolete_translation.repeat }
52
+
53
+ rule(:file) { (headers >> translations >> obsolete_translations).as(:file) }
49
54
  root(:file)
50
55
 
51
56
  end
@@ -16,12 +16,12 @@ module Polint
16
16
  { headers: items.to_h }
17
17
  end
18
18
 
19
- rule(msgid: sequence(:items)) { { msgid: { text: items.join("\n") } } }
20
- rule(msgid_plural: sequence(:items)) { { msgid_plural: { text: items.join("\n") } } }
19
+ rule(msgid: sequence(:items)) { { msgid: { text: items.join } } }
20
+ rule(msgid_plural: sequence(:items)) { { msgid_plural: { text: items.join } } }
21
21
  rule(msgstr: subtree(:items)) do
22
22
  msgstr = {}
23
23
  msgstr[:index] = items.shift[:index].to_i if items.first.is_a?(Hash)
24
- msgstr[:text] = items.join("\n")
24
+ msgstr[:text] = items.join
25
25
  { msgstr: msgstr }
26
26
  end
27
27
 
@@ -29,6 +29,7 @@ module Polint
29
29
  translation = {
30
30
  flags: [],
31
31
  references: [],
32
+ comments: [],
32
33
  msgid: {},
33
34
  msgid_plural: {},
34
35
  msgstrs: []
@@ -38,6 +39,7 @@ module Polint
38
39
  case k
39
40
  when :flags then translation[:flags] |= v
40
41
  when :reference then translation[:references] << v
42
+ when :comment then translation[:comments] << v
41
43
  when :msgid, :msgid_plural then translation[k] = v
42
44
  when :msgstr then translation[:msgstrs] << v
43
45
  end
@@ -1,3 +1,3 @@
1
1
  module Polint
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/polint.rb CHANGED
@@ -120,7 +120,7 @@ module Polint
120
120
  tree = Polint::Parser.new.parse(data)
121
121
  tree = Polint::Transform.new.apply(tree)
122
122
 
123
- die 'No Plural-Forms header found' unless tree[:headers].key?('Plural-Forms')
123
+ die "The PO file '#{@pofile}' has no Plural-Forms header, aborting." unless tree[:headers].key?('Plural-Forms')
124
124
  nplurals = tree[:headers]['Plural-Forms'][:nplurals]
125
125
 
126
126
  tree[:translations].each do |translation|
@@ -150,7 +150,7 @@ module Polint
150
150
  end
151
151
  end
152
152
  rescue Parslet::ParseFailed => e
153
- die e.cause.ascii_tree
153
+ die "The PO file '#{@pofile}' cannot be parsed, aborting.\n\n#{e.cause.ascii_tree}"
154
154
  end
155
155
 
156
156
  # Check for errors in a key/translation pair.
data/polint.gemspec CHANGED
@@ -17,11 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.7"
21
- spec.add_development_dependency "rake", "~> 10.0"
20
+ spec.add_development_dependency "bundler", "~> 2.3"
21
+ spec.add_development_dependency "rake", "~> 13.0"
22
22
  spec.add_development_dependency "pry-byebug"
23
23
  spec.add_development_dependency "guard-rspec"
24
24
 
25
25
  spec.add_dependency "term-ansicolor"
26
- spec.add_dependency "parslet", "~> 1.7", ">= 1.7.1"
26
+ spec.add_dependency "parslet", "~> 1.8"
27
27
  end
@@ -16,3 +16,10 @@ msgid "Hello World Plural"
16
16
  msgid_plural "Hello %{n} Worlds Plural"
17
17
  msgstr[0] "Hello World Plural"
18
18
  msgstr[1] "Hello %{n} Worlds Plural"
19
+
20
+ # comment on obsolete translation
21
+ #~ msgid "Obsolete Translation"
22
+ #~ msgstr "Obsolete Translation"
23
+
24
+ #~ msgid "Another Obsolete Translation"
25
+ #~ msgstr "Another Obsolete Translation"
@@ -89,6 +89,30 @@ RSpec.describe Polint::Parser do
89
89
  end
90
90
  end
91
91
 
92
+ describe 'rule(:unparsed_comment)' do
93
+ let(:rule) { :unparsed_comment }
94
+
95
+ context 'when matching a translator comment' do
96
+ let(:line) { '# no semantics here' }
97
+ it { expect(tree).to eq comment: 'no semantics here' }
98
+ end
99
+
100
+ context 'when matching an extracted comment' do
101
+ let(:line) { '#. no semantics here' }
102
+ it { expect(tree).to eq comment: 'no semantics here' }
103
+ end
104
+
105
+ context 'when matching a previous translation comment' do
106
+ let(:line) { '#| no semantics here' }
107
+ it { expect(tree).to eq comment: 'no semantics here' }
108
+ end
109
+
110
+ context 'when matching an obsolete translation' do
111
+ let(:line) { '#~ obsolete things go here' }
112
+ it { expect{ tree }.to raise_error Parslet::ParseFailed }
113
+ end
114
+ end
115
+
92
116
  describe 'rule(:msgid)' do
93
117
  let(:rule) { :msgid }
94
118
 
@@ -207,6 +231,25 @@ RSpec.describe Polint::Parser do
207
231
  }
208
232
  end
209
233
 
234
+ context 'when matching without comments' do
235
+ let(:lines) {
236
+ [
237
+ 'msgid "Hello World"',
238
+ 'msgid_plural "Hello %{n} Worlds"',
239
+ 'msgstr[0] "Hello World"',
240
+ 'msgstr[1] "Hello %{n} Worlds"'
241
+ ]
242
+ }
243
+ it {
244
+ expect(tree).to eq translation: [
245
+ { msgid: [{ quoted_string: 'Hello World' }] },
246
+ { msgid_plural: [{ quoted_string: 'Hello %{n} Worlds' }] },
247
+ { msgstr: [{ index: '0' }, { quoted_string: 'Hello World' }] },
248
+ { msgstr: [{ index: '1' }, { quoted_string: 'Hello %{n} Worlds' }] }
249
+ ]
250
+ }
251
+ end
252
+
210
253
  # TODO: Multiline strings and negative cases
211
254
  end
212
255
 
@@ -255,4 +298,25 @@ RSpec.describe Polint::Parser do
255
298
  end
256
299
  end
257
300
 
301
+ describe 'rule(:obsolete_translation)' do
302
+ let(:rule) { :obsolete_translation }
303
+ let(:line) { lines.join("\n") }
304
+
305
+ context 'when matching a singular single-line msgstr with comments' do
306
+ let(:lines) {
307
+ [
308
+ '# comment on obsolete translation',
309
+ '#~ msgid "Hello World"',
310
+ '#~ msgstr "Hello World"'
311
+ ]
312
+ }
313
+ it {
314
+ expect(tree).to eq obsolete_translation: [
315
+ { comment: 'comment on obsolete translation' },
316
+ { text: %{#~ msgid "Hello World"\n#~ msgstr "Hello World"} }
317
+ ]
318
+ }
319
+ end
320
+ end
321
+
258
322
  end
@@ -37,10 +37,11 @@ RSpec.describe Polint::Transform do
37
37
  { flags: [{ flag: 'fuzzy' }] },
38
38
  { reference: '../../some_file.rb:34' },
39
39
  { reference: '../../some_other_file.rb:283' },
40
- { msgid: [{ quoted_string: [] }, { quoted_string: 'Hello World' }, { quoted_string: 'Hello Again'}] },
41
- { msgid_plural: [{ quoted_string: [] }, { quoted_string: 'Hello %{n} Worlds' }, { quoted_string: 'Hello Again'}] },
42
- { msgstr: [{ index: '0' }, { quoted_string: [] }, { quoted_string: 'Hello World' }, { quoted_string: 'Hello Again'}] },
43
- { msgstr: [{ index: '1' }, { quoted_string: [] }, { quoted_string: 'Hello %{n} Worlds' }, { quoted_string: 'Hello Again'}] }
40
+ { comment: 'arbitrary text' },
41
+ { msgid: [{ quoted_string: [] }, { quoted_string: 'Hello World\\n' }, { quoted_string: 'Hello Again'}] },
42
+ { msgid_plural: [{ quoted_string: [] }, { quoted_string: 'Hello %{n} Worlds\\n' }, { quoted_string: 'Hello Again'}] },
43
+ { msgstr: [{ index: '0' }, { quoted_string: [] }, { quoted_string: 'Hello World\\n' }, { quoted_string: 'Hello Again'}] },
44
+ { msgstr: [{ index: '1' }, { quoted_string: [] }, { quoted_string: 'Hello %{n} Worlds\\n' }, { quoted_string: 'Hello Again'}] }
44
45
  ]
45
46
  }
46
47
  }
@@ -48,11 +49,12 @@ RSpec.describe Polint::Transform do
48
49
  expect(output).to eq translation: {
49
50
  flags: [:fuzzy],
50
51
  references: ['../../some_file.rb:34', '../../some_other_file.rb:283'],
51
- msgid: { text: "\nHello World\nHello Again" },
52
- msgid_plural: { text: "\nHello %{n} Worlds\nHello Again" },
52
+ comments: ['arbitrary text'],
53
+ msgid: { text: 'Hello World\\nHello Again' },
54
+ msgid_plural: { text: 'Hello %{n} Worlds\\nHello Again' },
53
55
  msgstrs: [
54
- { index: 0, text: "\nHello World\nHello Again" },
55
- { index: 1, text: "\nHello %{n} Worlds\nHello Again" }
56
+ { index: 0, text: 'Hello World\\nHello Again' },
57
+ { index: 1, text: 'Hello %{n} Worlds\\nHello Again' }
56
58
  ]
57
59
  }
58
60
  }
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Letessier
8
8
  - Greg Beech
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-22 00:00:00.000000000 Z
12
+ date: 2022-08-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.7'
20
+ version: '2.3'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.7'
27
+ version: '2.3'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '10.0'
34
+ version: '13.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '10.0'
41
+ version: '13.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: pry-byebug
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -87,21 +87,15 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '1.7'
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: 1.7.1
90
+ version: '1.8'
94
91
  type: :runtime
95
92
  prerelease: false
96
93
  version_requirements: !ruby/object:Gem::Requirement
97
94
  requirements:
98
95
  - - "~>"
99
96
  - !ruby/object:Gem::Version
100
- version: '1.7'
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: 1.7.1
104
- description:
97
+ version: '1.8'
98
+ description:
105
99
  email:
106
100
  - julien.letessier@gmail.com
107
101
  - greg@gregbeech.com
@@ -136,7 +130,7 @@ homepage: ''
136
130
  licenses:
137
131
  - MIT
138
132
  metadata: {}
139
- post_install_message:
133
+ post_install_message:
140
134
  rdoc_options: []
141
135
  require_paths:
142
136
  - lib
@@ -151,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
145
  - !ruby/object:Gem::Version
152
146
  version: '0'
153
147
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.5.1
156
- signing_key:
148
+ rubygems_version: 3.2.22
149
+ signing_key:
157
150
  specification_version: 4
158
151
  summary: A linter for Uniforum PO files.
159
152
  test_files: