From f0de67f45cf73a7c674c6fc45707362ec4cd549c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Mon, 14 Mar 2022 19:50:53 +0000 Subject: [PATCH 01/15] Add test to make sure `
` elements have a `` element --- .../accessibility/details_has_summary.rb | 39 +++++++++++++++++++ .../accessibility/details_has_summary_test.rb | 23 +++++++++++ 2 files changed, 62 insertions(+) create mode 100644 lib/erblint-github/linters/github/accessibility/details_has_summary.rb create mode 100644 test/linters/accessibility/details_has_summary_test.rb diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb new file mode 100644 index 0000000..9e1bcba --- /dev/null +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require_relative "../../custom_helpers" + +module ERBLint + module Linters + module GitHub + module Accessibility + class DetailsHasSummary < Linter + include ERBLint::Linters::CustomHelpers + include LinterRegistry + + MESSAGE = "
elements need to have explict elements" + + def run(processed_source) + tags(processed_source).each do |tag| + next if tag.closing? + next unless tag.name == "details" + + # Find the details element index in the AST + index = processed_source.ast.to_a.find_index(tag.node) + + # Get the next element in the AST + next_node = processed_source.ast.to_a[index + 1] + next_tag = BetterHtml::Tree::Tag.from_node(next_node) + + # If the next element is a summary, we're good + next if next_tag.name == "summary" + + generate_offense(self.class, processed_source, tag) + end + + rule_disabled?(processed_source) + end + end + end + end + end +end diff --git a/test/linters/accessibility/details_has_summary_test.rb b/test/linters/accessibility/details_has_summary_test.rb new file mode 100644 index 0000000..b7c0b1d --- /dev/null +++ b/test/linters/accessibility/details_has_summary_test.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require "test_helper" + +class DetailsHasSummary < LinterTestCase + def linter_class + ERBLint::Linters::GitHub::Accessibility::DetailsHasSummary + end + + def test_warns_if_details_doesnt_have_a_summary + @file = "
I don't have a summary element
" + @linter.run(processed_source) + + assert_equal @linter.offenses.count, 1 + end + + def test_does_not_warn_if_only_disabled_attribute_is_set + @file = "
Expand me!
" + @linter.run(processed_source) + + assert_empty @linter.offenses + end +end From a10071a7d4706c9d08c9b068f5c2318c59b4a023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 12:52:57 +0000 Subject: [PATCH 02/15] Use `each_with_index` to get the index of tag --- .../linters/github/accessibility/details_has_summary.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb index 9e1bcba..4badb5b 100644 --- a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -13,13 +13,10 @@ class DetailsHasSummary < Linter MESSAGE = "
elements need to have explict elements" def run(processed_source) - tags(processed_source).each do |tag| + tags(processed_source).each_with_index do |tag, index| next if tag.closing? next unless tag.name == "details" - # Find the details element index in the AST - index = processed_source.ast.to_a.find_index(tag.node) - # Get the next element in the AST next_node = processed_source.ast.to_a[index + 1] next_tag = BetterHtml::Tree::Tag.from_node(next_node) From de0c0880329132b71bd02d7af8995066baf320b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 13:08:22 +0000 Subject: [PATCH 03/15] Simplify iterating through children --- .../accessibility/details_has_summary.rb | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb index 4badb5b..94862ae 100644 --- a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -13,18 +13,22 @@ class DetailsHasSummary < Linter MESSAGE = "
elements need to have explict elements" def run(processed_source) - tags(processed_source).each_with_index do |tag, index| - next if tag.closing? - next unless tag.name == "details" - - # Get the next element in the AST - next_node = processed_source.ast.to_a[index + 1] - next_tag = BetterHtml::Tree::Tag.from_node(next_node) + current_details = nil + has_summary = false - # If the next element is a summary, we're good - next if next_tag.name == "summary" - - generate_offense(self.class, processed_source, tag) + tags(processed_source).each_with_index do |tag, index| + if tag.name == "summary" && !tag.closing? + has_summary = true + end + + next if tag.name != "details" + + if tag.closing? && !has_summary + generate_offense(self.class, processed_source, current_details) + current_details = nil + else + current_details = tag + end end rule_disabled?(processed_source) From 43bd2dabe0685cb76a910b702d5bc6ae8059440f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 13:09:38 +0000 Subject: [PATCH 04/15] Update test name --- test/linters/accessibility/details_has_summary_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/linters/accessibility/details_has_summary_test.rb b/test/linters/accessibility/details_has_summary_test.rb index b7c0b1d..c3324f6 100644 --- a/test/linters/accessibility/details_has_summary_test.rb +++ b/test/linters/accessibility/details_has_summary_test.rb @@ -14,7 +14,7 @@ def test_warns_if_details_doesnt_have_a_summary assert_equal @linter.offenses.count, 1 end - def test_does_not_warn_if_only_disabled_attribute_is_set + def test_does_not_warn_if_details_has_a_summary @file = "
Expand me!
" @linter.run(processed_source) From 963ed23bf7c04088855ac8498742fd885726c82c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 13:09:53 +0000 Subject: [PATCH 05/15] Add a test for when the `` is in a weird place --- test/linters/accessibility/details_has_summary_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/linters/accessibility/details_has_summary_test.rb b/test/linters/accessibility/details_has_summary_test.rb index c3324f6..b2278bf 100644 --- a/test/linters/accessibility/details_has_summary_test.rb +++ b/test/linters/accessibility/details_has_summary_test.rb @@ -14,6 +14,13 @@ def test_warns_if_details_doesnt_have_a_summary assert_equal @linter.offenses.count, 1 end + def test_does_not_warn_if_details_has_a_summary_in_a_weird_place + @file = "

