From f2295806810e15fecc3f98b3c4d02d78740e902f Mon Sep 17 00:00:00 2001 From: Abdullah Hashim Date: Thu, 24 Sep 2026 09:07:53 -0400 Subject: [PATCH] Drop Slim support --- .claude/commands/implement.md | 6 +- .claude/commands/task.md | 2 +- .claude/rules/testing.md | 22 +- CHANGELOG.md | 4 + CLAUDE.md | 7 +- Gemfile.lock | 6 - README.md | 9 +- a11y-lint.gemspec | 2 - docs/CONTRIBUTING.md | 9 +- docs/src/_components/shared/code_tabs.rb | 5 +- .../form-controls-need-accessible-names.md | 6 - docs/src/rules/images-need-alt-text.md | 58 +-- lib/a11y/lint.rb | 2 - lib/a11y/lint/cli.rb | 12 +- lib/a11y/lint/errors.rb | 10 - lib/a11y/lint/ruby_code.rb | 2 +- lib/a11y/lint/slim_node.rb | 228 ---------- lib/a11y/lint/slim_runner.rb | 78 ---- .../perceivable/test_area_missing_alt.rb | 92 ---- .../test_image_submit_tag_missing_alt.rb | 136 ------ .../perceivable/test_image_tag_missing_alt.rb | 131 ------ .../rules/perceivable/test_img_missing_alt.rb | 86 ---- .../test_input_image_missing_alt.rb | 97 ----- .../test_input_missing_autocomplete.rb | 179 -------- .../test_list_invalid_children_slim.rb | 169 -------- ...est_anchor_missing_accessible_name_slim.rb | 181 -------- ...est_button_missing_accessible_name_slim.rb | 181 -------- ...button_tag_missing_accessible_name_slim.rb | 330 -------------- ...st_link_to_missing_accessible_name_slim.rb | 404 ------------------ ...form_input_missing_accessible_name_slim.rb | 243 ----------- test/a11y/lint/test_cli.rb | 30 +- test/a11y/lint/test_cli_configuration.rb | 8 +- test/a11y/lint/test_cli_erb.rb | 10 +- test/a11y/lint/test_offense.rb | 2 +- test/a11y/lint/test_slim_node.rb | 274 ------------ test/a11y/lint/test_slim_runner.rb | 180 -------- .../dummy_app/app/views/home.html.slim | 133 ------ 37 files changed, 72 insertions(+), 3262 deletions(-) delete mode 100644 lib/a11y/lint/slim_node.rb delete mode 100644 lib/a11y/lint/slim_runner.rb delete mode 100644 test/a11y/lint/rules/perceivable/test_area_missing_alt.rb delete mode 100644 test/a11y/lint/rules/perceivable/test_image_submit_tag_missing_alt.rb delete mode 100644 test/a11y/lint/rules/perceivable/test_image_tag_missing_alt.rb delete mode 100644 test/a11y/lint/rules/perceivable/test_img_missing_alt.rb delete mode 100644 test/a11y/lint/rules/perceivable/test_input_image_missing_alt.rb delete mode 100644 test/a11y/lint/rules/perceivable/test_input_missing_autocomplete.rb delete mode 100644 test/a11y/lint/rules/perceivable/test_list_invalid_children_slim.rb delete mode 100644 test/a11y/lint/rules/robust/test_anchor_missing_accessible_name_slim.rb delete mode 100644 test/a11y/lint/rules/robust/test_button_missing_accessible_name_slim.rb delete mode 100644 test/a11y/lint/rules/robust/test_button_tag_missing_accessible_name_slim.rb delete mode 100644 test/a11y/lint/rules/robust/test_link_to_missing_accessible_name_slim.rb delete mode 100644 test/a11y/lint/rules/robust/test_simple_form_input_missing_accessible_name_slim.rb delete mode 100644 test/a11y/lint/test_slim_node.rb delete mode 100644 test/a11y/lint/test_slim_runner.rb delete mode 100644 test/fixtures/dummy_app/app/views/home.html.slim diff --git a/.claude/commands/implement.md b/.claude/commands/implement.md index 311afa4..df5890a 100644 --- a/.claude/commands/implement.md +++ b/.claude/commands/implement.md @@ -15,12 +15,12 @@ Plan and implement GitHub issue **#$ARGUMENTS** in this repo, end-to-end, on a f 3. **Plan before coding.** Produce a short plan covering: - Which files you'll touch or create - For new rules: the WCAG principle directory under `lib/a11y/lint/rules/`, the rule class name (see CLAUDE.md "Rule Scoping Convention"), and whether it has an HTML/helper pair - - Tests to add (Slim + ERB + Phlex parity per `.claude/rules/testing.md`) - - Dummy app fixtures to add in `test/fixtures/dummy_app/app/views/home/home.html.{slim,erb}` and any Phlex view + - Tests to add (ERB + Phlex parity per `.claude/rules/testing.md`) + - Dummy app fixtures to add in `test/fixtures/dummy_app/app/views/home/home.html.erb` and any Phlex view - Open questions, if any — ask once, then proceed 4. **Implement the plan.** - - Follow `CLAUDE.md` (rule scoping, node interface, configuration loading) and `.claude/rules/testing.md` (no `setup`, all three calling styles for `ruby_code` rules, Slim/ERB/Phlex parity, inline HEREDOC fixtures). + - Follow `CLAUDE.md` (rule scoping, node interface, configuration loading) and `.claude/rules/testing.md` (no `setup`, all three calling styles for `ruby_code` rules, ERB/Phlex parity, inline HEREDOC fixtures). - For new rules: register the rule, add good/bad examples to dummy app fixtures, and add a docs page under `docs/src/rules/` if the issue is adding a user-visible rule. - Add an entry under `[Unreleased]` in `CHANGELOG.md` for any user-visible change (bug fixes, new rules, behavior changes). Skip for internal refactors and test-only changes. diff --git a/.claude/commands/task.md b/.claude/commands/task.md index 10d7069..5b7b93b 100644 --- a/.claude/commands/task.md +++ b/.claude/commands/task.md @@ -17,7 +17,7 @@ Idea: $ARGUMENTS - **Proposed approach** — only include if the approach is obvious from the idea - **Files likely involved** — only include if you can quickly identify them from the repo (e.g. a new rule idea should point at the right WCAG principle directory under `lib/a11y/lint/rules/`) -2. **Clarify only if necessary** — one round, max. Voice input drops context, but too many questions defeat frictionless capture. Skip clarification when the idea is unambiguous. Typical clarifications: bug vs. feature, which rule/file, which template pipeline (Slim/ERB/Phlex). +2. **Clarify only if necessary** — one round, max. Voice input drops context, but too many questions defeat frictionless capture. Skip clarification when the idea is unambiguous. Typical clarifications: bug vs. feature, which rule/file, which template pipeline (ERB/Phlex). 3. **Create the issue** with `gh issue create --title "..." --body "$(cat <<'EOF' ... EOF)"` against the current repo. Do **not** pass `--repo`. Do **not** add labels. diff --git a/.claude/rules/testing.md b/.claude/rules/testing.md index 0d09cbb..eb509e2 100644 --- a/.claude/rules/testing.md +++ b/.claude/rules/testing.md @@ -10,7 +10,7 @@ globs: test/**/*.rb def setup @offense = Offense.new( rule: "ImgMissingAlt", - filename: "test.slim", + filename: "test.html.erb", line: 1, message: "missing alt" ) @@ -26,7 +26,7 @@ globs: test/**/*.rb def test_rule offense = Offense.new( rule: "ImgMissingAlt", - filename: "test.slim", + filename: "test.html.erb", line: 1, message: "missing alt" ) @@ -36,17 +36,17 @@ globs: test/**/*.rb ``` - Rules that inspect `ruby_code` (e.g. `link_to`, `image_tag` helpers) must include test cases for all three calling styles: - 1. Single-line with parentheses: `= link_to("", "/path", class: "icon")` - 2. Single-line without parentheses: `= link_to "", "/path", class: "icon"` + 1. Single-line with parentheses: `<%= link_to("", "/path", class: "icon") %>` + 2. Single-line without parentheses: `<%= link_to "", "/path", class: "icon" %>` 3. Multiline with trailing comma: - ```slim - = link_to(\ - "", - "/path", - class: "icon", - ) + ```erb + <%= link_to( + "", + "/path", + class: "icon", + ) %> ``` Each style must be tested for both the offense case and the "passes with fix" case. -- Every rule must be tested against the Slim, ERB, and Phlex pipelines. +- Every rule must be tested against the ERB and Phlex pipelines. diff --git a/CHANGELOG.md b/CHANGELOG.md index 07f2236..a2b886f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Removed + +- **Breaking:** Slim support has been dropped. `.slim` files are no longer discovered or linted, and `SlimRunner`, `SlimNode`, and `SlimLoadError` have been removed along with the `slim` development dependency. a11y-lint now targets ERB and Phlex only + ## [0.15.0] - 2026-05-06 ### Changed diff --git a/CLAUDE.md b/CLAUDE.md index 6e4a337..13f00d4 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -19,18 +19,17 @@ a11y-lint is a Ruby gem (v0.1.0) for accessibility linting. It uses the `A11y::L ## Architecture -- **CLI:** `lib/a11y/lint/cli.rb` — command-line interface; executable at `exe/a11y-lint`; routes `.slim` files to `SlimRunner`, `.erb` files to `ErbRunner`, and `.rb` files to `PhlexRunner` +- **CLI:** `lib/a11y/lint/cli.rb` — command-line interface; executable at `exe/a11y-lint`; routes `.erb` files to `ErbRunner` and `.rb` files to `PhlexRunner` - **Entry point:** `lib/a11y/lint.rb` — defines the `A11y::Lint` module and `A11y::Lint::Error` exception -- **Slim pipeline:** `SlimRunner` parses Slim templates via `Slim::Parser`; `SlimNode` wraps Slim S-expressions - **ERB pipeline:** `ErbRunner` parses ERB templates via Nokogiri; `ErbNode` wraps Nokogiri nodes and extracted `<%= %>` Ruby code - **Phlex pipeline:** `PhlexRunner` parses Phlex view classes via Prism; `PhlexNode` wraps Prism AST call nodes; detects Phlex files by the presence of `def view_template` -- **Ruby code parsing:** `RubyCode` (`lib/a11y/lint/ruby_code.rb`) — parses a Ruby code string once with Prism and exposes the resulting `CallNode`; used by `SlimNode` and `ErbNode` so rules work against a parsed AST instead of re-parsing strings +- **Ruby code parsing:** `RubyCode` (`lib/a11y/lint/ruby_code.rb`) — parses a Ruby code string once with Prism and exposes the resulting `CallNode`; used by `ErbNode` so rules work against a parsed AST instead of re-parsing strings - **Configuration:** `lib/a11y/lint/configuration.rb` — loads `.a11y-lint.yml` to enable/disable individual rules; searches upward from the target path - **Rules:** `lib/a11y/lint/rules/` — organized by WCAG principle (`perceivable/`, `operable/`, `understandable/`, `robust/`); rules implement `check(node)` against the shared node interface (`tag_name`, `attribute?`, `attributes`, `call_node`, `line`) - **Version:** `lib/a11y/lint/version.rb` - **Type signatures (RBS):** `sig/a11y/lint.rbs` - **Tests:** `test/` directory using Minitest; test helper at `test/test_helper.rb` -- **Dummy app:** `test/fixtures/dummy_app/` — a fixture app with Slim/ERB/Phlex templates for end-to-end smoke testing before releases (`bundle exec a11y-lint test/fixtures/dummy_app`) +- **Dummy app:** `test/fixtures/dummy_app/` — a fixture app with ERB/Phlex templates for end-to-end smoke testing before releases (`bundle exec a11y-lint test/fixtures/dummy_app`) - **Documentation site:** `docs/` — Bridgetown site deployed to https://a11y-lint.guidedrails.com via `.github/workflows/docs.yml` on push to `main`. Has its own `Gemfile`, `package.json`, and Ruby version, and is excluded from the gem's RuboCop config. Rule reference pages live in `docs/src/rules/` (one page per WCAG concept; individual rule classes are anchor sections, e.g. `/rules/images-need-alt-text/#img-missing-alt`). Run locally with `cd docs && bin/bridgetown start`. ## Rule Scoping Convention diff --git a/Gemfile.lock b/Gemfile.lock index d3df05b..01fb916 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -60,12 +60,7 @@ GEM parser (>= 3.3.7.2) prism (~> 1.7) ruby-progressbar (1.13.0) - slim (5.2.1) - temple (~> 0.10.0) - tilt (>= 2.1.0) stringio (3.2.0) - temple (0.10.4) - tilt (2.7.0) tsort (0.2.0) unicode-display_width (3.2.0) unicode-emoji (~> 4.1) @@ -81,7 +76,6 @@ DEPENDENCIES minitest (~> 5.16) rake (~> 13.0) rubocop (~> 1.21) - slim (>= 4.0) BUNDLED WITH 2.6.9 diff --git a/README.md b/README.md index 1e1cf6f..6736c6c 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,10 @@ Run the linter on specific files or directories: ```bash a11y-lint app/views/ -a11y-lint app/views/home.html.slim app/views/about.html.slim +a11y-lint app/views/home.html.erb app/views/about.html.erb ``` -With no arguments, it scans the current directory recursively for `.slim`, `.erb`, and `.rb` (Phlex) files: +With no arguments, it scans the current directory recursively for `.erb` and `.rb` (Phlex) files: ```bash a11y-lint @@ -64,11 +64,6 @@ a11y-lint --config path/to/.a11y-lint.yml app/views/ ```ruby require "a11y/lint" -# Slim -source = File.read("app/views/home.html.slim") -runner = A11y::Lint::SlimRunner.new([A11y::Lint::Rules::ImgMissingAlt]) -offenses = runner.run(source, filename: "app/views/home.html.slim") - # ERB source = File.read("app/views/home.html.erb") runner = A11y::Lint::ErbRunner.new([A11y::Lint::Rules::ImgMissingAlt]) diff --git a/a11y-lint.gemspec b/a11y-lint.gemspec index 85dd512..d613adf 100644 --- a/a11y-lint.gemspec +++ b/a11y-lint.gemspec @@ -35,8 +35,6 @@ Gem::Specification.new do |spec| spec.add_dependency "nokogiri", ">= 1.13" - spec.add_development_dependency "slim", ">= 4.0" - # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html end diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 5a15c9e..92ce3aa 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -6,18 +6,15 @@ Rule pages live in `src/rules/`, one Markdown file per WCAG concept. Each rule c ### Showing example code in multiple template languages -a11y-lint supports ERB, Slim, and Phlex. When a rule page shows example code, render it through the `Shared::CodeTabs` component so all three pipelines collapse into one tabbed block instead of three stacked code blocks. +a11y-lint supports ERB and Phlex. When a rule page shows example code, render it through the `Shared::CodeTabs` component so both pipelines collapse into one tabbed block instead of two stacked code blocks. -ERB is required and is the default tab. Slim and Phlex are optional — omit either kwarg and the tab won't render. +ERB is required and is the default tab. Phlex is optional — omit the kwarg and the tab won't render. ```erb <%= render Shared::CodeTabs.new( erb: <<~ERB, Team celebrating after a product launch ERB - slim: <<~SLIM, - img src="hero.jpg" alt="Team celebrating after a product launch" - SLIM phlex: <<~PHLEX, img(src: "hero.jpg", alt: "Team celebrating after a product launch") PHLEX @@ -26,7 +23,7 @@ ERB is required and is the default tab. Slim and Phlex are optional — omit eit The component takes care of: -- Rouge syntax highlighting per tab (using the `erb`, `slim`, and `ruby` lexers). +- Rouge syntax highlighting per tab (using the `erb` and `ruby` lexers). - WAI-ARIA tab pattern: `role="tablist"` / `role="tab"` / `role="tabpanel"` with full `aria-*` wiring. - Keyboard navigation: Left/Right arrows move between tabs, Home/End jump to the first/last tab, Enter/Space activate, Tab moves into the panel. - A no-JavaScript fallback that shows the ERB panel only. diff --git a/docs/src/_components/shared/code_tabs.rb b/docs/src/_components/shared/code_tabs.rb index b3f3301..1fa480a 100644 --- a/docs/src/_components/shared/code_tabs.rb +++ b/docs/src/_components/shared/code_tabs.rb @@ -4,14 +4,13 @@ class Shared::CodeTabs < Bridgetown::Component TABS = [ { key: :erb, label: "ERB", lexer: "erb" }, - { key: :slim, label: "Slim", lexer: "slim" }, { key: :phlex, label: "Phlex", lexer: "ruby" } ].freeze attr_reader :id - def initialize(erb:, slim: nil, phlex: nil) - @samples = { erb: erb, slim: slim, phlex: phlex } + def initialize(erb:, phlex: nil) + @samples = { erb: erb, phlex: phlex } @id = "code-tabs-#{SecureRandom.hex(4)}" end diff --git a/docs/src/rules/form-controls-need-accessible-names.md b/docs/src/rules/form-controls-need-accessible-names.md index ece2bec..cc1ea21 100644 --- a/docs/src/rules/form-controls-need-accessible-names.md +++ b/docs/src/rules/form-controls-need-accessible-names.md @@ -80,12 +80,6 @@ Or `aria-labelledby` pointing to existing visible text: <%%= form.input :secret, as: :hidden, label: false %> ``` -### Slim equivalent - -```slim -= form.input :name, label: false, input_html: { aria: { label: "Name" } } -``` - ## What this rule doesn't catch This rule has a deliberately narrow scope. Things it doesn't flag: diff --git a/docs/src/rules/images-need-alt-text.md b/docs/src/rules/images-need-alt-text.md index 3158d0e..927f0bd 100644 --- a/docs/src/rules/images-need-alt-text.md +++ b/docs/src/rules/images-need-alt-text.md @@ -71,9 +71,6 @@ Applies to: HTML `` elements. erb: <<~ERB, ERB - slim: <<~SLIM, - img src="hero.jpg" - SLIM phlex: <<~PHLEX, img(src: "hero.jpg") PHLEX @@ -85,9 +82,6 @@ Applies to: HTML `` elements. erb: <<~ERB, Team celebrating after a product launch ERB - slim: <<~SLIM, - img src="hero.jpg" alt="Team celebrating after a product launch" - SLIM phlex: <<~PHLEX, img(src: "hero.jpg", alt: "Team celebrating after a product launch") PHLEX @@ -99,15 +93,7 @@ For a decorative image, use an empty `alt` so assistive tech skips it: ``` -### Slim and Phlex equivalents - -Slim: - -```slim -img src="hero.jpg" alt="Team celebrating after a product launch" -``` - -Phlex: +### Phlex equivalent ```ruby img(src: "hero.jpg", alt: "Team celebrating after a product launch") @@ -136,15 +122,7 @@ For a decorative image: <%%= image_tag("divider.svg", alt: "") %> ``` -### Slim and Phlex equivalents - -Slim: - -```slim -= image_tag("hero.jpg", alt: "Team celebrating after a product launch") -``` - -Phlex: +### Phlex equivalent ```ruby image_tag("hero.jpg", alt: "Team celebrating after a product launch") @@ -169,15 +147,7 @@ Applies to: HTML `` elements. ``` -### Slim and Phlex equivalents - -Slim: - -```slim -input type="image" src="search.svg" alt="Search" -``` - -Phlex: +### Phlex equivalent ```ruby input(type: "image", src: "search.svg", alt: "Search") @@ -202,15 +172,7 @@ Applies to: Rails `image_submit_tag` helper (renders ``). <%%= image_submit_tag("search.svg", alt: "Search") %> ``` -### Slim and Phlex equivalents - -Slim: - -```slim -= image_submit_tag("search.svg", alt: "Search") -``` - -Phlex: +### Phlex equivalent ```ruby image_submit_tag("search.svg", alt: "Search") @@ -243,17 +205,7 @@ Each `` is a clickable hotspot in an image map — effectively a link. Its ``` -### Slim and Phlex equivalents - -Slim: - -```slim -img src="team-photo.jpg" alt="Our team" usemap="#team" -map name="team" - area shape="rect" coords="0,0,100,100" href="/team/alex" alt="Alex's profile" -``` - -Phlex: +### Phlex equivalent ```ruby img(src: "team-photo.jpg", alt: "Our team", usemap: "#team") diff --git a/lib/a11y/lint.rb b/lib/a11y/lint.rb index 95ac2f4..303aeff 100644 --- a/lib/a11y/lint.rb +++ b/lib/a11y/lint.rb @@ -7,7 +7,6 @@ require_relative "lint/call_node" require_relative "lint/ruby_code" require_relative "lint/block_inspection" -require_relative "lint/slim_node" require_relative "lint/erb_element_node" require_relative "lint/erb_output_node" require_relative "lint/phlex_tags" @@ -15,6 +14,5 @@ require_relative "lint/configuration" require_relative "lint/node_rule" Dir[File.join(__dir__, "lint", "rules", "**", "*.rb")].each { |f| require f } -require_relative "lint/slim_runner" require_relative "lint/erb_runner" require_relative "lint/phlex_runner" diff --git a/lib/a11y/lint/cli.rb b/lib/a11y/lint/cli.rb index a39042f..21a11fc 100644 --- a/lib/a11y/lint/cli.rb +++ b/lib/a11y/lint/cli.rb @@ -18,7 +18,7 @@ def run files = resolve_files(@argv) if files.empty? - @stderr.puts("No .slim, .erb, or .rb files found") + @stderr.puts("No .erb or .rb files found") return 0 end @@ -61,7 +61,7 @@ def resolve_files(paths) def expand_path(path) if File.directory?(path) - Dir.glob(File.join(path, "**", "*.{slim,erb,rb}")) + Dir.glob(File.join(path, "**", "*.{erb,rb}")) elsif File.file?(path) [path] else @@ -72,22 +72,20 @@ def expand_path(path) def lint_files(files) configuration = load_configuration - slim_runner = SlimRunner.new(configuration:) erb_runner = ErbRunner.new(configuration:) phlex_runner = PhlexRunner.new(configuration:) files.flat_map do |file| source = File.read(file) - runner = runner_for(file, slim_runner, erb_runner, phlex_runner) + runner = runner_for(file, erb_runner, phlex_runner) runner.run(source, filename: file) end end - def runner_for(file, slim_runner, erb_runner, phlex_runner) + def runner_for(file, erb_runner, phlex_runner) case File.extname(file) - when ".erb" then erb_runner when ".rb" then phlex_runner - else slim_runner + else erb_runner end end diff --git a/lib/a11y/lint/errors.rb b/lib/a11y/lint/errors.rb index eca847f..5813237 100644 --- a/lib/a11y/lint/errors.rb +++ b/lib/a11y/lint/errors.rb @@ -3,15 +3,5 @@ module A11y module Lint class Error < StandardError; end - - # Raised when slim is not installed. - class SlimLoadError < Error - def initialize - super( - "a11y-lint needs the `slim` gem to lint .slim files. " \ - "Add `gem \"slim\"` to your Gemfile." - ) - end - end end end diff --git a/lib/a11y/lint/ruby_code.rb b/lib/a11y/lint/ruby_code.rb index fd3f48a..220fb90 100644 --- a/lib/a11y/lint/ruby_code.rb +++ b/lib/a11y/lint/ruby_code.rb @@ -81,7 +81,7 @@ def prism_parse_result @prism_parse_result ||= Prism.parse(source) end - # Slim/ERB block forms end with ` do` (e.g. `link_to("#") do`) + # ERB block forms end with ` do` (e.g. `link_to("#") do`) # which isn't valid Ruby on its own. Appending `\nend` makes it # parseable and gives the resulting CallNode a `.block` attribute. def source diff --git a/lib/a11y/lint/slim_node.rb b/lib/a11y/lint/slim_node.rb deleted file mode 100644 index 1387932..0000000 --- a/lib/a11y/lint/slim_node.rb +++ /dev/null @@ -1,228 +0,0 @@ -# frozen_string_literal: true - -module A11y - module Lint - # Wraps a Slim AST s-expression as a queryable node for lint rules. - class SlimNode - include BlockInspection - - attr_reader :line, :configuration - - def initialize(sexp, line:, configuration: Configuration.new) - @sexp = sexp - @line = line - @configuration = configuration - end - - def tag_name - @sexp[2] - end - - def ruby_code - return unless slim_output? - - @sexp[3] - end - - def call_node - return unless slim_output? - - @call_node ||= parse_call_node - end - - def attribute?(name) - attributes.key?(name) - end - - def attributes - @attributes ||= extract_attributes - end - - # Returns direct HTML element children as SlimNode objects. - # Walks through [:multi] and [:slim, :control] wrappers so that tags - # nested inside control flow are still treated as direct children. - # Opaque [:slim, :output] blocks are skipped. - def children - return [] unless html_tag? - - body = @sexp[4] - collect_children(body) - end - - # Returns ruby_code strings from child :slim :output nodes - # inside a block body. Only meaningful for output nodes - # (e.g. `= button_tag(...) do`). - def block_body_codes - return unless slim_output? - - collect_output_codes(@sexp[4]) - end - - # Returns true when the block body contains visible text or - # HTML tag children (i.e. content that provides an accessible name). - def block_has_text_children? - return false unless slim_output? - - block_text_content?(@sexp[4]) - end - - # Returns true when the HTML element body contains visible text - # or dynamic output (i.e. content that could provide an accessible - # name). Only meaningful for HTML tag nodes. - def text_content? - return false unless html_tag? - - text_or_output?(@sexp[4]) - end - - private - - def html_tag? - @sexp[0] == :html && @sexp[1] == :tag - end - - def slim_output? - @sexp[0] == :slim && @sexp[1] == :output - end - - def parse_call_node - RubyCode.new(@sexp[3]).call_node - end - - def collect_output_codes(sexp) - return [] unless sexp.is_a?(Array) - return [] if inaccessible_wrapper_sexp?(sexp) - return [sexp[3]] if slim_output_sexp?(sexp) - - sexp.flat_map { |child| collect_output_codes(child) } - end - - def slim_output_sexp?(sexp) - sexp.is_a?(Array) && sexp[0] == :slim && sexp[1] == :output - end - - def block_text_content?(sexp) - return false unless sexp.is_a?(Array) - return false if inaccessible_wrapper_sexp?(sexp) - return true if slim_text_sexp?(sexp) || html_tag_sexp?(sexp) - - sexp.any? { |child| block_text_content?(child) } - end - - def text_or_output?(sexp) - return false unless sexp.is_a?(Array) - return false if inaccessible_wrapper_sexp?(sexp) - return true if slim_text_sexp?(sexp) || slim_output_sexp?(sexp) - - sexp.any? { |child| text_or_output?(child) } - end - - def inaccessible_wrapper_sexp?(sexp) - return false unless html_tag_sexp?(sexp) - return false if configuration.inaccessible_wrapper_classes.empty? - - class_values(sexp[3]).any? do |klass| - configuration.inaccessible_wrapper_classes.include?(klass) - end - end - - def class_values(attrs_sexp) - return [] unless attrs_sexp.is_a?(Array) && - attrs_sexp[0] == :html && attrs_sexp[1] == :attrs - - attrs_sexp[2..].flat_map { |attr| class_values_for_attr(attr) } - end - - def class_values_for_attr(attr) - return [] unless attr.is_a?(Array) && - attr[0] == :html && attr[1] == :attr && - attr[2] == "class" - - value = static_class_string(attr[3]) - value ? value.split : [] - end - - # Extracts a static class string from the two forms Slim emits: - # `[:static, "name"]` for class shortcuts (`.popover`) and - # `[:escape, true, [:slim, :interpolate, "name"]]` for `class="..."`. - def static_class_string(value_sexp) - return unless value_sexp.is_a?(Array) - return static_sexp_value(value_sexp) if value_sexp[0] == :static - - interpolate_sexp_value(value_sexp) - end - - def static_sexp_value(sexp) - sexp[1] if sexp[1].is_a?(String) - end - - def interpolate_sexp_value(sexp) - return unless sexp[0] == :escape && sexp[2].is_a?(Array) - return unless sexp[2][0] == :slim && sexp[2][1] == :interpolate - - sexp[2][2] if sexp[2][2].is_a?(String) - end - - def slim_text_sexp?(sexp) - sexp[0] == :slim && sexp[1] == :text - end - - def collect_children(sexp) - return [] unless sexp.is_a?(Array) - - if html_tag_sexp?(sexp) - return [SlimNode.new(sexp, line: @line, configuration: configuration)] - end - - return collect_children(sexp[3]) if slim_control_sexp?(sexp) - return [] unless sexp[0] == :multi - - sexp[1..].flat_map { |c| collect_children(c) } - end - - def html_tag_sexp?(sexp) - sexp[0] == :html && sexp[1] == :tag - end - - def slim_control_sexp?(sexp) - sexp[0] == :slim && sexp[1] == :control - end - - def extract_attributes - return {} unless html_attributes? - - sexp_attributes[2..].each_with_object({}) do |attr_sexp, result| - next unless html_attribute?(attr_sexp) - - result[attr_sexp[2]] = static_value(attr_sexp[3]) - end - end - - def static_value(value_sexp) - if value_sexp.is_a?(Array) && value_sexp[0] == :escape && - value_sexp[2].is_a?(Array) && - value_sexp[2][0] == :slim && value_sexp[2][1] == :interpolate - value_sexp[2][2] - else - true - end - end - - def sexp_attributes - @sexp[3] - end - - def html_attributes? - sexp_attributes.is_a?(Array) && - sexp_attributes[0] == :html && - sexp_attributes[1] == :attrs - end - - def html_attribute?(attributes) - attributes.is_a?(Array) && - attributes[0] == :html && - attributes[1] == :attr - end - end - end -end diff --git a/lib/a11y/lint/slim_runner.rb b/lib/a11y/lint/slim_runner.rb deleted file mode 100644 index a387f02..0000000 --- a/lib/a11y/lint/slim_runner.rb +++ /dev/null @@ -1,78 +0,0 @@ -# frozen_string_literal: true - -module A11y - module Lint - # Parses Slim templates and checks them against accessibility rules. - class SlimRunner - def initialize(rules = nil, configuration: Configuration.new) - @rules = rules || configuration.enabled_rules - @configuration = configuration - end - - def run(source, filename:) - require "slim" - sexp = Slim::Parser.new.call(source) - @line = 1 - @filename = filename - @offenses = [] - walk(sexp) - @offenses - rescue LoadError - raise SlimLoadError - end - - private - - attr_reader(:rules, :configuration) - - def walk(sexp) - return unless node?(sexp) - - @line += 1 if sexp[0] == :newline - new_node = SlimNode.new(sexp, line: @line, configuration:) - check_node(new_node) if html_tag?(sexp) || slim_output?(sexp) - @line += continuation_newlines(sexp) - sexp.each { |child| walk(child) } - end - - def html_tag?(sexp) - sexp[0] == :html && sexp[1] == :tag - end - - def slim_output?(sexp) - sexp[0] == :slim && sexp[1] == :output - end - - # Counts extra source lines consumed by backslash-continued - # multiline expressions in :output and :control nodes. - # Slim collapses these into one AST node whose ruby_code - # string retains the original newlines. - def continuation_newlines(sexp) - code = case sexp - in [:slim, :output, _, String => c, *] then c - in [:slim, :control, String => c, *] then c - else return 0 - end - code.count("\n") - end - - def node?(sexp) - sexp.is_a?(Array) && !sexp.empty? && sexp[0].is_a?(Symbol) - end - - def check_node(node) - rules.each do |rule_class| - message = rule_class.check(node) - next unless message - - @offenses << Offense.new( - rule: rule_class.rule_name, - filename: @filename, - line: node.line, - message: message - ) - end - end - end - end -end diff --git a/test/a11y/lint/rules/perceivable/test_area_missing_alt.rb b/test/a11y/lint/rules/perceivable/test_area_missing_alt.rb deleted file mode 100644 index 4209063..0000000 --- a/test/a11y/lint/rules/perceivable/test_area_missing_alt.rb +++ /dev/null @@ -1,92 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -module A11y - module Lint - module Rules - class TestAreaMissingAlt < Minitest::Test - def test_area_without_alt_reports_offense - source = 'area shape="rect" coords="0,0,82,126" href="/sun"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal( - "area tag is missing an alt attribute (WCAG 1.1.1)", - offenses[0].message - ) - assert_equal(1, offenses[0].line) - assert_equal("AreaMissingAlt", offenses[0].rule) - end - - def test_area_with_alt_passes - source = 'area shape="rect" coords="0,0,82,126" href="/sun" alt="Sun"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_area_with_empty_alt_passes - source = 'area shape="rect" coords="0,0,82,126" href="/sun" alt=""' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_nested_area_without_alt - source = "map\n area shape=\"rect\" href=\"/sun\"" - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_multiple_areas_reports_only_missing - source = <<~SLIM.chomp - area shape="rect" href="/sun" alt="Sun" - area shape="circle" href="/moon" - area shape="poly" href="/star" alt="Star" - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_deeply_nested_area - source = <<~SLIM.chomp - section - div - map - area shape="rect" href="/sun" - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(4, offenses[0].line) - end - - def test_sets_filename_on_offense - filename = "app/views/index.html.slim" - source = 'area shape="rect" href="/sun"' - - offenses = run_linter(source, filename:) - - assert_equal(filename, offenses[0].filename) - end - - private - - def run_linter(source, filename: "test.slim") - SlimRunner.new([AreaMissingAlt]).run(source, filename: filename) - end - end - end - end -end diff --git a/test/a11y/lint/rules/perceivable/test_image_submit_tag_missing_alt.rb b/test/a11y/lint/rules/perceivable/test_image_submit_tag_missing_alt.rb deleted file mode 100644 index fca2cb7..0000000 --- a/test/a11y/lint/rules/perceivable/test_image_submit_tag_missing_alt.rb +++ /dev/null @@ -1,136 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -module A11y - module Lint - module Rules - class TestImageSubmitTagMissingAlt < Minitest::Test - def test_image_submit_tag_without_alt_reports_offense - source = '= image_submit_tag "submit.png"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal( - "image_submit_tag is missing an alt option (WCAG 1.1.1)", - offenses[0].message - ) - assert_equal(1, offenses[0].line) - assert_equal("ImageSubmitTagMissingAlt", offenses[0].rule) - end - - def test_image_submit_tag_with_alt_symbol_key_passes - source = '= image_submit_tag "submit.png", alt: "Submit"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_submit_tag_with_empty_alt_passes - source = '= image_submit_tag "submit.png", alt: ""' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_submit_tag_with_parentheses_without_alt_reports_offense - source = '= image_submit_tag("submit.png")' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_image_submit_tag_with_parentheses_and_alt_passes - source = '= image_submit_tag("submit.png", alt: "Submit")' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_multiline_image_submit_tag_without_alt_reports_offense - source = <<~SLIM.chomp - = image_submit_tag(\\ - "submit.png", - class: "btn", - ) - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_multiline_image_submit_tag_with_alt_passes - source = <<~SLIM.chomp - = image_submit_tag(\\ - "submit.png", - alt: "Submit", - class: "btn", - ) - SLIM - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_submit_tag_with_other_options_but_no_alt_reports_offense - source = '= image_submit_tag "submit.png", class: "btn"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_image_submit_tag_with_alt_among_other_options_passes - source = <<~SLIM.chomp - = image_submit_tag "submit.png", class: "btn", alt: "Submit" - SLIM - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_submit_tag_with_hash_rocket_alt_passes - source = '= image_submit_tag "submit.png", "alt" => "Submit"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_nested_image_submit_tag_without_alt - source = "div\n = image_submit_tag \"submit.png\"" - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_sets_filename_on_offense - filename = "app/views/index.html.slim" - source = '= image_submit_tag "submit.png"' - - offenses = run_linter(source, filename:) - - assert_equal(filename, offenses[0].filename) - end - - private - - def run_linter(source, filename: "test.slim") - SlimRunner - .new([ImageSubmitTagMissingAlt]) - .run(source, filename: filename) - end - end - end - end -end diff --git a/test/a11y/lint/rules/perceivable/test_image_tag_missing_alt.rb b/test/a11y/lint/rules/perceivable/test_image_tag_missing_alt.rb deleted file mode 100644 index f7f9710..0000000 --- a/test/a11y/lint/rules/perceivable/test_image_tag_missing_alt.rb +++ /dev/null @@ -1,131 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -module A11y - module Lint - module Rules - class TestImageTagMissingAlt < Minitest::Test - def test_image_tag_without_alt_reports_offense - source = '= image_tag "photo.jpg"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal( - "image_tag is missing an alt option (WCAG 1.1.1)", - offenses[0].message - ) - assert_equal(1, offenses[0].line) - assert_equal("ImageTagMissingAlt", offenses[0].rule) - end - - def test_image_tag_with_alt_symbol_key_passes - source = '= image_tag "photo.jpg", alt: "A photo"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_tag_with_empty_alt_passes - source = '= image_tag "photo.jpg", alt: ""' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_tag_with_parentheses_without_alt_reports_offense - source = '= image_tag("photo.jpg")' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_image_tag_with_parentheses_and_alt_passes - source = '= image_tag("photo.jpg", alt: "A photo")' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_tag_with_other_options_but_no_alt_reports_offense - source = '= image_tag "photo.jpg", class: "hero"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_image_tag_with_alt_among_other_options_passes - source = '= image_tag "photo.jpg", class: "hero", alt: "A photo"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_image_tag_with_hash_rocket_alt_passes - source = '= image_tag "photo.jpg", "alt" => "A photo"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_nested_image_tag_without_alt - source = "div\n = image_tag \"photo.jpg\"" - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_image_tag_nested_in_link_to_without_alt_reports_offense - source = '= link_to(image_tag("logo.svg"), root_path)' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_image_tag_nested_in_link_to_with_alt_passes - source = '= link_to(image_tag("logo.svg", alt: "Logo"), root_path)' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_alt_in_filename_still_reports_offense - source = '= image_tag "icons/alt:native.png"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_sets_filename_on_offense - filename = "app/views/index.html.slim" - source = '= image_tag "photo.jpg"' - - offenses = run_linter(source, filename:) - - assert_equal(filename, offenses[0].filename) - end - - private - - def run_linter(source, filename: "test.slim") - SlimRunner - .new([ImageTagMissingAlt]) - .run(source, filename: filename) - end - end - end - end -end diff --git a/test/a11y/lint/rules/perceivable/test_img_missing_alt.rb b/test/a11y/lint/rules/perceivable/test_img_missing_alt.rb deleted file mode 100644 index eb79819..0000000 --- a/test/a11y/lint/rules/perceivable/test_img_missing_alt.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -module A11y - module Lint - module Rules - class TestImgMissingAlt < Minitest::Test - def test_img_without_alt_reports_offense - source = 'img src="photo.jpg"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal( - "img tag is missing an alt attribute (WCAG 1.1.1)", - offenses[0].message - ) - assert_equal(1, offenses[0].line) - assert_equal("ImgMissingAlt", offenses[0].rule) - end - - def test_img_with_alt_passes - source = 'img src="photo.jpg" alt="A photo"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_img_with_empty_alt_passes - source = 'img src="decorative.jpg" alt=""' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_nested_img_without_alt - source = "div\n img src=\"photo.jpg\"" - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_multiple_images_reports_only_missing - source = <<~SLIM.chomp - img src="a.jpg" alt="A" - img src="b.jpg" - img src="c.jpg" alt="C" - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_deeply_nested_img - source = "section\n div\n article\n img src=\"deep.jpg\"" - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(4, offenses[0].line) - end - - def test_sets_filename_on_offense - filename = "app/views/index.html.slim" - source = 'img src="photo.jpg"' - - offenses = run_linter(source, filename:) - - assert_equal(filename, offenses[0].filename) - end - - private - - def run_linter(source, filename: "test.slim") - SlimRunner.new([ImgMissingAlt]).run(source, filename: filename) - end - end - end - end -end diff --git a/test/a11y/lint/rules/perceivable/test_input_image_missing_alt.rb b/test/a11y/lint/rules/perceivable/test_input_image_missing_alt.rb deleted file mode 100644 index ed947a6..0000000 --- a/test/a11y/lint/rules/perceivable/test_input_image_missing_alt.rb +++ /dev/null @@ -1,97 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -module A11y - module Lint - module Rules - class TestInputImageMissingAlt < Minitest::Test - def test_input_image_without_alt_reports_offense - source = 'input type="image" src="submit.png"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal( - "input type=\"image\" is missing an alt attribute (WCAG 1.1.1)", - offenses[0].message - ) - assert_equal(1, offenses[0].line) - assert_equal("InputImageMissingAlt", offenses[0].rule) - end - - def test_input_image_with_alt_passes - source = 'input type="image" src="submit.png" alt="Submit"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_image_with_empty_alt_passes - source = 'input type="image" src="submit.png" alt=""' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_text_without_alt_passes - source = 'input type="text" name="username"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_submit_without_alt_passes - source = 'input type="submit" value="Go"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_nested_input_image_without_alt - source = <<~SLIM.chomp - form - input type="image" src="submit.png" - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_multiple_inputs_reports_only_image_missing_alt - source = <<~SLIM.chomp - input type="text" name="q" - input type="image" src="go.png" - input type="image" src="search.png" alt="Search" - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_sets_filename_on_offense - filename = "app/views/index.html.slim" - source = 'input type="image" src="submit.png"' - - offenses = run_linter(source, filename:) - - assert_equal(filename, offenses[0].filename) - end - - private - - def run_linter(source, filename: "test.slim") - SlimRunner.new([InputImageMissingAlt]).run(source, filename: filename) - end - end - end - end -end diff --git a/test/a11y/lint/rules/perceivable/test_input_missing_autocomplete.rb b/test/a11y/lint/rules/perceivable/test_input_missing_autocomplete.rb deleted file mode 100644 index cb2f935..0000000 --- a/test/a11y/lint/rules/perceivable/test_input_missing_autocomplete.rb +++ /dev/null @@ -1,179 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -module A11y - module Lint - module Rules - class TestInputMissingAutocomplete < Minitest::Test - def test_input_without_autocomplete_reports_offense - source = 'input type="text" name="username"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal( - "input is missing an autocomplete attribute (WCAG 1.3.5)", - offenses[0].message - ) - assert_equal(1, offenses[0].line) - assert_equal("InputMissingAutocomplete", offenses[0].rule) - end - - def test_input_with_autocomplete_passes - source = 'input type="text" name="username" autocomplete="username"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_with_autocomplete_on_passes - source = 'input type="text" name="query" autocomplete="on"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_with_autocomplete_off_passes - source = 'input type="text" name="otp" autocomplete="off"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_without_type_reports_offense - source = 'input name="search"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_input_hidden_without_autocomplete_passes - source = 'input type="hidden" name="token"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_submit_without_autocomplete_passes - source = 'input type="submit" value="Go"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_button_without_autocomplete_passes - source = 'input type="button" value="Click"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_reset_without_autocomplete_passes - source = 'input type="reset" value="Reset"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_image_without_autocomplete_passes - source = 'input type="image" src="submit.png" alt="Submit"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_checkbox_without_autocomplete_passes - source = 'input type="checkbox" name="agree"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_radio_without_autocomplete_passes - source = 'input type="radio" name="color" value="red"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_file_without_autocomplete_passes - source = 'input type="file" name="avatar"' - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_input_email_without_autocomplete_reports_offense - source = 'input type="email" name="email"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_input_tel_without_autocomplete_reports_offense - source = 'input type="tel" name="phone"' - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - end - - def test_nested_input_without_autocomplete - source = <<~SLIM.chomp - form - input type="email" name="email" - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_multiple_inputs_reports_only_missing_autocomplete - source = <<~SLIM.chomp - input type="text" name="name" autocomplete="name" - input type="email" name="email" - input type="submit" value="Send" - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal(2, offenses[0].line) - end - - def test_sets_filename_on_offense - filename = "app/views/index.html.slim" - source = 'input type="text" name="username"' - - offenses = run_linter(source, filename:) - - assert_equal(filename, offenses[0].filename) - end - - private - - def run_linter(source, filename: "test.slim") - SlimRunner - .new([InputMissingAutocomplete]) - .run(source, filename: filename) - end - end - end - end -end diff --git a/test/a11y/lint/rules/perceivable/test_list_invalid_children_slim.rb b/test/a11y/lint/rules/perceivable/test_list_invalid_children_slim.rb deleted file mode 100644 index a43516d..0000000 --- a/test/a11y/lint/rules/perceivable/test_list_invalid_children_slim.rb +++ /dev/null @@ -1,169 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -module A11y - module Lint - module Rules - class TestListInvalidChildrenSlim < Minitest::Test - def test_ul_with_only_li_passes - source = <<~SLIM.chomp - ul - li one - li two - SLIM - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_ol_with_only_li_passes - source = <<~SLIM.chomp - ol - li one - li two - SLIM - - offenses = run_linter(source) - - assert_empty(offenses) - end - - def test_ul_with_div_child_reports_offense - source = <<~SLIM.chomp - ul - div bad - li ok - SLIM - - offenses = run_linter(source) - - assert_equal(1, offenses.length) - assert_equal( - "