immosquare-cleaner 0.1.81 → 0.1.83
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 +4 -4
- data/lib/immosquare-cleaner/version.rb +1 -1
- data/linters/erb_lint/custom_html_to_content_tag.rb +70 -10
- metadata +1 -2
- data/linters/erb-lint-3.4.1.yml +0 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1ef4621cff404769813cf6e8de68d657912a80e590f8626f6fb7b4e92c214e9
|
|
4
|
+
data.tar.gz: 427c3a61e31512a98a566f1ff786aeca114f7843bc707e4c1aa0de130adfb411
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1e6a3fda2aab18322d56d2c580248cbfaba77c8c68c780c5aad461bcb832215a4062ff2da3eee716db76f9883bcea4cb793e8ba3fff43964407206f96240d270
|
|
7
|
+
data.tar.gz: 88535ccc05485fc89947862c3032abad0d9fe85113dc54e5aa953a56b4b9bce2a2ab974ae6165616be6d90124783c1dabf7ae99649b76a4b1aa02c6f03c87495
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
3
5
|
module ERBLint
|
|
4
6
|
module Linters
|
|
5
7
|
##============================================================##
|
|
@@ -7,14 +9,15 @@ module ERBLint
|
|
|
7
9
|
## output statement and converts them to content_tag helpers.
|
|
8
10
|
##
|
|
9
11
|
## @example
|
|
10
|
-
##
|
|
12
|
+
## bad
|
|
11
13
|
## <div class="card-title"><%= t("app.title") %></div>
|
|
12
14
|
##
|
|
13
|
-
##
|
|
15
|
+
## good
|
|
14
16
|
## <%= content_tag(:div, t("app.title"), :class => "card-title") %>
|
|
15
17
|
##
|
|
16
18
|
##============================================================##
|
|
17
19
|
class CustomHtmlToContentTag < Linter
|
|
20
|
+
|
|
18
21
|
include LinterRegistry
|
|
19
22
|
|
|
20
23
|
MSG = "Use content_tag helper instead of HTML tag with ERB output."
|
|
@@ -22,9 +25,26 @@ module ERBLint
|
|
|
22
25
|
##============================================================##
|
|
23
26
|
## Void elements that cannot have content (self-closing tags)
|
|
24
27
|
##============================================================##
|
|
25
|
-
VOID_ELEMENTS =
|
|
26
|
-
area base br col command embed hr img input keygen
|
|
27
|
-
|
|
28
|
+
VOID_ELEMENTS = [
|
|
29
|
+
"area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"
|
|
30
|
+
].freeze
|
|
31
|
+
|
|
32
|
+
##============================================================##
|
|
33
|
+
## Methods that should not be converted to content_tag
|
|
34
|
+
## - render: partials should stay in HTML for readability
|
|
35
|
+
## - content_tag: prevents cascading on multiple erb_lint passes
|
|
36
|
+
##
|
|
37
|
+
## Note: If content_tag is removed from exclusions, additional
|
|
38
|
+
## logic is needed to prevent cascading conversions. The approach
|
|
39
|
+
## would be to check if the content_tag has HTML attributes
|
|
40
|
+
## (:class, :id) which indicates it was generated by us in a
|
|
41
|
+
## previous pass. See same_tag_content_tag? method pattern:
|
|
42
|
+
## - content_tag(:div, x, :class => "y") → skip (generated)
|
|
43
|
+
## - content_tag(:div, x) → allow (user-written)
|
|
44
|
+
##============================================================##
|
|
45
|
+
EXCLUDED_METHODS = [
|
|
46
|
+
"render",
|
|
47
|
+
"content_tag"
|
|
28
48
|
].freeze
|
|
29
49
|
|
|
30
50
|
def run(processed_source)
|
|
@@ -60,11 +80,15 @@ module ERBLint
|
|
|
60
80
|
next unless extract_tag_name(closing_child) == tag_name
|
|
61
81
|
|
|
62
82
|
##============================================================##
|
|
63
|
-
##
|
|
83
|
+
## Extract ERB code and check if it should be skipped
|
|
64
84
|
##============================================================##
|
|
65
|
-
attributes = extract_attributes(child)
|
|
66
85
|
erb_code = extract_erb_code(erb_node)
|
|
86
|
+
next if excluded_method?(erb_code)
|
|
67
87
|
|
|
88
|
+
##============================================================##
|
|
89
|
+
## Build the content_tag replacement
|
|
90
|
+
##============================================================##
|
|
91
|
+
attributes = extract_attributes(child)
|
|
68
92
|
new_code = build_content_tag(tag_name, erb_code, attributes)
|
|
69
93
|
|
|
70
94
|
##============================================================##
|
|
@@ -140,6 +164,43 @@ module ERBLint
|
|
|
140
164
|
code_node&.loc&.source&.strip
|
|
141
165
|
end
|
|
142
166
|
|
|
167
|
+
##============================================================##
|
|
168
|
+
## Check if the ERB code calls an excluded method
|
|
169
|
+
## Uses Prism parser for proper Ruby AST analysis
|
|
170
|
+
##============================================================##
|
|
171
|
+
def excluded_method?(erb_code)
|
|
172
|
+
return false unless erb_code
|
|
173
|
+
|
|
174
|
+
method_name = extract_method_name(erb_code)
|
|
175
|
+
return false unless method_name
|
|
176
|
+
|
|
177
|
+
EXCLUDED_METHODS.include?(method_name)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
##============================================================##
|
|
181
|
+
## Extract the method name from Ruby code using Prism parser
|
|
182
|
+
## Handles both direct calls and calls with if/unless modifiers
|
|
183
|
+
##============================================================##
|
|
184
|
+
def extract_method_name(erb_code)
|
|
185
|
+
result = Prism.parse(erb_code)
|
|
186
|
+
return nil unless result.success?
|
|
187
|
+
|
|
188
|
+
node = result.value.statements.body.first
|
|
189
|
+
|
|
190
|
+
##============================================================##
|
|
191
|
+
## Handle if/unless modifiers: `render(...) if condition`
|
|
192
|
+
##============================================================##
|
|
193
|
+
if node.is_a?(Prism::IfNode) || node.is_a?(Prism::UnlessNode)
|
|
194
|
+
node = node.statements&.body&.first
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
return nil unless node.is_a?(Prism::CallNode)
|
|
198
|
+
|
|
199
|
+
node.name.to_s
|
|
200
|
+
rescue StandardError
|
|
201
|
+
nil
|
|
202
|
+
end
|
|
203
|
+
|
|
143
204
|
##============================================================##
|
|
144
205
|
## Extract attributes from tag node as hash
|
|
145
206
|
##============================================================##
|
|
@@ -203,10 +264,8 @@ module ERBLint
|
|
|
203
264
|
## Check if value contains interpolation
|
|
204
265
|
##============================================================##
|
|
205
266
|
if value&.include?('#{')
|
|
206
|
-
"#{key} => \"#{value}\""
|
|
207
|
-
else
|
|
208
|
-
"#{key} => \"#{value}\""
|
|
209
267
|
end
|
|
268
|
+
"#{key} => \"#{value}\""
|
|
210
269
|
end.join(", ")
|
|
211
270
|
|
|
212
271
|
"<%= content_tag(:#{tag_name}, #{content}, #{attrs_str}) %>"
|
|
@@ -224,6 +283,7 @@ module ERBLint
|
|
|
224
283
|
":\"#{name}\""
|
|
225
284
|
end
|
|
226
285
|
end
|
|
286
|
+
|
|
227
287
|
end
|
|
228
288
|
end
|
|
229
289
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: immosquare-cleaner
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.83
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- immosquare
|
|
@@ -147,7 +147,6 @@ files:
|
|
|
147
147
|
- lib/immosquare-cleaner/railtie.rb
|
|
148
148
|
- lib/immosquare-cleaner/version.rb
|
|
149
149
|
- lib/tasks/immosquare_cleaner.rake
|
|
150
|
-
- linters/erb-lint-3.4.1.yml
|
|
151
150
|
- linters/erb-lint.yml
|
|
152
151
|
- linters/erb_lint/custom_html_to_content_tag.rb
|
|
153
152
|
- linters/erb_lint/custom_single_line_if_modifier.rb
|
data/linters/erb-lint-3.4.1.yml
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
EnableDefaultLinters: true
|
|
3
|
-
linters:
|
|
4
|
-
NoJavascriptTagHelper:
|
|
5
|
-
enabled: false
|
|
6
|
-
SpaceInHtmlTag:
|
|
7
|
-
enabled: false
|
|
8
|
-
CustomSingleLineIfModifier:
|
|
9
|
-
enabled: true
|
|
10
|
-
CustomHtmlToContentTag:
|
|
11
|
-
enabled: true
|
|
12
|
-
Rubocop:
|
|
13
|
-
enabled: true
|
|
14
|
-
rubocop_config:
|
|
15
|
-
inherit_from:
|
|
16
|
-
- linters/rubocop-3.4.1.yml
|
|
17
|
-
Layout/TrailingWhitespace:
|
|
18
|
-
Enabled: false
|