Surprise text!

Expand me!
" + @linter.run(processed_source) + + assert_empty @linter.offenses + end + def test_does_not_warn_if_details_has_a_summary @file = "
Expand me!
" @linter.run(processed_source) From 8d42625489b7a71ca116d611cc98ef40d689be0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 13:16:07 +0000 Subject: [PATCH 06/15] Add docs on the `DetailsHasSummary` rule --- README.md | 1 + .../accessibility/details-has-summary.md | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 docs/rules/accessibility/details-has-summary.md diff --git a/README.md b/README.md index 3a2cf2b..811b9f1 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ linters: - [GitHub::Accessibility::NoPositiveTabIndex](./docs/rules/accessibility/no-positive-tab-index.md) - [GitHub::Accessibility::NoRedundantImageAlt](./docs/rules/accessibility/no-redundant-image-alt.md) - [GitHub::Accessibility::NoTitleAttributeCounter](./docs/rules/accessibility/no-title-attribute-counter.md) +- [GitHub::Accessibility::DetailsHasSummary](./docs/rules/accessibility/details-has-summary.md) ## Testing diff --git a/docs/rules/accessibility/details-has-summary.md b/docs/rules/accessibility/details-has-summary.md new file mode 100644 index 0000000..d241486 --- /dev/null +++ b/docs/rules/accessibility/details-has-summary.md @@ -0,0 +1,28 @@ +# Details has summary + +## Rule Details +`
` should have a `` element hinting to the user what they'll be expanding by interfacing with the element. This is useful to screen reader users to navigate the website as well as a good UI pattern since omitting a `` element lets the user agent inject their own `` element that adds no context to the control. + +### 👎 Examples of **incorrect** code for this rule: + +```erb +
+ I don't have a summary tag! +
+``` + +### 👍 Examples of **correct** code for this rule: + +```erb +
+ Expand me! + I do have a summary tag! +
+```` + +```erb +
+ I do have a summary tag! + Expand me! +
+```` From 8abd5035b11b42d8ee49e161d44eaed8ba60e6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 13:20:14 +0000 Subject: [PATCH 07/15] Update rule description a bit --- docs/rules/accessibility/details-has-summary.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/accessibility/details-has-summary.md b/docs/rules/accessibility/details-has-summary.md index d241486..b2640a2 100644 --- a/docs/rules/accessibility/details-has-summary.md +++ b/docs/rules/accessibility/details-has-summary.md @@ -1,7 +1,7 @@ # Details has summary ## Rule Details -`
` should have a `` element hinting to the user what they'll be expanding by interfacing with the element. This is useful to screen reader users to navigate the website as well as a good UI pattern since omitting a `` element lets the user agent inject their own `` element that adds no context to the control. +`
` should have a `` element hinting to the user what they'll be expanding by interfacing with the element. `` elements are helpful for screen reader users navigating the website. They are also a good UI pattern since a user agent adds their own `` if a developer omitted it with no context on what UI the details element will expand. ### 👎 Examples of **incorrect** code for this rule: From aae4f1f344bdbc164a62a91ce14839efd4a8be02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 13:20:46 +0000 Subject: [PATCH 08/15] Remove unused `each_with_index` --- .../linters/github/accessibility/details_has_summary.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb index 94862ae..c01c896 100644 --- a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -16,7 +16,7 @@ def run(processed_source) current_details = nil has_summary = false - tags(processed_source).each_with_index do |tag, index| + tags(processed_source).each do |tag| if tag.name == "summary" && !tag.closing? has_summary = true end From bb572de5c23b3296dc28bb1a45e5f47baf5a85f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 13:22:58 +0000 Subject: [PATCH 09/15] Fix rubocop violations --- .../linters/github/accessibility/details_has_summary.rb | 4 +--- test/linters/accessibility/details_has_summary_test.rb | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb index c01c896..b536532 100644 --- a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -17,9 +17,7 @@ def run(processed_source) has_summary = false tags(processed_source).each do |tag| - if tag.name == "summary" && !tag.closing? - has_summary = true - end + has_summary = true if tag.name == "summary" && !tag.closing? next if tag.name != "details" diff --git a/test/linters/accessibility/details_has_summary_test.rb b/test/linters/accessibility/details_has_summary_test.rb index b2278bf..7ebf3aa 100644 --- a/test/linters/accessibility/details_has_summary_test.rb +++ b/test/linters/accessibility/details_has_summary_test.rb @@ -20,7 +20,7 @@ def test_does_not_warn_if_details_has_a_summary_in_a_weird_place assert_empty @linter.offenses end - + def test_does_not_warn_if_details_has_a_summary @file = "
Expand me!
" @linter.run(processed_source) From f4d75a96f54bc870e620accfd066de7fb677d3ea Mon Sep 17 00:00:00 2001 From: Manuel Puyol Date: Tue, 15 Mar 2022 10:58:15 -0500 Subject: [PATCH 10/15] Add TagTreeHelpers from PVC to actually build a tag tree structure --- .../linters/tag_tree_helpers.rb | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 lib/erblint-github/linters/tag_tree_helpers.rb diff --git a/lib/erblint-github/linters/tag_tree_helpers.rb b/lib/erblint-github/linters/tag_tree_helpers.rb new file mode 100644 index 0000000..5889f1f --- /dev/null +++ b/lib/erblint-github/linters/tag_tree_helpers.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +module ERBLint + module Linters + # Helpers used by linters to organize HTML tags into abstract syntax trees. + module TagTreeHelpers + # from https://github.com/Shopify/erb-lint/blob/6179ee2d9d681a6ec4dd02351a1e30eefa748d3d/lib/erb_lint/linters/self_closing_tag.rb + SELF_CLOSING_TAGS = %w[ + area base br col command embed hr input keygen + link menuitem meta param source track wbr img + ].freeze + + # This assumes that the AST provided represents valid HTML, where each tag has a corresponding closing tag. + # From the tags, we build a structured tree which represents the tag hierarchy. + # With this, we are able to know where the tags start and end. + def build_tag_tree(processed_source) + nodes = processed_source.ast.children + tag_tree = {} + tags = [] + current_opened_tag = nil + + nodes.each do |node| + tag = BetterHtml::Tree::Tag.from_node(node) + + if node.type == :tag + # get the tag from previously calculated list so the references are the same + tags << tag + + if tag.closing? + if current_opened_tag && tag.name == current_opened_tag.name + tag_tree[current_opened_tag][:closing] = tag + current_opened_tag = tag_tree[current_opened_tag][:parent] + end + + next + end + + self_closing = self_closing?(tag) + + tag_tree[tag] = { + tag: tag, + closing: self_closing ? tag : nil, + parent: current_opened_tag, + children: [] + } + + tag_tree[current_opened_tag][:children] << tag_tree[tag] if current_opened_tag + current_opened_tag = tag unless self_closing + elsif current_opened_tag + tag_tree[current_opened_tag][:children] << { + tag: tag, + closing: tag, + parent: current_opened_tag, + children: [] + } + end + end + + [tags, tag_tree] + end + + def self_closing?(tag) + tag.self_closing? || SELF_CLOSING_TAGS.include?(tag.name) + end + end + end +end From 6491bcc603e6bafbea647b936910068408d37c53 Mon Sep 17 00:00:00 2001 From: Manuel Puyol Date: Tue, 15 Mar 2022 10:58:37 -0500 Subject: [PATCH 11/15] Search for details with summaries using the tag_tree --- .../accessibility/details_has_summary.rb | 25 ++++++++++++------- .../accessibility/details_has_summary_test.rb | 7 ++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb index b536532..a371308 100644 --- a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative "../../custom_helpers" +require_relative "../../tag_tree_helpers" module ERBLint module Linters @@ -8,25 +9,31 @@ module GitHub module Accessibility class DetailsHasSummary < Linter include ERBLint::Linters::CustomHelpers + include ERBLint::Linters::TagTreeHelpers include LinterRegistry MESSAGE = "
elements need to have explict elements" def run(processed_source) - current_details = nil has_summary = false - tags(processed_source).each do |tag| - has_summary = true if tag.name == "summary" && !tag.closing? + (tags, tag_tree) = build_tag_tree(processed_source) - next if tag.name != "details" + tags.each do |tag| + next if tag.name != "details" || tag.closing? - if tag.closing? && !has_summary - generate_offense(self.class, processed_source, current_details) - current_details = nil - else - current_details = tag + details = tag_tree[tag] + + details[:children].each do |child| + if child && child[:tag].name == "summary" + has_summary = true + break + end end + + generate_offense(self.class, processed_source, details[:tag]) unless has_summary + + has_summary = false end rule_disabled?(processed_source) diff --git a/test/linters/accessibility/details_has_summary_test.rb b/test/linters/accessibility/details_has_summary_test.rb index 7ebf3aa..df78982 100644 --- a/test/linters/accessibility/details_has_summary_test.rb +++ b/test/linters/accessibility/details_has_summary_test.rb @@ -27,4 +27,11 @@ def test_does_not_warn_if_details_has_a_summary assert_empty @linter.offenses end + + def test_does_warns_if_details_has_a_summary_as_an_inner_child + @file = "

Expand me!

" + @linter.run(processed_source) + + assert_equal @linter.offenses.count, 1 + end end From afd2917331abe2c0b7c96f379b27889ef9b9c0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Tue, 15 Mar 2022 16:04:52 +0000 Subject: [PATCH 12/15] Add another incorrect example --- docs/rules/accessibility/details-has-summary.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/rules/accessibility/details-has-summary.md b/docs/rules/accessibility/details-has-summary.md index b2640a2..bb671b0 100644 --- a/docs/rules/accessibility/details-has-summary.md +++ b/docs/rules/accessibility/details-has-summary.md @@ -11,6 +11,13 @@
``` +```erb +
+
Expand me!
+ I have a invalid summary tag! The summary tag needs to be a direct child of the details tag. +
+``` + ### 👍 Examples of **correct** code for this rule: ```erb From 185195f9ae4fb46e3b4595871b27eb6b079d9856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Wed, 16 Mar 2022 10:26:07 +0000 Subject: [PATCH 13/15] fix speling Co-authored-by: Kate Higa <16447748+khiga8@users.noreply.github.com> --- .../linters/github/accessibility/details_has_summary.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb index a371308..6fb3ce0 100644 --- a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -12,7 +12,7 @@ class DetailsHasSummary < Linter include ERBLint::Linters::TagTreeHelpers include LinterRegistry - MESSAGE = "
elements need to have explict elements" + MESSAGE = "
elements need to have explicit element" def run(processed_source) has_summary = false From 3a802dcc4f4e41f8ef2ca3b81804b9f13d8c0b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Thu, 17 Mar 2022 14:08:32 +0000 Subject: [PATCH 14/15] Add a test for tag_tree_helpers --- test/linters/tag_tree_helpers_test.rb | 41 +++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 test/linters/tag_tree_helpers_test.rb diff --git a/test/linters/tag_tree_helpers_test.rb b/test/linters/tag_tree_helpers_test.rb new file mode 100644 index 0000000..f4fdf82 --- /dev/null +++ b/test/linters/tag_tree_helpers_test.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +require "test_helper" +require_relative "../../lib/erblint-github/linters/tag_tree_helpers" + +class TagTreeHelpers < Minitest::Test + include ERBLint::Linters::TagTreeHelpers + + def test_build_tree + file = %{ + + + Hello + + +

