haml_i18n_lint 0.6.0 → 0.7.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: 8d9ee40768e6218d8c809a750e54a587c8b2bba3
4
- data.tar.gz: da8a2c1bc972dc38f885813df2a0d002a9e02556
3
+ metadata.gz: fba6d5c77e333974e53abb7dcdd20f2d7422d686
4
+ data.tar.gz: 4eb6802848c56cf739814e16c008661124c6a064
5
5
  SHA512:
6
- metadata.gz: e27accffb82430ba7df4be43f1b14f2209b1e393b730a23f07105f01468f7f90af4d3468063051616e1930ef0b3af3b66b074dae0992fbdd6173b935be95ea3f
7
- data.tar.gz: 00e39c081bf4ea7244bb7509f7432af30969c004d60643b484f082892fe6ee81feeabbb28701402706ce0e7cc0d016171f077219a4744a45989706bc174e5c22
6
+ metadata.gz: d43e795c867d365cb13d305838e6e073a58ca355c0d19b6c44666a99900c47e7842d4a128a9e8d708e9766095c0813fb31babc1cf1bd33ba2216d929fc303a4c
7
+ data.tar.gz: 3de43811603c2d3c223a0b7a7884d1b6eba9e7b1ebb4f7e629a9932095f951587f9b8cef6b477b8cb43e0e7f0fa037f2c8f4fce4972527b2510f7e5b6031d119
checksums.yaml.gz.sig CHANGED
@@ -1,3 +1,3 @@
1
- I&� ��[if\ D
2
- ��Ǘb:/S.:P;ߪ�ɧ� o���EN�T-lZ"W��x�,�Ww����6&��ּ�^[k;�
3
- R]Ȋ�G�����b+B40��� z�� ����:A6��W���oiU��6��|������������Ѵ"qpa��%wW�>7��#?b��=L����N�M�vT� ��/�d�|�5� �Jٚ)W")ja�� ���11��x̢�)D��
1
+ ~ ��UXbV��F}?�o��ovc� �kƶ6m�;�]�_�p�
2
+ .�Pu��F���m��:���CX"��[ �������m?�(NM�#U�,01�16�7�!]zy&�I4m�Ke��n ����|d�۫�歐qT����k�l¹B���쌣�/�y����a�O�f��e��.񬲦��ƀ�t��k�]�?�D�U���
3
+
@@ -42,12 +42,22 @@ module HamlI18nLint
42
42
 
43
43
  # @return [String] the list of methods, which takes string. The string is no translation required.
44
44
  def ignore_methods
45
- %w(t render)
45
+ %w(
46
+ asset_path
47
+ image_path
48
+ image_tag
49
+ javascript_include_tag
50
+ pluralize
51
+ render
52
+ singularize
53
+ stylesheet_link_tag
54
+ t
55
+ )
46
56
  end
47
57
 
48
58
  # @return [String] the list of key of attributes hash. The key is no translation required.
49
59
  def ignore_keys
50
- %w(id class method controller action type lang selected checked src href rel language media)
60
+ %w(id class style type lang selected checked href src language rel media method controller action)
51
61
  end
52
62
 
53
63
  private
@@ -19,32 +19,7 @@ module HamlI18nLint
19
19
  def lint_attribute_need_i18n?
20
20
  attributes_hashes = lint_attributes_hashes
21
21
  attributes_hashes.any? do |attributes_hash|
22
- sexp = Ripper.sexp("{#{attributes_hash}}")
23
- program, ((hash,(assoclist_from_args,assocs)),) = sexp
24
-
25
- unless program == :program &&
26
- hash == :hash &&
27
- assoclist_from_args == :assoclist_from_args &&
28
- assocs.respond_to?(:all?) &&
29
- assocs.all? { |assoc| assoc.first == :assoc_new }
30
- raise AttributesParseError
31
- end
32
-
33
- assocs.any? do |assoc|
34
- assoc_new, (_label, key, _pos), value = assoc
35
-
36
- next if lint_config.ignore_keys.any? { |k| "#{k}:" == key }
37
-
38
- raise AttributesParseError unless assoc_new == :assoc_new
39
-
40
- string_literal, *strings = value
41
- next unless string_literal == :string_literal
42
- strings.any? do |(string_content, (tstring_content,val,pos))|
43
- string_content == :string_content &&
44
- tstring_content == :@tstring_content &&
45
- lint_config.need_i18n?(val)
46
- end
47
- end
22
+ script_need_i18n?("{#{attributes_hash}}")
48
23
  end
