Skip to content

Commit

Permalink
Recommend usage of require: rubocop-rails-accessibility; rename Rub…
Browse files Browse the repository at this point in the history
…oCop department to "RailsAccessibility"
  • Loading branch information
bensheldon committed Oct 12, 2022
1 parent 61e9f3e commit 6199ad2
Show file tree
Hide file tree
Showing 21 changed files with 95 additions and 77 deletions.
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require:
- rubocop-rails-accessibility

inherit_gem:
rubocop-github:
- config/default.yml
Expand All @@ -7,3 +10,4 @@ Naming/FileName:
Enabled: true
Exclude:
- "rubocop-rails-accessibility.gemspec"
- "lib/rubocop-rails-accessibility.rb"
5 changes: 4 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ GEM
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
minitest (5.16.3)
nokogiri (1.13.8-arm64-darwin)
racc (~> 1.4)
nokogiri (1.13.8-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.13.8-x86_64-linux)
Expand Down Expand Up @@ -91,6 +93,7 @@ GEM
unicode-display_width (2.2.0)

PLATFORMS
arm64-darwin-21
x86_64-darwin-19
x86_64-linux

Expand All @@ -105,4 +108,4 @@ DEPENDENCIES
rubocop-rails-accessibility!

BUNDLED WITH
2.3.17
2.3.22
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ You need to tell RuboCop to load RuboCop Rails Accessibility.
Put this into your `.rubocop.yml`.

``` yaml
inherit_gem:
rubocop-rails-accessibility:
- config/default.yml
require:
- rubocop-rails-accessibility
```
## Testing
Expand All @@ -47,14 +46,14 @@ bundle exec rake
## The Cops

All cops are located under
[`lib/rubocop/cop/rubocop-rails-accessibility`](lib/rubocop/cop/rubocop-rails-accessibility), and contain
[`lib/rubocop/cop/rails_accessibility`](lib/rubocop/cop/rails_accessibility), and contain
examples/documentation.

## Rules

- [RuboCop::Cop::Accessibility::ImageHasAlt](guides/image-has-alt.md)
- [RuboCop::Cop::Accessibility::NoPositiveTabindex](guides/no-positive-tabindex.md)
- [RuboCop::Cop::Accessibility::NoRedundantImageAlt](guides/no-redundant-image-alt.md)
- [RailsAccessibility/ImageHasAlt](guides/image-has-alt.md)
- [RailsAccessibility/NoPositiveTabindex](guides/no-positive-tabindex.md)
- [RailsAccessibility/NoRedundantImageAlt](guides/no-redundant-image-alt.md)

## Contributing

Expand Down
14 changes: 5 additions & 9 deletions config/default.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
require:
- rubocop/cop/rubocop_rails_accessibility_cops

AllCops:
DisabledByDefault: true

RubocopRailsAccessibility/ImageHasAlt:
RailsAccessibility/ImageHasAlt:
Enabled: true
StyleGuide: https://github.com/github/rubocop-rails-accessibility/blob/master/guides/image-has-alt.md
RubocopRailsAccessibility/NoPositiveTabindex:

RailsAccessibility/NoPositiveTabindex:
Enabled: true
StyleGuide: https://github.com/github/rubocop-rails-accessibility/blob/master/guides/no-positive-tabindex.md
RubocopRailsAccessibility/NoRedundantImageAlt:

RailsAccessibility/NoRedundantImageAlt:
Enabled: true
StyleGuide: https://github.com/github/rubocop-rails-accessibility/blob/master/guides/no-redundant-image-alt.md
4 changes: 2 additions & 2 deletions guides/image-has-alt.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RubocopRailsAccessibility/ImageHasAlt
# RailsAccessibility/ImageHasAlt

## Rule Details

Expand Down Expand Up @@ -26,4 +26,4 @@ Images should have an alt prop with meaningful text or an empty string for decor
```erb
<!-- also good -->
<%= image_tag "spinners/octocat-spinner-16px.gif", size: "12x12", alt: "" %>
```
```
4 changes: 2 additions & 2 deletions guides/no-positive-tabindex.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RubocopRailsAccessibility/NoPositiveTabindex
# RailsAccessibility/NoPositiveTabindex

## Rule Details

Expand All @@ -21,4 +21,4 @@ Positive tabindex is error-prone and often inaccessible.
```erb
<!-- good -->
<%= button_tag "Continue", :tabindex => -1 %>
```
```
4 changes: 2 additions & 2 deletions guides/no-redundant-image-alt.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RubocopRailsAccessibility/NoRedundantImageAlt
# RailsAccessibility/NoRedundantImageAlt

## Rule Details

