Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ require "erblint-github/linters"
```yaml
---
linters:
GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled:
GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter:
enabled: true
GitHub::Accessibility::AvoidGenericLinkTextCounter:
enabled: true
GitHub::Accessibility::DisabledAttributeCounter:
enabled: true
GitHub::Accessibility::IframeHasTitle:
GitHub::Accessibility::IframeHasTitleCounter:
enabled: true
GitHub::Accessibility::ImageHasAlt:
GitHub::Accessibility::ImageHasAltCounter:
enabled: true
GitHub::Accessibility::LandmarkHasLabelCounter:
enabled: true
Expand All @@ -41,9 +41,9 @@ linters:
enabled: true
GitHub::Accessibility::NoAriaLabelMisuseCounter:
enabled: true
GitHub::Accessibility::NoPositiveTabIndex:
GitHub::Accessibility::NoPositiveTabIndexCounter:
enabled: true
GitHub::Accessibility::NoRedundantImageAlt:
GitHub::Accessibility::NoRedundantImageAltCounter:
enabled: true
GitHub::Accessibility::NoTitleAttributeCounter:
enabled: true
Expand All @@ -53,17 +53,17 @@ linters:

## Rules

- [GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled](./docs/rules/accessibility/avoid-both-disabled-and-aria-disabled.md)
- [GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter](./docs/rules/accessibility/avoid-both-disabled-and-aria-disabled-counter.md)
- [GitHub::Accessibility::AvoidGenericLinkTextCounter](./docs/rules/accessibility/avoid-generic-link-text-counter.md)
- [GitHub::Accessibility::DisabledAttributeCounter](./docs/rules/accessibility/disabled-attribute-counter.md)
- [GitHub::Accessibility::IframeHasTitle](./docs/rules/accessibility/iframe-has-title.md)
- [GitHub::Accessibility::LandmarkHasLabelCounter](./docs/rules/accessibility/landmark-has-label-counter.md)
- [GitHub::Accessibility::ImageHasAlt](./docs/rules/accessibility/image-has-alt.md)
- [GitHub::Accessibility::LinkHasHrefCounter](./docs/rules/accessibility/link-has-href-counter.md)
- [GitHub::Accessibility::NestedInteractiveElementsCounter](./docs/rules/accessibility/nested-interactive-elements-counter.md)
- [GitHub::Accessibility::IframeHasTitleCounter](./docs/rules/accessibility/iframe-has-title-counter.md)
- [GitHub::Accessibility::ImageHasAltCounter](./docs/rules/accessibility/image-has-alt-counter.md)
- [GitHub::Accessibility::NoAriaLabelMisuseCounter](./docs/rules/accessibility/no-aria-label-misuse-counter.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::NoPositiveTabIndexCounter](./docs/rules/accessibility/no-positive-tab-index-counter.md)
- [GitHub::Accessibility::NoRedundantImageAltCounter](./docs/rules/accessibility/no-redundant-image-alt-counter.md)
- [GitHub::Accessibility::NoTitleAttributeCounter](./docs/rules/accessibility/no-title-attribute-counter.md)
- [GitHub::Accessibility::SvgHasAccessibleTextCounter](./docs/rules/accessibility/svg-has-accessible-text-counter.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ERBLint
module Linters
module GitHub
module Accessibility
class AvoidBothDisabledAndAriaDisabled < Linter
class AvoidBothDisabledAndAriaDisabledCounter < Linter
include ERBLint::Linters::CustomHelpers
include LinterRegistry

Expand All @@ -22,7 +22,21 @@ def run(processed_source)
generate_offense(self.class, processed_source, tag)
end

rule_disabled?(processed_source)
counter_correct?(processed_source)
end

def autocorrect(processed_source, offense)
return unless offense.context

lambda do |corrector|
if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
# update the counter if exists
corrector.replace(offense.source_range, offense.context)
else
# add comment with counter if none
corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ERBLint
module Linters
module GitHub
module Accessibility
class IframeHasTitle < Linter
class IframeHasTitleCounter < Linter
include ERBLint::Linters::CustomHelpers
include LinterRegistry

Expand All @@ -23,7 +23,21 @@ def run(processed_source)
generate_offense(self.class, processed_source, tag) if title.empty? && !aria_hidden?(tag)
end

rule_disabled?(processed_source)
counter_correct?(processed_source)
end

def autocorrect(processed_source, offense)
return unless offense.context

lambda do |corrector|
if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
# update the counter if exists
corrector.replace(offense.source_range, offense.context)
else
# add comment with counter if none
corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
end
end
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ERBLint
module Linters
module GitHub
module Accessibility
class ImageHasAlt < Linter
class ImageHasAltCounter < Linter
include ERBLint::Linters::CustomHelpers
include LinterRegistry

Expand All @@ -22,7 +22,21 @@ def run(processed_source)
generate_offense(self.class, processed_source, tag) if alt.empty?
end

rule_disabled?(processed_source)
counter_correct?(processed_source)
end

def autocorrect(processed_source, offense)
return unless offense.context

lambda do |corrector|
if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
# update the counter if exists
corrector.replace(offense.source_range, offense.context)
else
# add comment with counter if none
corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ERBLint
module Linters
module GitHub
module Accessibility
class NoPositiveTabIndex < Linter
class NoPositiveTabIndexCounter < Linter
include ERBLint::Linters::CustomHelpers
include LinterRegistry

Expand All @@ -20,7 +20,21 @@ def run(processed_source)
generate_offense(self.class, processed_source, tag)
end

rule_disabled?(processed_source)
counter_correct?(processed_source)
end

def autocorrect(processed_source, offense)
return unless offense.context

lambda do |corrector|
if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
# update the counter if exists
corrector.replace(offense.source_range, offense.context)
else
# add comment with counter if none
corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module ERBLint
module Linters
module GitHub
module Accessibility
class NoRedundantImageAlt < Linter
class NoRedundantImageAltCounter < Linter
include ERBLint::Linters::CustomHelpers
include LinterRegistry

Expand All @@ -24,7 +24,21 @@ def run(processed_source)
generate_offense(self.class, processed_source, tag) if (alt.downcase.split & REDUNDANT_ALT_WORDS).any?
end

rule_disabled?(processed_source)
counter_correct?(processed_source)
end

def autocorrect(processed_source, offense)
return unless offense.context

lambda do |corrector|
if processed_source.file_content.include?("erblint:counter #{simple_class_name}")
# update the counter if exists
corrector.replace(offense.source_range, offense.context)
else
# add comment with counter if none
corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n")
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class AvoidBothDisabledAndAriaDisabled < LinterTestCase
def linter_class
ERBLint::Linters::GitHub::Accessibility::AvoidBothDisabledAndAriaDisabled
ERBLint::Linters::GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter
end

ELEMENTS_WITH_NATIVE_DISABLED_ATTRIBUTE_SUPPORT = %w[button fieldset input optgroup option select textarea].freeze
Expand All @@ -15,7 +15,7 @@ def test_warns_if_both_disabled_and_aria_disabled_set_on_html_elements_with_disa
end.join
@linter.run(processed_source)

assert_equal @linter.offenses.count, 7
assert_equal @linter.offenses.count, 8
end

def test_does_not_warn_if_only_disabled_attribute_is_set
Expand All @@ -35,4 +35,36 @@ def test_does_not_warn_if_only_aria_disabled_attribute_is_set

assert_empty @linter.offenses
end

def test_does_not_raise_when_ignore_comment_with_correct_count
@file = <<~ERB
<%# erblint:counter GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter 1 %>
<button disabled aria-disabled="true">Some text</span>
ERB

@linter.run(processed_source)
assert_empty @linter.offenses
end

def test_does_not_autocorrect_when_ignores_are_correct
@file = <<~ERB
<%# erblint:counter GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter 1 %>
<button disabled aria-disabled="true">Some text</button>
ERB

assert_equal @file, corrected_content
end

def test_does_autocorrect_when_ignores_are_not_correct
@file = <<~ERB
<button disabled aria-disabled="true">Some text</button>
ERB
refute_equal @file, corrected_content

expected_content = <<~ERB
<%# erblint:counter GitHub::Accessibility::AvoidBothDisabledAndAriaDisabledCounter 1 %>
<button disabled aria-disabled="true">Some text</button>
ERB
assert_equal expected_content, corrected_content
end
end
62 changes: 62 additions & 0 deletions test/linters/accessibility/iframe_has_title_counter_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

require "test_helper"

class IframeHasTitleCounterTest < LinterTestCase
def linter_class
ERBLint::Linters::GitHub::Accessibility::IframeHasTitleCounter
end

def test_warns_if_iframe_has_no_title
@file = "<iframe alt='image of an octopus'></iframe>"
@linter.run(processed_source)

refute_empty @linter.offenses
end

def test_does_not_warn_if_iframe_has_aria_hidden_to_true
@file = "<iframe aria-hidden='true'></iframe>"
@linter.run(processed_source)

assert_empty @linter.offenses
end

def test_does_not_warn_if_iframe_has_title_set_to_string
@file = "<iframe title='Video tutorial of GitHub Actions'></iframe>"
@linter.run(processed_source)

assert_empty @linter.offenses
end

def test_does_not_raise_when_ignore_comment_with_correct_count
@file = <<~ERB
<%# erblint:counter GitHub::Accessibility::IframeHasTitleCounter 1 %>
<iframe></iframe>
ERB

@linter.run(processed_source)
assert_empty @linter.offenses
end

def test_does_not_autocorrect_when_ignores_are_correct
@file = <<~ERB
<%# erblint:counter GitHub::Accessibility::IframeHasTitleCounter 1 %>
<iframe></iframe>
ERB

assert_equal @file, corrected_content
end

def test_does_autocorrect_when_ignores_are_not_correct
@file = <<~ERB
<iframe></iframe>
ERB
refute_equal @file, corrected_content

expected_content = <<~ERB
<%# erblint:counter GitHub::Accessibility::IframeHasTitleCounter 1 %>
<iframe></iframe>
ERB
assert_equal expected_content, corrected_content
end
end
30 changes: 0 additions & 30 deletions test/linters/accessibility/iframe_has_title_test.rb

This file was deleted.

Loading