immosquare-cleaner 0.1.83 → 0.1.84

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1ef4621cff404769813cf6e8de68d657912a80e590f8626f6fb7b4e92c214e9
4
- data.tar.gz: 427c3a61e31512a98a566f1ff786aeca114f7843bc707e4c1aa0de130adfb411
3
+ metadata.gz: 5db4cb8de23d20003df752fda8dc72588776050a743e6c4f24cfaf9004e1a975
4
+ data.tar.gz: 94dd38d03de54e6a216a83eec05f4ee92ddf8154e2552ec8b1930a53d8c4a295
5
5
  SHA512:
6
- metadata.gz: 1e6a3fda2aab18322d56d2c580248cbfaba77c8c68c780c5aad461bcb832215a4062ff2da3eee716db76f9883bcea4cb793e8ba3fff43964407206f96240d270
7
- data.tar.gz: 88535ccc05485fc89947862c3032abad0d9fe85113dc54e5aa953a56b4b9bce2a2ab974ae6165616be6d90124783c1dabf7ae99649b76a4b1aa02c6f03c87495
6
+ metadata.gz: 86c068a18ff2ef426704c1585d940f9ce702f026b98c37e67797b8a12fe93a5232ad21cadf1cbebdb5b6fcd7ca678a8956747e1d4c547710ec9a672106b7325a
7
+ data.tar.gz: fae01ff6fb1c24ec38f95ca92095b17e85d8024f9fd35372941ce14a862a0a7dc00db3361545f6199620ebefdceb735cbd42c772d96bc7bbada453a575bb409f
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.83".freeze
2
+ VERSION = "0.1.84".freeze
3
3
  end
@@ -0,0 +1,18 @@
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
@@ -26,7 +26,23 @@ module ERBLint
26
26
  ## Void elements that cannot have content (self-closing tags)
27
27
  ##============================================================##
28
28
  VOID_ELEMENTS = [
29
- "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr"
29
+ "area",
30
+ "base",
31
+ "br",
32
+ "col",
33
+ "command",
34
+ "embed",
35
+ "hr",
36
+ "img",
37
+ "input",
38
+ "keygen",
39
+ "link",
40
+ "menuitem",
41
+ "meta",
42
+ "param",
43
+ "source",
44
+ "track",
45
+ "wbr"
30
46
  ].freeze
31
47
 
32
48
  ##============================================================##
@@ -44,7 +60,70 @@ module ERBLint
44
60
  ##============================================================##
45
61
  EXCLUDED_METHODS = [
46
62
  "render",
47
- "content_tag"
63
+ "content_tag",
64
+ "image_tag"
65
+ ].freeze
66
+
67
+ ##============================================================##
68
+ ## HTML tags that should not be converted to content_tag
69
+ ## These tags are more readable as HTML (tables, etc.)
70
+ ##============================================================##
71
+ EXCLUDED_TAGS = [
72
+ "th",
73
+ "td",
74
+ "tr",
75
+ "thead",
76
+ "tbody",
77
+ "tfoot",
78
+ "table",
79
+ "caption",
80
+ "colgroup"
81
+ ].freeze
82
+
83
+ ##============================================================##
84
+ ## Form builder methods - if called on a receiver, skip conversion
85
+ ## This detects form builders regardless of variable name (f, form, etc.)
86
+ ## Example: <div><%= f.input(:name) %></div> should stay as-is
87
+ ##============================================================##
88
+ FORM_BUILDER_METHODS = [
89
+ "input",
90
+ "label",
91
+ "text_field",
92
+ "text_area",
93
+ "password_field",
94
+ "hidden_field",
95
+ "file_field",
96
+ "check_box",
97
+ "radio_button",
98
+ "select",
99
+ "collection_select",
100
+ "collection_check_boxes",
101
+ "collection_radio_buttons",
102
+ "grouped_collection_select",
103
+ "date_select",
104
+ "time_select",
105
+ "datetime_select",
106
+ "date_field",
107
+ "time_field",
108
+ "datetime_field",
109
+ "datetime_local_field",
110
+ "month_field",
111
+ "week_field",
112
+ "url_field",
113
+ "email_field",
114
+ "number_field",
115
+ "range_field",
116
+ "search_field",
117
+ "telephone_field",
118
+ "phone_field",
119
+ "color_field",
120
+ "submit",
121
+ "button",
122
+ "association",
123
+ "input_field",
124
+ "error",
125
+ "hint",
126
+ "full_error"
48
127
  ].freeze