Expand All @@ -21,4 +21,4 @@ Alt prop should not contain `image` or `picture` as screen readers already annou
```erb
<!-- good -->
<%= image_tag "cat.gif", size: "12x12", alt: "A black cat" %>
```
```
12 changes: 12 additions & 0 deletions lib/rubocop-rails-accessibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "rubocop"
require "rubocop/rails_accessibility"
require "rubocop/rails_accessibility/inject"
require "rubocop/rails_accessibility/version"

RuboCop::RailsAccessibility::Inject.defaults!

require "rubocop/cop/rails_accessibility/image_has_alt"
require "rubocop/cop/rails_accessibility/no_positive_tabindex"
require "rubocop/cop/rails_accessibility/no_redundant_image_alt"
18 changes: 0 additions & 18 deletions lib/rubocop/cop/inject.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module RuboCop
module Cop
module RubocopRailsAccessibility
module RailsAccessibility
class ImageHasAlt < Base
MSG = "Images should have an alt prop with meaningful text or an empty string for decorative images"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module RuboCop
module Cop
module RubocopRailsAccessibility
module RailsAccessibility
class NoPositiveTabindex < Base
MSG = "Positive tabindex is error-prone and often inaccessible."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

module RuboCop
module Cop
module RubocopRailsAccessibility
module RailsAccessibility
class NoRedundantImageAlt < Base
MSG = "Alt prop should not contain `image` or `picture` as screen readers already announce the element as an image"
REDUNDANT_ALT_WORDS = %w[image picture].freeze
Expand Down
10 changes: 0 additions & 10 deletions lib/rubocop/cop/rubocop_rails_accessibility_cops.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/rubocop/cop/version.rb

This file was deleted.

10 changes: 10 additions & 0 deletions lib/rubocop/rails_accessibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "pathname"

module RuboCop
module RailsAccessibility
PROJECT_ROOT = Pathname.new(__dir__).parent.parent.expand_path.freeze
CONFIG_DEFAULT = PROJECT_ROOT.join("config", "default.yml").freeze
end
end
20 changes: 20 additions & 0 deletions lib/rubocop/rails_accessibility/inject.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require "rubocop"

# The original code is from https://github.com/rubocop/rubocop-rspec/blob/main/lib/rubocop/rspec/inject.rb
# See https://github.com/rubocop/rubocop-rspec/blob/main/MIT-LICENSE.md
module RuboCop
module RailsAccessibility
module Inject
def self.defaults!
path = CONFIG_DEFAULT.to_s
hash = ::RuboCop::ConfigLoader.send(:load_yaml_configuration, path)
config = ::RuboCop::Config.new(hash, path).tap(&:make_excludes_absolute)
puts "configuration from #{path}" if ::RuboCop::ConfigLoader.debug?
config = ::RuboCop::ConfigLoader.merge_with_default(config, path)
::RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, config)
end
end
end
end
7 changes: 7 additions & 0 deletions lib/rubocop/rails_accessibility/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module RuboCop
module RailsAccessibility
VERSION = "0.1.2"
end
end
24 changes: 12 additions & 12 deletions rubocop-rails-accessibility.gemspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

require_relative "lib/rubocop/cop/version"
require_relative "lib/rubocop/rails_accessibility/version"

Gem::Specification.new do |spec|
spec.name = "rubocop-rails-accessibility"
spec.version = RubocopRailsAccessibility::VERSION
spec.version = RuboCop::RailsAccessibility::VERSION
spec.authors = ["GitHub Accessibility Team"]
spec.email = ["[email protected]"]

spec.summary = "Custom extension for RuboCop."
spec.summary = "Custom RuboCop rules for Rails Accessibility."
spec.homepage = "https://github.com/github/rubocop-rails-accessibility"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.7.0"
Expand All @@ -28,14 +28,14 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rubocop-rails"
spec.add_development_dependency "rubocop-performance"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.files = Dir[
"config/*.yml",
"guides/*.md",
"lib/**/*.rb",
"CONTRIBUTING.md",
"LICENSE",
"README.md",
]

spec.require_paths = ["lib"]
end
4 changes: 2 additions & 2 deletions test/test_image_has_alt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

require_relative "./cop_test"
require "minitest/autorun"
require "rubocop/cop/rubocop-rails-accessibility/image_has_alt"
require "rubocop/cop/rails_accessibility/image_has_alt"

class TestImageHasAlt < CopTest
def cop_class
RuboCop::Cop::RubocopRailsAccessibility::ImageHasAlt
RuboCop::Cop::RailsAccessibility::ImageHasAlt
end

def test_image_has_alt_offense
Expand Down
4 changes: 2 additions & 2 deletions test/test_no_positive_tabindex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

require_relative "./cop_test"
require "minitest/autorun"
require "rubocop/cop/rubocop-rails-accessibility/no_positive_tabindex"
require "rubocop/cop/rails_accessibility/no_positive_tabindex"

class NoPositiveTabindex < CopTest
def cop_class
RuboCop::Cop::RubocopRailsAccessibility::NoPositiveTabindex
RuboCop::Cop::RailsAccessibility::NoPositiveTabindex
end

def test_no_positive_tabindex_alt_offense
Expand Down
4 changes: 2 additions & 2 deletions test/test_no_redundant_image_alt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

require_relative "./cop_test"
require "minitest/autorun"
require "rubocop/cop/rubocop-rails-accessibility/no_redundant_image_alt"
require "rubocop/cop/rails_accessibility/no_redundant_image_alt"

class NoRedundantImageAlt < CopTest
def cop_class
RuboCop::Cop::RubocopRailsAccessibility::NoRedundantImageAlt
RuboCop::Cop::RailsAccessibility::NoRedundantImageAlt
end

def test_no_redundant_image_alt_offense
Expand Down

0 comments on commit 6199ad2

Please sign in to comment.