49
24
  end
50
25
 
@@ -52,6 +27,7 @@ module HamlI18nLint
52
27
  super
53
28
  if @node.value[:parse]
54
29
  lint_add_matched_node(@node) if script_need_i18n?(@node.value[:value])
30
+
55
31
  else
56
32
  lint_add_matched_node(@node) if lint_config.need_i18n?(@node.value[:value])
57
33
  end
@@ -62,27 +38,96 @@ module HamlI18nLint
62
38
 
63
39
  private
64
40
 
41
+ def lint_aref?(sexp)
42
+ sexp.first == :aref
43
+ end
44
+
45
+ def lint_assoc_new?(sexp, key)
46
+ return false unless sexp.first == :assoc_new
47
+
48
+ _assoc_new, assoc_key, _value = sexp
49
+
50
+ type, k, _lineno = assoc_key
51
+
52
+ case type
53
+ when :@label
54
+ return k == "#{key}:"
55
+ when :dyna_symbol
56
+ return k.size == 2 &&
57
+ k.first == :string_content &&
58
+ k.last[0] == :@tstring_content &&
59
+ k.last[1] == key
60
+ end
61
+
62
+ false
63
+ end
64
+
65
+ def lint_command?(sexp, method_name)
66
+ return unless sexp.first == :command
67
+
68
+ _command, (ident, m, _lineno), * = sexp
69
+
70
+ ident == :@ident && m == method_name
71
+ end
72
+
73
+ def lint_fcall?(sexp, method_name)
74
+ return unless sexp.first == :method_add_arg
75
+
76
+ _method_add_arg, (fcall, (ident, m, _lineno)), * = sexp
77
+
78
+ fcall == :fcall && ident == :@ident && m == method_name
79
+ end
80
+
81
+ def lint_call?(sexp, method_name)
82
+ return unless sexp.first == :method_add_arg
83
+
84
+ _method_add_arg, (call, _receiver, _dot, (ident, m, _lineno)), * = sexp
85
+
86
+ call == :call && ident == :@ident && m == method_name
87
+ end
88
+
89
+ def lint_string_literal?(sexp)
90
+ sexp.first == :string_literal
91
+ end
92
+
93
+ def lint_string_literal_need_i18n?(sexp)
94
+ exps = sexp.flatten
95
+ exps.each_with_index.any? do |exp, i|
96
+ exp == :@tstring_content && exps[i + 1].is_a?(String) && lint_config.need_i18n?(exps[i + 1])
97
+ end
98
+ end
99
+
100
+ def lint_ignore_method?(sexp, m)
101
+ lint_command?(sexp, m) || lint_fcall?(sexp, m) || lint_call?(sexp, m)
102
+ end
103
+
65
104
  def script_need_i18n?(script)
66
105
  script = script.dup
67
106
  if Ripper.lex(script.rstrip).any? { |(_, on_kw, kw_do)| on_kw == :on_kw && kw_do == "do" }
68
107
  script << "\nend\n"
69
108
  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]
109
+ sexp = Ripper.sexp(script)
110
+
111
+ string_literal_found = false
112
+ walk = -> (sexp) do
113
+ return if !sexp.is_a?(Array)
114
+ return if lint_aref?(sexp)
115
+ return if lint_config.ignore_methods.any? { |m| lint_ignore_method?(sexp, m) }
116
+ return if lint_config.ignore_keys.any? { |k| lint_assoc_new?(sexp, k) }
117
+
118
+ if lint_string_literal?(sexp) && lint_string_literal_need_i18n?(sexp)
119
+ string_literal_found = true
120
+ return
76
121
  end
77
- end
78
122
 
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
123
+ sexp.each do |sexp|
124
+ walk.(sexp)
82
125
  end
83
126
  end
84
127
 
85
- str_num != tstr_num + ignore_key_num
128
+ walk.(sexp)
129
+
130
+ string_literal_found
86
131
  end
87
132
 
88
133
  end
@@ -1,3 +1,3 @@
1
1
  module HamlI18nLint
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.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.6.0
4
+ version: 0.7.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-05 00:00:00.000000000 Z
33
+ date: 2017-05-06 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: haml
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.6.8
171
+ rubygems_version: 2.6.11
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: find out not translated yet plain text from your Haml template
metadata.gz.sig CHANGED
Binary file