a11y-lint 0.5.0 → 0.6.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: 7cb772a75e7dc2bc7f36f7869efac31d0f9281a196ef237f57e2e2db4f3116c1
4
- data.tar.gz: ddb88dd42e274631a6d289ab56b2c0353e305b37816b9232bd7689578d19ed87
3
+ metadata.gz: '041558922708cbcbc98072a22a57ee9c01292eabefc08d7c8ad2e289b89f159c'
4
+ data.tar.gz: b6de899716228d66c4a56a33e26e6dc2e55aa216e6a261ae82cef3f7c010b5a0
5
5
  SHA512:
6
- metadata.gz: 98b46acd6a78f33f546b6c2aa88e6ff40f7ffe89aaf196d3df0b355a7e2cd2a96d0fdc74c89796764953d47e40b3e89a26dc0008ae55528c3585f48a4d31493d
7
- data.tar.gz: 2571c7dbaef8b3c37cea2a6426b29586c1ad5d3e5d120504ff20c3d4b70cabe8578cbcd50d2f8c677056aabee4520f264eae642be07e610290a4303317031c41
6
+ metadata.gz: d7792835cc5123bc0832ca308ab88e28e51662f6ea1fc597458a5fcd96145e7135d9ad01c486f6efe6436b8f7453f44c8ef4f086bf76d6de7b8fdba271c122d4
7
+ data.tar.gz: 2d22327769cc721c03056845c6f13e46ef35a62b265b67114d5dc85eb6f8c656b1bcc3cf3d5d4e7a52fcde4fb7a2de25972ce822006fda0d78f558ade625aa68
@@ -34,3 +34,19 @@ globs: test/**/*.rb
34
34
  assert_equal("ImgMissingAlt", offense.rule)
35
35
  end
36
36
  ```
37
+
38
+ - Rules that inspect `ruby_code` (e.g. `link_to`, `image_tag` helpers) must include test cases for all three calling styles:
39
+ 1. Single-line with parentheses: `= link_to("", "/path", class: "icon")`
40
+ 2. Single-line without parentheses: `= link_to "", "/path", class: "icon"`
41
+ 3. Multiline with trailing comma:
42
+ ```slim
43
+ = link_to(\
44
+ "",
45
+ "/path",
46
+ class: "icon",
47
+ )
48
+ ```
49
+
50
+ Each style must be tested for both the offense case and the "passes with fix" case.
51
+
52
+ - Every rule must be tested against both the Slim and ERB pipelines.
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.6.0] - 2026-03-31
11
+
12
+ ### Added
13
+
14
+ - `LinkMissingAccessibleName` rule: detect block-style `link_to` calls missing an `aria-label`
15
+
16
+ ## [0.5.1] - 2026-03-31
17
+
18
+ ### Fixed
19
+
20
+ - `LinkMissingAccessibleName` rule: detect multiline method calls with trailing commas
21
+
10
22
  ## [0.5.0] - 2026-03-31
11
23
 
12
24
  ### Added
@@ -6,29 +6,31 @@ module A11y
6
6
  module Lint
7
7
  module Rules
8
8
  # Checks that link_to / external_link_to calls with empty text
9
- # include an aria-label (WCAG 4.1.2).
9
+ # or block content include an aria-label (WCAG 4.1.2).
10
10
  class LinkMissingAccessibleName < Rule
11
11
  LINK_METHODS = %w[link_to external_link_to].freeze
12
12
 
13
13
  def check(node)
14
- return unless link_with_empty_text_and_no_accessible_name?(node)
14
+ code = node.ruby_code
15
+ return unless code
16
+
17
+ clean_code = code.sub(/\s+do\s*\z/, "")
18
+ is_block = clean_code != code
19
+ call = parse_link_call(clean_code)
20
+ return unless call
21
+ return if aria_label_within?(call)
22
+ return unless first_arg_empty_string?(call) || is_block
15
23
 
16
- "link with empty text content requires an aria-label (WCAG 4.1.2)"
24
+ "link missing an accessible name requires an aria-label (WCAG 4.1.2)"
17
25
  end
18
26
 
19
27
  private
20
28
 
21
- def link_with_empty_text_and_no_accessible_name?(node)
22
- code = node.ruby_code
23
- return false unless code
24
-
29
+ def parse_link_call(code)
25
30
  sexp = Ripper.sexp(code)
26
- return false unless sexp
27
-
28
- call = extract_link_call(sexp)
29
- return false unless call
31
+ return unless sexp
30
32
 
31
- first_arg_empty_string?(call) && !aria_label_within?(call)
33
+ extract_link_call(sexp)
32
34
  end
33
35
 
34
36
  def extract_link_call(sexp)
@@ -62,6 +64,7 @@ module A11y
62
64
  case call
63
65
  in [:command, _, [:args_add_block, args, *]] then args
64
66
  in [:method_add_arg, _, [:arg_paren, [:args_add_block, args, *]]] then args
67
+ in [:method_add_arg, _, [:arg_paren, Array => args]] then args
65
68
  else nil
66
69
  end
67
70
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module A11y
4
4
  module Lint
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a11y-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdullah Hashim