49
128
 
50
129
  def run(processed_source)
@@ -61,6 +140,7 @@ module ERBLint
61
140
  tag_name = extract_tag_name(child)
62
141
  next if tag_name.nil?
63
142
  next if VOID_ELEMENTS.include?(tag_name.downcase)
143
+ next if EXCLUDED_TAGS.include?(tag_name.downcase)
64
144
 
65
145
  ##============================================================##
66
146
  ## Check if next child is text containing only ERB output
@@ -165,23 +245,32 @@ module ERBLint
165
245
  end
166
246
 
167
247
  ##============================================================##
168
- ## Check if the ERB code calls an excluded method
248
+ ## Check if the ERB code calls an excluded method or form builder
169
249
  ## Uses Prism parser for proper Ruby AST analysis
170
250
  ##============================================================##
171
251
  def excluded_method?(erb_code)
172
252
  return false unless erb_code
173
253
 
174
- method_name = extract_method_name(erb_code)
175
- return false unless method_name
254
+ call_node = extract_call_node(erb_code)
255
+ return false unless call_node
256
+
257
+ method_name = call_node.name.to_s
258
+ return true if EXCLUDED_METHODS.include?(method_name)
259
+
260
+ ##============================================================##
261
+ ## If method is a form builder method called on a receiver,
262
+ ## skip conversion (e.g., f.input, form.text_field, etc.)
263
+ ##============================================================##
264
+ return true if call_node.receiver && FORM_BUILDER_METHODS.include?(method_name)
176
265
 
177
- EXCLUDED_METHODS.include?(method_name)
266
+ false
178
267
  end
179
268
 
180
269
  ##============================================================##
181
- ## Extract the method name from Ruby code using Prism parser
270
+ ## Extract the CallNode from Ruby code using Prism parser
182
271
  ## Handles both direct calls and calls with if/unless modifiers
183
272
  ##============================================================##
184
- def extract_method_name(erb_code)
273
+ def extract_call_node(erb_code)
185
274
  result = Prism.parse(erb_code)
186
275
  return nil unless result.success?
187
276
 
@@ -190,13 +279,11 @@ module ERBLint
190
279
  ##============================================================##
191
280
  ## Handle if/unless modifiers: `render(...) if condition`
192
281
  ##============================================================##
193
- if node.is_a?(Prism::IfNode) || node.is_a?(Prism::UnlessNode)
194
- node = node.statements&.body&.first
195
- end
282
+ node = node.statements&.body&.first if node.is_a?(Prism::IfNode) || node.is_a?(Prism::UnlessNode)
196
283
 
197
284
  return nil unless node.is_a?(Prism::CallNode)
198
285
 
199
- node.name.to_s
286
+ node
200
287
  rescue StandardError
201
288
  nil
202
289
  end
@@ -71,9 +71,22 @@ module RuboCop
71
71
  end
72
72
 
73
73
  standalone_comments.each_with_index do |comment, index|
74
- next_comment = standalone_comments[index + 1]
74
+ next_comment = standalone_comments[index + 1]
75
+ comment_text = comment.text.strip
76
+ next_comment_text = next_comment&.text&.strip
77
+ is_double_hash = comment_text.start_with?("##")
75
78
 
76
- if next_comment && next_comment.location.line == comment.location.line + 1
79
+ ##============================================================##
80
+ ## On vérifie si le prochain commentaire est sur la ligne suivante
81
+ ## ET si les deux commentaires sont du même "type" (## ou #)
82
+ ## Cela permet de ne pas fusionner les commentaires temporaires
83
+ ## (# x = 1) avec les vrais commentaires (##)
84
+ ##============================================================##
85
+ next_is_double_hash = next_comment_text&.start_with?("##")
86
+ same_type = is_double_hash == next_is_double_hash
87
+ next_line_contiguous = next_comment && next_comment.location.line == comment.location.line + 1
88
+
89
+ if next_line_contiguous && same_type
77
90
  current_block << comment
78
91
  else
79
92
  current_block << comment
@@ -2,28 +2,32 @@ module RuboCop
2
2
  module Cop
3
3
  module CustomCops
4
4
  module Style
