Class: RuboCop::Cop::Koi::TableAsset
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Koi::TableAsset
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/koi/table_asset.rb
Overview
Koi admin index tables should not render images or attachments. Index views are for scanning and comparing records; rendering assets makes rows uneven, slows the page down (variant generation and blob queries per row), and rarely helps identify a record. Display text in the table and show the asset on the record's page instead.
This cop flags row.attachment cells and image_tag/image_pack_tag
helpers. It does not autocorrect; it identifies a smell for a human to
resolve.
This cop only takes effect through erb_lint: plain rubocop does not
inspect .erb files, and the Include configuration restricts it to
Koi admin index views, so row.attachment in show views is fine.
Constant Summary collapse
- MSG_ATTACHMENT =
"Avoid attachments in index tables; display text in the table " \ "and show the attachment on the record's page instead."
- MSG_IMAGE =
"Avoid images in index tables; display text in the table " \ "and show the image on the record's page instead."
- RESTRICT_ON_SEND =
%i[attachment image_tag image_pack_tag].freeze
Instance Method Summary collapse
Instance Method Details
#image_helper?(node) ⇒ Object
49 50 51 |
# File 'lib/rubocop/cop/koi/table_asset.rb', line 49 def_node_matcher :image_helper?, <<~PATTERN (send nil? {:image_tag :image_pack_tag} ...) PATTERN |
#on_send(node) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/rubocop/cop/koi/table_asset.rb', line 53 def on_send(node) if (node) add_offense(node, message: MSG_ATTACHMENT) elsif image_helper?(node) add_offense(node, message: MSG_IMAGE) end end |
#row_attachment?(node) ⇒ Object
44 45 46 |
# File 'lib/rubocop/cop/koi/table_asset.rb', line 44 def_node_matcher :row_attachment?, <<~PATTERN (send {(send nil? :row) (lvar :row)} :attachment ...) PATTERN |