From c1f8175975a6cdeca6331c4833fbe8ae131643e0 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Thu, 13 Apr 2023 20:13:46 -0400 Subject: [PATCH 1/6] Update docs to be more helpful --- .../aria-label-is-well-formatted.md | 26 ++++++++++++++++--- .../aria_label_is_well_formatted_test.rb | 3 ++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/docs/rules/accessibility/aria-label-is-well-formatted.md b/docs/rules/accessibility/aria-label-is-well-formatted.md index e8fc344..7152bea 100644 --- a/docs/rules/accessibility/aria-label-is-well-formatted.md +++ b/docs/rules/accessibility/aria-label-is-well-formatted.md @@ -2,10 +2,18 @@ ## Rule Details -`[aria-label]` content should be formatted in the same way you would visual text. Please use sentence case. +`[aria-label]` content should be formatted in the same way you would visual text. -Do not kebab case the words like you would an HTML ID. An `aria-label` is different from `aria-labelledby`. -An `aria-label` is not an ID, and should be formatted as human-friendly text. +Keep the following practices in mind: + +- Use sentence case. +- Do not kebab case the words like you would an HTML ID. An `aria-label` is different from `aria-labelledby`. An `aria-label` represents the name of a control, and has the same purpsoe as a visual label would for screen reader users. Therefore, it should be formatted as human-friendly text. +- Do not use line-break characters like, ` `. An accessible name should be concise to start with. +- Do not set the `aria-label` to a URL. Instead, use an appropriate name. + +## Resources + +- [Staff only: Guidance on naming controls](https://github.com/github/accessibility-playbook/blob/main/content/link-and-button-guidance.mdx#guidance-on-naming-controls) ## Config @@ -35,6 +43,14 @@ If you determine that there are valid scenarios for `aria-label` to start with l + HTML @linter.run(processed_source) - assert_equal 4, @linter.offenses.count + assert_equal 5, @linter.offenses.count end def test_does_not_warn_when_aria_labelledby_starts_with_downcase From 2c893f8475fc7997ede4ec6adb4303dcad110cc8 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Fri, 14 Apr 2023 08:27:43 -0400 Subject: [PATCH 2/6] Update docs/rules/accessibility/aria-label-is-well-formatted.md Co-authored-by: Joyce Zhu --- docs/rules/accessibility/aria-label-is-well-formatted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/accessibility/aria-label-is-well-formatted.md b/docs/rules/accessibility/aria-label-is-well-formatted.md index 7152bea..40052fb 100644 --- a/docs/rules/accessibility/aria-label-is-well-formatted.md +++ b/docs/rules/accessibility/aria-label-is-well-formatted.md @@ -7,7 +7,7 @@ Keep the following practices in mind: - Use sentence case. -- Do not kebab case the words like you would an HTML ID. An `aria-label` is different from `aria-labelledby`. An `aria-label` represents the name of a control, and has the same purpsoe as a visual label would for screen reader users. Therefore, it should be formatted as human-friendly text. +- Do not kebab case the words like you would an HTML ID. An `aria-label` is different from `aria-labelledby`. An `aria-label` represents the name of a control, and has the same purpose as a visual label would for screen reader users. Therefore, it should be formatted as human-friendly text. - Do not use line-break characters like, ` `. An accessible name should be concise to start with. - Do not set the `aria-label` to a URL. Instead, use an appropriate name. From 9ba998f28b83a98f6a9969c7443c7937d452d259 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Fri, 14 Apr 2023 08:27:48 -0400 Subject: [PATCH 3/6] Update docs/rules/accessibility/aria-label-is-well-formatted.md Co-authored-by: Joyce Zhu --- docs/rules/accessibility/aria-label-is-well-formatted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/accessibility/aria-label-is-well-formatted.md b/docs/rules/accessibility/aria-label-is-well-formatted.md index 40052fb..16429fb 100644 --- a/docs/rules/accessibility/aria-label-is-well-formatted.md +++ b/docs/rules/accessibility/aria-label-is-well-formatted.md @@ -8,7 +8,7 @@ Keep the following practices in mind: - Use sentence case. - Do not kebab case the words like you would an HTML ID. An `aria-label` is different from `aria-labelledby`. An `aria-label` represents the name of a control, and has the same purpose as a visual label would for screen reader users. Therefore, it should be formatted as human-friendly text. -- Do not use line-break characters like, ` `. An accessible name should be concise to start with. +- Do not use line-break characters like ` `. An accessible name should be concise to start with. - Do not set the `aria-label` to a URL. Instead, use an appropriate name. ## Resources From d37f91cdbe9edea43f74cf10eeedb377fadfa337 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Fri, 14 Apr 2023 08:27:59 -0400 Subject: [PATCH 4/6] Update docs/rules/accessibility/aria-label-is-well-formatted.md Co-authored-by: Joyce Zhu --- docs/rules/accessibility/aria-label-is-well-formatted.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/rules/accessibility/aria-label-is-well-formatted.md b/docs/rules/accessibility/aria-label-is-well-formatted.md index 16429fb..90b4a67 100644 --- a/docs/rules/accessibility/aria-label-is-well-formatted.md +++ b/docs/rules/accessibility/aria-label-is-well-formatted.md @@ -9,7 +9,7 @@ Keep the following practices in mind: - Use sentence case. - Do not kebab case the words like you would an HTML ID. An `aria-label` is different from `aria-labelledby`. An `aria-label` represents the name of a control, and has the same purpose as a visual label would for screen reader users. Therefore, it should be formatted as human-friendly text. - Do not use line-break characters like ` `. An accessible name should be concise to start with. -- Do not set the `aria-label` to a URL. Instead, use an appropriate name. +- Do not set the `aria-label` to a URL. Instead, use an appropriate human-friendly description. ## Resources From 3dfa13b9ed84b0d496aa70ebc0698bd7cc411d97 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Mon, 17 Apr 2023 10:36:05 -0400 Subject: [PATCH 5/6] Update logic --- lib/erblint-github/linters/custom_helpers.rb | 2 +- .../aria_label_is_well_formatted.rb | 5 ++-- .../aria_label_is_well_formatted_test.rb | 26 +++++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/erblint-github/linters/custom_helpers.rb b/lib/erblint-github/linters/custom_helpers.rb index ebab2d2..24826ea 100644 --- a/lib/erblint-github/linters/custom_helpers.rb +++ b/lib/erblint-github/linters/custom_helpers.rb @@ -57,7 +57,7 @@ def generate_offense_from_source_range(klass, source_range, message = nil, repla def possible_attribute_values(tag, attr_name) value = tag.attributes[attr_name]&.value || nil - basic_conditional_code_check(value || "") || [value].compact + [value].compact end # Map possible values from condition diff --git a/lib/erblint-github/linters/github/accessibility/aria_label_is_well_formatted.rb b/lib/erblint-github/linters/github/accessibility/aria_label_is_well_formatted.rb index 4f9073f..17606fe 100644 --- a/lib/erblint-github/linters/github/accessibility/aria_label_is_well_formatted.rb +++ b/lib/erblint-github/linters/github/accessibility/aria_label_is_well_formatted.rb @@ -10,7 +10,7 @@ class AriaLabelIsWellFormatted < Linter include ERBLint::Linters::CustomHelpers include LinterRegistry - MESSAGE = "[aria-label] text should be formatted the same as you would visual text. Use sentence case." + MESSAGE = "[aria-label] text should be formatted the same as you would visual text. Use sentence case, and don't format it like an ID. Additionally, `aria-label` should be concise and should not contain line breaks." class ConfigSchema < LinterConfig property :exceptions, accepts: array_of?(String), @@ -23,9 +23,8 @@ def run(processed_source) next if tag.closing? aria_label = possible_attribute_values(tag, "aria-label").join - next if aria_label.empty? - if aria_label.match?(/^[a-z]/) && !@config.exceptions.include?(aria_label) + if (aria_label.start_with?(/^[a-z]/) || aria_label.match?(/[\r\n]+/)) && !@config.exceptions.include?(aria_label) generate_offense(self.class, processed_source, tag) end end diff --git a/test/linters/accessibility/aria_label_is_well_formatted_test.rb b/test/linters/accessibility/aria_label_is_well_formatted_test.rb index c957539..6ecfed8 100644 --- a/test/linters/accessibility/aria_label_is_well_formatted_test.rb +++ b/test/linters/accessibility/aria_label_is_well_formatted_test.rb @@ -20,6 +20,15 @@ def test_warns_when_aria_label_starts_with_downcase assert_equal 5, @linter.offenses.count end + def test_warns_when_aria_label_contains_newline_characer + @file = <<~HTML + + + HTML + @linter.run(processed_source) + assert_equal 2, @linter.offenses.count + end + def test_does_not_warn_when_aria_labelledby_starts_with_downcase @file = " - - - HTML + def test_does_not_warn_with_string_interpolation + @file = '' @linter.run(processed_source) assert_empty @linter.offenses end - def test_does_not_warn_when_aria_label_is_excepted_in_config + def test_does_not_warn_when_aria_label_starts_with_anything_other_than_downcase @file = <<~HTML @@ -49,15 +54,14 @@ def test_does_not_warn_when_aria_label_is_excepted_in_config assert_empty @linter.offenses end - def test_does_not_warn_if_aria_label_is_in_excepted_list @file = <<~HTML - + HTML - @linter.config.exceptions = ["hello"] + @linter.config.exceptions = ["hello", "git checkout <%= some_branch %>"] @linter.run(processed_source) - assert_equal 1, @linter.offenses.count + assert_empty @linter.offenses end end From 73c83303b7973d851c3c407e6a83a043d6466bf3 Mon Sep 17 00:00:00 2001 From: Kate Higa <16447748+khiga8@users.noreply.github.com> Date: Tue, 18 Apr 2023 10:40:46 -0400 Subject: [PATCH 6/6] Bump to 0.3.1 --- Gemfile.lock | 2 +- erblint-github.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1754b8d..2b54584 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - erblint-github (0.3.0) + erblint-github (0.3.1) GEM remote: https://rubygems.org/ diff --git a/erblint-github.gemspec b/erblint-github.gemspec index 667bcea..2aa3d55 100644 --- a/erblint-github.gemspec +++ b/erblint-github.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = "erblint-github" - s.version = "0.3.0" + s.version = "0.3.1" s.summary = "erblint GitHub" s.description = "Template style checking for GitHub Ruby repositories" s.homepage = "https://github.com/github/erblint-github"