5
- # This cop identifies usage of short Font Awesome prefix styles (e.g., 'fas', 'far', 'fal')
6
- # and suggests replacing them with the long version style (which is the standard since v6).
7
- #
8
- # Doc : https://docs.fontawesome.com/web/setup/upgrade/whats-changed#full-style-names
9
- #
10
- # @example
11
- # # bad
12
- # font_awesome_icon("fas fa-user")
13
- # font_awesome_icon("far fa-circle-info")
14
- # font_awesome_icon("fal fa-bell")
15
- #
16
- # # good
17
- # font_awesome_icon("fa-solid fa-user")
18
- # font_awesome_icon("fa-regular fa-circle-info")
19
- # font_awesome_icon("fa-light fa-bell")
5
+ ##============================================================##
6
+ ## This cop identifies usage of short Font Awesome prefix styles (e.g., 'fas', 'far', 'fal')
7
+ ## and suggests replacing them with the long version style (which is the standard since v6).
8
+ ##
9
+ ## Doc : https://docs.fontawesome.com/web/setup/upgrade/whats-changed#full-style-names
10
+ ##
11
+ ## @example
12
+ ## bad
13
+ ## font_awesome_icon("fas fa-user")
14
+ ## font_awesome_icon("far fa-circle-info")
15
+ ## font_awesome_icon("fal fa-bell")
16
+ ##
17
+ ## good
18
+ ## font_awesome_icon("fa-solid fa-user")
19
+ ## font_awesome_icon("fa-regular fa-circle-info")
20
+ ## font_awesome_icon("fa-light fa-bell")
21
+ ##============================================================##
20
22
  class FontAwesomeNormalization < RuboCop::Cop::Base
21
23
 
22
24
  extend AutoCorrector
23
25
 
24
26
  MSG = "Use long version Font Awesome style prefix instead of short version.".freeze
25
27
 
26
- # Mapping from short prefixes to long prefixes
28
+ ##============================================================##
29
+ ## Mapping from short prefixes to long prefixes
30
+ ##============================================================##
27
31
  FA_PREFIX_MAP = {
28
32
  "fas" => "fa-solid",
29
33
  "far" => "fa-regular",
@@ -44,11 +48,11 @@ module RuboCop
44
48
  "fab" => "fa-brands"
45
49
  }.freeze
46
50
 
47
- def_node_matcher :font_awesome_icon_call?, <<~PATTERN
51
+ def_node_matcher(:font_awesome_icon_call?, <<~PATTERN)
48
52
  (send nil? :font_awesome_icon $...)
49
53
  PATTERN
50
54
 
51
- def_node_matcher :string_argument?, <<~PATTERN
55
+ def_node_matcher(:string_argument?, <<~PATTERN)
52
56
  (str $_)
53
57
  PATTERN
54
58
 
@@ -93,7 +97,9 @@ module RuboCop
93
97
  corrector.replace(node, replacement)
94
98
  end
95
99
 
96
- # Once we've found a match, no need to check other prefixes
100
+ ##============================================================##
101
+ ## Once we've found a match, no need to check other prefixes
102
+ ##============================================================##
97
103
  break
98
104
  end
99
105
  end
@@ -107,12 +107,104 @@ Style/MethodCallWithArgsParentheses:
107
107
  - raise
108
108
  - fail
109
109
  - gem
110
+ - group
110
111
  - source
111
112
  - ruby
112
113
  - desc
113
114
  - task
114
115
  - namespace
115
116
  - yield
