rubocop-katalyst 3.2.0 → 3.3.1

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: ca026117c849f4df349fe5c67aed0695aedfc780a64af122996eb3d51fc3cc28
4
- data.tar.gz: db9a73d62f9d1f0005540ae233de188ce4fa7486272a06387ac72335b8bc3037
3
+ metadata.gz: 11bba14eda481aa2b0b923d0a9c9a7f42bf689dd7594ca716ca4789c3e5b9dd0
4
+ data.tar.gz: 8db7b93edab8ec321cbda7aa0004f43523938662541c106334c85b0fbe5013cf
5
5
  SHA512:
6
- metadata.gz: 752ce4174f0ea3121ba76a2cfe72c49771e0069dc4f940eda114f789ed13a73cc1dbe88558efb4a193765c3b5038003a8af8a2c3979a4b126d515d5b171304c2
7
- data.tar.gz: d9dd3b37ec0884d11b0d08a0ceb228315174b00ffdc6736246bd1da5e9f8271f7fa1d2af91809170d5ebfc2d0f664daba801d0d8b0ac5be4ed7d46b8150859c7
6
+ metadata.gz: d4bf9074a6d81aada7a002bb91da6956729e495e764d46050faefd503766ab8ffc04341dd193fae70d91bc793b863ad2d8e5f38703ed32cd2ede509e6cda1907
7
+ data.tar.gz: 3fc92a85f61b1c72da770a546fe7a25f687f5b1d8d426794ec2a8571dabe0e8fb94042092f9c959990d566edd7f5808b02daa59cfb74c30eb7dbe8a8a30a397f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [3.3.0] - 2026-08-18
2
+
3
+ - Add Koi/TableAsset cop: admin index tables (index/archived views and row
4
+ partials) should not render images or attachments. Flags `row.attachment`
5
+ cells and `image_tag`/`image_pack_tag` helpers as a smell, without
6
+ autocorrection.
7
+
1
8
  ## [3.2.0] - 2026-08-17
2
9
 
3
10
  - Add Koi/DuplicatesAssociation identifying Katalyst::Content items that
@@ -13,6 +13,19 @@ Koi/DuplicatesAssociation:
13
13
  Include:
14
14
  - "**/app/models/**/*.rb"
15
15
 
16
+ # Targets admin index views, which are only linted when RuboCop runs
17
+ # through erb_lint, so it takes effect via `rake erb_lint`.
18
+ Koi/TableAsset:
19
+ Description: "Index tables should not render images or attachments."
20
+ Enabled: true
21
+ Safe: true
22
+ SafeAutoCorrect: false
23
+ VersionAdded: "3.3"
24
+ Include:
25
+ - "**/app/views/admin/**/index.html.erb"
26
+ - "**/app/views/admin/**/archived.html.erb"
27
+ - "**/app/views/admin/**/*.html+row.erb"
28
+
16
29
  # Targets admin views, which are only linted when RuboCop runs through
17
30
  # erb_lint, so it takes effect via `rake erb_lint`.
18
31
  Koi/TableLinkHeading:
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "koi/duplicates_association"
4
+ require_relative "koi/table_asset"
4
5
  require_relative "koi/table_link_heading"
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Koi
6
+ # Koi admin index tables should not render images or attachments.
7
+ # Index views are for scanning and comparing records; rendering assets
8
+ # makes rows uneven, slows the page down (variant generation and blob
9
+ # queries per row), and rarely helps identify a record. Display text in
10
+ # the table and show the asset on the record's page instead.
11
+ #
12
+ # This cop flags `row.attachment` cells and `image_tag`/`image_pack_tag`
13
+ # helpers. It does not autocorrect; it identifies a smell for a human to
14
+ # resolve.
15
+ #
16
+ # This cop only takes effect through erb_lint: plain `rubocop` does not
17
+ # inspect `.erb` files, and the `Include` configuration restricts it to
18
+ # Koi admin index views, so `row.attachment` in show views is fine.
19
+ #
20
+ # @example
21
+ # # bad
22
+ # row.attachment :image, variant: :admin_thumb
23
+ #
24
+ # # bad
25
+ # row.cell(:image) { image_tag(record.image.variant(:thumb)) }
26
+ #
27
+ # # good
28
+ # row.text :name
29
+ class TableAsset < Base
30
+ # This cop never registers a correction, but it must advertise
31
+ # autocorrect support: erb_lint mobilizes RuboCop in autocorrect mode,
32
+ # where non-autocorrecting cops are skipped for any fragment that an
33
+ # autocorrecting cop has corrected (see RuboCop::Cop::Team).
34
+ extend AutoCorrector
35
+
36
+ MSG_ATTACHMENT = "Avoid attachments in index tables; display text in the table " \
37
+ "and show the attachment on the record's page instead."
38
+ MSG_IMAGE = "Avoid images in index tables; display text in the table " \
39
+ "and show the image on the record's page instead."
40
+
41
+ RESTRICT_ON_SEND = %i[attachment image_tag image_pack_tag].freeze
42
+
43
+ # @!method row_attachment?(node)
44
+ def_node_matcher :row_attachment?, <<~PATTERN
45
+ (send {(send nil? :row) (lvar :row)} :attachment ...)
46
+ PATTERN
47
+
48
+ # @!method image_helper?(node)
49
+ def_node_matcher :image_helper?, <<~PATTERN
50
+ (send nil? {:image_tag :image_pack_tag} ...)
51
+ PATTERN
52
+
53
+ def on_send(node)
54
+ if row_attachment?(node)
55
+ add_offense(node, message: MSG_ATTACHMENT)
56
+ elsif image_helper?(node)
57
+ add_offense(node, message: MSG_IMAGE)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-katalyst
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katalyst Interactive
@@ -161,6 +161,7 @@ files:
161
161
  - config/rubocop-style.yml
162
162
  - lib/rubocop/cop/katalyst_cops.rb
163
163
  - lib/rubocop/cop/koi/duplicates_association.rb
164
+ - lib/rubocop/cop/koi/table_asset.rb
164
165
  - lib/rubocop/cop/koi/table_link_heading.rb
165
166
  - lib/rubocop/katalyst.rb
166
167
  - lib/rubocop/katalyst/erb_lint_task.rb