From ea9d80d89aa8de9f3d3ee32a38067efa3beb7dd4 Mon Sep 17 00:00:00 2001 From: Kate Higa Date: Thu, 17 Feb 2022 16:34:41 -0800 Subject: [PATCH 1/5] add counter support and title counter --- README.md | 3 ++ .../no-title-attribute-counter.md | 39 ++++++++++++++ lib/erblint-github/linters/custom_helpers.rb | 35 +++++++++++++ .../no_title_attribute_counter.rb | 51 +++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 docs/rules/accessibility/no-title-attribute-counter.md create mode 100644 lib/erblint-github/linters/github/accessibility/no_title_attribute_counter.rb diff --git a/README.md b/README.md index 2679eca..486d788 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ linters: enabled: true GitHub::Accessibility::NoRedundantImageAlt: enabled: true + GitHub::Accessibility::NoTitleAttributeCounter: + enabled: true ``` ## Rules @@ -45,6 +47,7 @@ linters: - [GitHub::Accessibility::NoAriaLabelMisuse](./docs/rules/accessibility/no-aria-label-misuse.md) - [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) ## Testing diff --git a/docs/rules/accessibility/no-title-attribute-counter.md b/docs/rules/accessibility/no-title-attribute-counter.md new file mode 100644 index 0000000..c787688 --- /dev/null +++ b/docs/rules/accessibility/no-title-attribute-counter.md @@ -0,0 +1,39 @@ +# No title attribute counter + +## Rule Details + +The `title` attribute is strongly discouraged. The only exception is on an `" + @linter.run(processed_source) + + assert_empty @linter.offenses + end + + def test_does_not_autocorrect_when_ignores_are_correct + @file = <<~ERB + <%# erblint:counter GitHub::Accessibility::NoTitleAttributeCounter 1 %> + some website + ERB + + assert_equal @file, corrected_content + end + + def test_does_autocorrect_when_ignores_are_not_correct + @file = <<~ERB + <%# erblint:counter GitHub::Accessibility::NoTitleAttributeCounter 3 %> + some website + ERB + refute_equal @file, corrected_content + + expected_content = <<~ERB + <%# erblint:counter GitHub::Accessibility::NoTitleAttributeCounter 1 %> + some website + ERB + assert_equal expected_content, corrected_content + end +end From e4e8c85a6fd456268a0fc1846491031bd2424148 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Tue, 22 Feb 2022 11:31:16 -0800 Subject: [PATCH 4/5] Update docs/rules/accessibility/no-title-attribute-counter.md Co-authored-by: Lindsey Wild <35239154+lindseywild@users.noreply.github.com> --- docs/rules/accessibility/no-title-attribute-counter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/accessibility/no-title-attribute-counter.md b/docs/rules/accessibility/no-title-attribute-counter.md index 767b22a..dabd98a 100644 --- a/docs/rules/accessibility/no-title-attribute-counter.md +++ b/docs/rules/accessibility/no-title-attribute-counter.md @@ -8,7 +8,7 @@ The `title` attribute is commonly seen set on links, matching the link text. Thi If you are considering `title` attribute to provide supplementary description, consider whether the text in question can be persisted in the design. Alternatively, if it's important to display supplementary text that is hidden by default, consider using an **accessible** tooltip implementation that uses the `aria-labelledby` or `aria-describedby` semantics. Even so, proceed with caution: tooltips should only be used on interactive elements like links or buttons. -### Should I use `title` attribute to provide accessible name for ``? +### Should I use the `title` attribute to provide an accessible name for an ``? Use a `` element instead of the `title` attribute, or an `aria-label`. From 7591c1b64faf15135ce0305d629119c86304ba1e Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Tue, 22 Feb 2022 11:31:21 -0800 Subject: [PATCH 5/5] Update docs/rules/accessibility/no-title-attribute-counter.md Co-authored-by: Lindsey Wild <35239154+lindseywild@users.noreply.github.com> --- docs/rules/accessibility/no-title-attribute-counter.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/accessibility/no-title-attribute-counter.md b/docs/rules/accessibility/no-title-attribute-counter.md index dabd98a..0da86fd 100644 --- a/docs/rules/accessibility/no-title-attribute-counter.md +++ b/docs/rules/accessibility/no-title-attribute-counter.md @@ -6,7 +6,7 @@ The `title` attribute is strongly discouraged. The only exception is on an `