117
+ - install_plugin
118
+ - before_action
119
+ - after_action
120
+ - skip_before_action
121
+ - around_action
122
+ - before_filter
123
+ - after_filter
124
+ - around_filter
125
+ - validates
126
+ - validates_presence_of
127
+ - validates_uniqueness_of
128
+ - validates_length_of
129
+ - validates_format_of
130
+ - validates_numericality_of
131
+ - validates_inclusion_of
132
+ - validates_exclusion_of
133
+ - validates_confirmation_of
134
+ - validates_acceptance_of
135
+ - validates_absence_of
136
+ - validates_associated
137
+ - validates_each
138
+ - validates_with
139
+ - validates_with_method
140
+ - validates_with_method_name
141
+ - validates_with_method_name_and_arguments
142
+ - validates_with_method_name_and_arguments_and_options
143
+ - belongs_to
144
+ - has_many
145
+ - has_one
146
+ - has_many_through
147
+ - has_one_through
148
+ - has_many_and_belongs_to_many
149
+ - has_many_and_belongs_to_many_through
150
+ - has_many_and_belongs_to_many_through_through
151
+ - has_many_and_belongs_to_many_through_through_through
152
+ - has_many_and_belongs_to_many_through_through_through_through
153
+ - before_validation
154
+ - after_validation
155
+ - around_validation
156
+ - before_save
157
+ - after_save
158
+ - around_save
159
+ - before_create
160
+ - after_create
161
+ - around_create
162
+ - before_update
163
+ - after_update
164
+ - around_update
165
+ - before_destroy
166
+ - after_destroy
167
+ - around_destroy
168
+ - before_commit
169
+ - after_commit
170
+ - around_commit
171
+ - before_validation
172
+ - after_validation
173
+ - around_validation
174
+ - before_save
175
+ - after_save
176
+ - around_save
177
+ - before_create
178
+ - after_create
179
+ - around_create
180
+ - before_update
181
+ - after_update
182
+ - around_update
183
+ - before_destroy
184
+ - after_destroy
185
+ - around_destroy
186
+ - before_commit
187
+ - after_commit
188
+ - around_commit
189
+ - before_validation
190
+ - after_validation
191
+ - around_validation
192
+ - before_save
193
+ - after_save
194
+ - around_save
195
+ - before_create
196
+ - after_create
197
+ - around_create
198
+ - before_update
199
+ - after_update
200
+ - around_update
201
+ - before_destroy
202
+ - after_destroy
203
+ - around_destroy
204
+ - before_commit
205
+ - after_commit
206
+ - around_commit
207
+ - serialize
116
208
  CustomCops/Style/CommentNormalization:
117
209
  Enabled: true
118
210
  CustomCops/Style/FontAwesomeNormalization:
data/linters/rubocop.yml CHANGED
@@ -111,6 +111,7 @@ Style/MethodCallWithArgsParentheses:
111
111
  EnforcedStyle: require_parentheses
112
112
  IgnoreMacros: false
113
113
  AllowedMethods:
114
+ ## Ruby core
114
115
  - require
115
116
  - require_relative
116
117
  - include
@@ -118,13 +119,74 @@ Style/MethodCallWithArgsParentheses:
118
119
  - prepend
119
120
  - raise
120
121
  - fail
122
+ - yield
123
+ - attr_accessor
124
+ - attr_reader
125
+ - attr_writer
126
+ ## Bundler / Gemfile
121
127
  - gem
128
+ - group
122
129
  - source
123
130
  - ruby
131
+ - install_plugin
132
+ ## Rake
124
133
  - desc
125
134
  - task
126
135
  - namespace
127
- - yield
136
+ ## Rails Controller
137
+ - before_action
138
+ - after_action
139
+ - around_action
140
+ - skip_before_action
141
+ - prepend_before_action
142
+ - append_before_action
143
+ - helper_method
144
+ - layout
145
+ - rescue_from
146
+ ## Rails Model - Associations
147
+ - belongs_to
148
+ - has_many
149
+ - has_one
150
+ - has_and_belongs_to_many
151
+ ## Rails Model - Validations
152
+ - validates
153
+ - validate
154
+ - validates_presence_of
155
+ - validates_uniqueness_of
156
+ - validates_length_of
157
+ - validates_format_of
158
+ - validates_numericality_of
159
+ - validates_inclusion_of
160
+ - validates_exclusion_of
161
+ - validates_confirmation_of
162
+ - validates_acceptance_of
163
+ - validates_absence_of
164
+ - validates_associated
165
+ - validates_each
166
+ - validates_with
167
+ ## Rails Model - Callbacks
168
+ - after_initialize
169
+ - after_find
170
+ - before_validation
171
+ - after_validation
172
+ - before_save
173
+ - after_save
174
+ - around_save
175
+ - before_create
176
+ - after_create
177
+ - around_create
178
+ - before_update
179
+ - after_update
180
+ - around_update
181
+ - before_destroy
182
+ - after_destroy
183
+ - around_destroy
184
+ - after_touch
185
+ - after_commit
186
+ - after_rollback
187
+ ## Rails Model - Other
188
+ - delegate
189
+ - enum
128
190
 
129
191
  #################### CUSTOMS ###########################
130
192
  CustomCops/Style/CommentNormalization:
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.83
4
+ version: 0.1.84
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare
@@ -147,6 +147,7 @@ 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
150
151
  - linters/erb-lint.yml
151
152
  - linters/erb_lint/custom_html_to_content_tag.rb
152
153
  - linters/erb_lint/custom_single_line_if_modifier.rb