haml_i18n_lint 0.5.0 → 0.6.0

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
2
  SHA1:
3
- metadata.gz: 4bb308fd331c251ccf43f96620ade24c80174b2a
4
- data.tar.gz: e998ab3fb26a7513d2f87304d7ba8b0e9f044cf5
3
+ metadata.gz: 8d9ee40768e6218d8c809a750e54a587c8b2bba3
4
+ data.tar.gz: da8a2c1bc972dc38f885813df2a0d002a9e02556
5
5
  SHA512:
6
- metadata.gz: ac0d81447e3874683ec0ec58e1a7e58e934e1fd88366ffcce14275b1f6ca4e0e09776ac7351deba57d2775ae244d5b1c3135c97de2a989ea0309e46c01091efe
7
- data.tar.gz: ea03e92ab5db3ec31f3b73aa31e1afa06c0b7088e8f65bdf91c7cd15e14c85d6b089be654f99be9afc46191ab88fb35aaf9563888db3d08da91c9977e9bce290
6
+ metadata.gz: e27accffb82430ba7df4be43f1b14f2209b1e393b730a23f07105f01468f7f90af4d3468063051616e1930ef0b3af3b66b074dae0992fbdd6173b935be95ea3f
7
+ data.tar.gz: 00e39c081bf4ea7244bb7509f7432af30969c004d60643b484f082892fe6ee81feeabbb28701402706ce0e7cc0d016171f077219a4744a45989706bc174e5c22
checksums.yaml.gz.sig CHANGED
Binary file
@@ -45,6 +45,11 @@ module HamlI18nLint
45
45
  %w(t render)
46
46
  end
47
47
 
48
+ # @return [String] the list of key of attributes hash. The key is no translation required.
49
+ def ignore_keys
50
+ %w(id class method controller action type lang selected checked src href rel language media)
51
+ end
52
+
48
53
  private
49
54
 
50
55
  def load_config(config_content)
@@ -4,20 +4,7 @@ module HamlI18nLint
4
4
 
5
5
  def compile_script
6
6
  super
7
- if Ripper.lex(@node.value[:text].rstrip).any? { |(_, on_kw, kw_do)| on_kw == :on_kw && kw_do == "do" }
8
- program = Ripper.sexp(@node.value[:text] + "\nend").flatten
9
- else
10
- program = Ripper.sexp(@node.value[:text]).flatten
11
- end
12
- str_num = program.flatten.count { |t| t == :string_literal }
13
- tstr_num = program.each_with_index.count do |t, i|
14
- lint_config.ignore_methods.any? do |m|
15
- [t, program[i + 1], program[i + 2]] == [:fcall, :@ident, m.to_s] ||
16
- [t, program[i + 1], program[i + 2]] == [:command, :@ident, m.to_s]
17
- end
18
- end
19
-
20
- lint_add_matched_node(@node) unless str_num == tstr_num
7
+ lint_add_matched_node(@node) if script_need_i18n?(@node.value[:text])
21
8
  end
22
9
 
23
10
  def compile_plain
@@ -44,8 +31,12 @@ module HamlI18nLint
44
31
  end
45
32
 
46
33
  assocs.any? do |assoc|
47
- assoc_new, key, value = assoc
34
+ assoc_new, (_label, key, _pos), value = assoc
35
+
36
+ next if lint_config.ignore_keys.any? { |k| "#{k}:" == key }
37
+
48
38
  raise AttributesParseError unless assoc_new == :assoc_new
39
+
49
40
  string_literal, *strings = value
50
41
  next unless string_literal == :string_literal
51
42
  strings.any? do |(string_content, (tstring_content,val,pos))|
@@ -59,12 +50,41 @@ module HamlI18nLint
59
50
 
60
51
  def compile_tag
61
52
  super
62
- lint_add_matched_node(@node) if lint_config.need_i18n?(@node.value[:value])
53
+ if @node.value[:parse]
54
+ lint_add_matched_node(@node) if script_need_i18n?(@node.value[:value])
55
+ else
56
+ lint_add_matched_node(@node) if lint_config.need_i18n?(@node.value[:value])
57
+ end
63
58
  lint_add_matched_node(@node) if lint_config.need_i18n?(@node.value.dig(:attributes, 'placeholder') || "")
64
59
  lint_add_matched_node(@node) if lint_config.need_i18n?(@node.value.dig(:attributes, 'value') || "")
65
60
  lint_add_matched_node(@node) if lint_attribute_need_i18n?
66
61
  end
67
62
 
63
+ private
64
+
65
+ def script_need_i18n?(script)
66
+ script = script.dup
67
+ if Ripper.lex(script.rstrip).any? { |(_, on_kw, kw_do)| on_kw == :on_kw && kw_do == "do" }
68
+ script << "\nend\n"
69
+ end
70
+ program = Ripper.sexp(script).flatten
71
+ str_num = program.flatten.count { |t| t == :string_literal }
72
+ tstr_num = program.each_with_index.count do |t, i|
73
+ lint_config.ignore_methods.any? do |m|
74
+ [t, program[i + 1], program[i + 2]] == [:fcall, :@ident, m.to_s] ||
75
+ [t, program[i + 1], program[i + 2]] == [:command, :@ident, m.to_s]
76
+ end
77
+ end
78
+
79
+ ignore_key_num = program.count.times.count do |i|
80
+ lint_config.ignore_keys.any? do |k|
81
+ program[i, 3] == [:assoc_new, :@label, "#{k}:"] && program[i + 5] == :string_literal
82
+ end
83
+ end
84
+
85
+ str_num != tstr_num + ignore_key_num
86
+ end
87
+
68
88
  end
69
89
  end
70
90
  end
@@ -1,3 +1,3 @@
1
1
  module HamlI18nLint
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml_i18n_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seiei Miyagi
@@ -30,7 +30,7 @@ cert_chain:
30
30
  +zDzgwp9Z4A8i47ioz1YEGIkQhDKZeGQznwkht0zsrtswEAiOisL5uJDtWvQiwt6
31
31
  a9nBgrpUm8NHrucdUDtMYjixgmU=
32
32
  -----END CERTIFICATE-----
33
- date: 2017-05-04 00:00:00.000000000 Z
33
+ date: 2017-05-05 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: haml
metadata.gz.sig CHANGED
Binary file