rubocop-katalyst 3.2.0 → 3.3.0

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: 04b7a088100580edc042b6f9197cfbb64c8b2aa3c8d978f0f4387f5774893d1c
4
+ data.tar.gz: 9bf922ffa58eb94577825d45d1e517e250cba503b0149f4fdde6858928777491
5
5
  SHA512:
6
- metadata.gz: 752ce4174f0ea3121ba76a2cfe72c49771e0069dc4f940eda114f789ed13a73cc1dbe88558efb4a193765c3b5038003a8af8a2c3979a4b126d515d5b171304c2
7
- data.tar.gz: d9dd3b37ec0884d11b0d08a0ceb228315174b00ffdc6736246bd1da5e9f8271f7fa1d2af91809170d5ebfc2d0f664daba801d0d8b0ac5be4ed7d46b8150859c7
6
+ metadata.gz: bd0f4a6fc15f050e509908df4c3663945e290aac33dc861e371a376ae26705a20c0406ba31d663aee0e8aaeeaa85a6880e94246cfaa6109059fef8c0876667f7
7
+ data.tar.gz: 896c9831d3abfe2459bf44982a50e5ae8b17f4f4b8183fbaf43ef0be790fd06e0dc479876c75a75ca4d475453f09b37a429bc9acd8d3c8474bb5f623a952dd4a
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, row and
4
+ table partials) should not render images or attachments. Flags
5
+ `row.attachment` cells and `image_tag`/`image_pack_tag` helpers as a smell,
6
+ without 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,22 @@ 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`. `_table`
18
+ # partials are included because they render index-style tables of child
19
+ # records within a parent view.
20
+ Koi/TableAsset:
21
+ Description: "Index tables should not render images or attachments."
22
+ Enabled: true
23
+ Safe: true
24
+ SafeAutoCorrect: false
25
+ VersionAdded: "3.3"
26
+ Include:
27
+ - "**/app/views/admin/**/index.html.erb"
28
+ - "**/app/views/admin/**/archived.html.erb"
29
+ - "**/app/views/admin/**/*.html+row.erb"
30
+ - "**/app/views/admin/**/_table*.erb"
31
+
16
32
  # Targets admin views, which are only linted when RuboCop runs through
17
33
  # erb_lint, so it takes effect via `rake erb_lint`.
18
34
  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.0
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