Hello

+ Welcome to my page! + + + } + processed_source = ERBLint::ProcessedSource.new("file.rb", file) + tags, tree = build_tag_tree(processed_source) + + html_tag = tags.first + + assert_equal "html", html_tag.name + + children = tree[html_tag][:children].filter do |child| + child[:tag].name + end + + assert_equal 2, children.length + assert_equal "head", children[0][:tag].name + + body_tag = children[1][:tag] + assert_equal "body", body_tag.name + + h1_tag = tree[body_tag][:children].filter{ |child| child[:tag].name }.first[:tag] + assert_equal "h1", h1_tag.name + end +end From 4e12784e36a2da4b331f536829622fa7ed292abf Mon Sep 17 00:00:00 2001 From: Manuel Puyol Date: Tue, 22 Mar 2022 10:59:44 -0500 Subject: [PATCH 15/15] add tests for content_tag --- .../accessibility/details_has_summary.rb | 36 +++++++++++++++- .../accessibility/details_has_summary_test.rb | 42 ++++++++++++++++++- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb index 6fb3ce0..03a6ae7 100644 --- a/lib/erblint-github/linters/github/accessibility/details_has_summary.rb +++ b/lib/erblint-github/linters/github/accessibility/details_has_summary.rb @@ -25,7 +25,28 @@ def run(processed_source) details = tag_tree[tag] details[:children].each do |child| - if child && child[:tag].name == "summary" + if child[:tag].name == "summary" + has_summary = true + break + end + + erb_nodes = extract_erb_nodes(child[:tag].node) + + next if erb_nodes.blank? + + code = "" + + erb_nodes.each do |erb_node| + _, _, code_node = *erb_node + code += code_node.children.first + end + + ast = erb_ast(code) + + ast = ast.children.first if ast.type == :block + next unless ast.method_name == :content_tag + + if ast.arguments.first.value.to_s == "summary" has_summary = true break end @@ -38,6 +59,19 @@ def run(processed_source) rule_disabled?(processed_source) end + + private + + def extract_erb_nodes(node) + return node if node.type == :erb + return nil unless node.type == :text + + node.children.select { |x| x.try(:type) == :erb } + end + + def erb_ast(code) + RuboCop::AST::ProcessedSource.new(code, RUBY_VERSION.to_f).ast + end end end end diff --git a/test/linters/accessibility/details_has_summary_test.rb b/test/linters/accessibility/details_has_summary_test.rb index df78982..54324c1 100644 --- a/test/linters/accessibility/details_has_summary_test.rb +++ b/test/linters/accessibility/details_has_summary_test.rb @@ -11,7 +11,7 @@ def test_warns_if_details_doesnt_have_a_summary @file = "
I don't have a summary element
" @linter.run(processed_source) - assert_equal @linter.offenses.count, 1 + assert_equal 1, @linter.offenses.count end def test_does_not_warn_if_details_has_a_summary_in_a_weird_place @@ -32,6 +32,44 @@ def test_does_warns_if_details_has_a_summary_as_an_inner_child @file = "

Expand me!

" @linter.run(processed_source) - assert_equal @linter.offenses.count, 1 + assert_equal 1, @linter.offenses.count + end + + def test_doesnt_warns_if_details_has_a_summary_content_tag + @file = <<~ERB +
+ <%= content_tag(:summary) { "Expand me!" } %> +

Surprise text!

+
+ ERB + @linter.run(processed_source) + + assert_empty @linter.offenses + end + + def test_doesnt_warns_if_details_has_a_summary_content_tag_with_do_block + @file = <<~ERB +
+ <%= content_tag(:summary) do %> + Expand me! + <% end %> +

Surprise text!

+
+ ERB + @linter.run(processed_source) + + assert_empty @linter.offenses + end + + def test_warns_if_details_has_a_non_summary_content_tag + @file = <<~ERB +
+ <%= content_tag(:div) { "Expand me!" } %> +

Surprise text!

+
+ ERB + @linter.run(processed_source) + + assert_equal 1, @linter.offenses.count end end