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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/haml_i18n_lint/config.rb +5 -0
- data/lib/haml_i18n_lint/linter/compiler_extension.rb +36 -16
- data/lib/haml_i18n_lint/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d9ee40768e6218d8c809a750e54a587c8b2bba3
|
4
|
+
data.tar.gz: da8a2c1bc972dc38f885813df2a0d002a9e02556
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
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
|
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.
|
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-
|
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
|