diff --git a/.rubocop.yml b/.rubocop.yml index 8cbb45e..503ac56 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +require: + - rubocop-rails-accessibility + inherit_gem: rubocop-github: - config/default.yml @@ -7,3 +10,4 @@ Naming/FileName: Enabled: true Exclude: - "rubocop-rails-accessibility.gemspec" + - "lib/rubocop-rails-accessibility.rb" diff --git a/Gemfile.lock b/Gemfile.lock index da1bbe9..c208e50 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -91,6 +93,7 @@ GEM unicode-display_width (2.2.0) PLATFORMS + arm64-darwin-21 x86_64-darwin-19 x86_64-linux @@ -105,4 +108,4 @@ DEPENDENCIES rubocop-rails-accessibility! BUNDLED WITH - 2.3.17 + 2.3.22 diff --git a/README.md b/README.md index 187eea5..495297b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/config/default.yml b/config/default.yml index e2b002c..5d6cc8f 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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 diff --git a/guides/image-has-alt.md b/guides/image-has-alt.md index 3dab40b..0ee9466 100644 --- a/guides/image-has-alt.md +++ b/guides/image-has-alt.md @@ -1,4 +1,4 @@ -# RubocopRailsAccessibility/ImageHasAlt +# RailsAccessibility/ImageHasAlt ## Rule Details @@ -26,4 +26,4 @@ Images should have an alt prop with meaningful text or an empty string for decor ```erb <%= image_tag "spinners/octocat-spinner-16px.gif", size: "12x12", alt: "" %> -``` \ No newline at end of file +``` diff --git a/guides/no-positive-tabindex.md b/guides/no-positive-tabindex.md index cf0e265..00f9825 100644 --- a/guides/no-positive-tabindex.md +++ b/guides/no-positive-tabindex.md @@ -1,4 +1,4 @@ -# RubocopRailsAccessibility/NoPositiveTabindex +# RailsAccessibility/NoPositiveTabindex ## Rule Details @@ -21,4 +21,4 @@ Positive tabindex is error-prone and often inaccessible. ```erb <%= button_tag "Continue", :tabindex => -1 %> -``` \ No newline at end of file +``` diff --git a/guides/no-redundant-image-alt.md b/guides/no-redundant-image-alt.md index 8b68867..3276e0d 100644 --- a/guides/no-redundant-image-alt.md +++ b/guides/no-redundant-image-alt.md @@ -1,4 +1,4 @@ -# RubocopRailsAccessibility/NoRedundantImageAlt +# RailsAccessibility/NoRedundantImageAlt ## Rule Details @@ -21,4 +21,4 @@ Alt prop should not contain `image` or `picture` as screen readers already annou ```erb <%= image_tag "cat.gif", size: "12x12", alt: "A black cat" %> -``` \ No newline at end of file +``` diff --git a/lib/rubocop-rails-accessibility.rb b/lib/rubocop-rails-accessibility.rb new file mode 100644 index 0000000..ed45347 --- /dev/null +++ b/lib/rubocop-rails-accessibility.rb @@ -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" diff --git a/lib/rubocop/cop/inject.rb b/lib/rubocop/cop/inject.rb deleted file mode 100644 index 77ccd2e..0000000 --- a/lib/rubocop/cop/inject.rb +++ /dev/null @@ -1,18 +0,0 @@ -# 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 RubocopRailsAccessibility - 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 diff --git a/lib/rubocop/cop/rubocop-rails-accessibility/image_has_alt.rb b/lib/rubocop/cop/rails_accessibility/image_has_alt.rb similarity index 93% rename from lib/rubocop/cop/rubocop-rails-accessibility/image_has_alt.rb rename to lib/rubocop/cop/rails_accessibility/image_has_alt.rb index 0558fd6..ca742c7 100644 --- a/lib/rubocop/cop/rubocop-rails-accessibility/image_has_alt.rb +++ b/lib/rubocop/cop/rails_accessibility/image_has_alt.rb @@ -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" diff --git a/lib/rubocop/cop/rubocop-rails-accessibility/no_positive_tabindex.rb b/lib/rubocop/cop/rails_accessibility/no_positive_tabindex.rb similarity index 95% rename from lib/rubocop/cop/rubocop-rails-accessibility/no_positive_tabindex.rb rename to lib/rubocop/cop/rails_accessibility/no_positive_tabindex.rb index b2b18c6..a00891d 100644 --- a/lib/rubocop/cop/rubocop-rails-accessibility/no_positive_tabindex.rb +++ b/lib/rubocop/cop/rails_accessibility/no_positive_tabindex.rb @@ -4,7 +4,7 @@ module RuboCop module Cop - module RubocopRailsAccessibility + module RailsAccessibility class NoPositiveTabindex < Base MSG = "Positive tabindex is error-prone and often inaccessible." diff --git a/lib/rubocop/cop/rubocop-rails-accessibility/no_redundant_image_alt.rb b/lib/rubocop/cop/rails_accessibility/no_redundant_image_alt.rb similarity index 95% rename from lib/rubocop/cop/rubocop-rails-accessibility/no_redundant_image_alt.rb rename to lib/rubocop/cop/rails_accessibility/no_redundant_image_alt.rb index 068e827..0218dfd 100644 --- a/lib/rubocop/cop/rubocop-rails-accessibility/no_redundant_image_alt.rb +++ b/lib/rubocop/cop/rails_accessibility/no_redundant_image_alt.rb @@ -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 diff --git a/lib/rubocop/cop/rubocop_rails_accessibility_cops.rb b/lib/rubocop/cop/rubocop_rails_accessibility_cops.rb deleted file mode 100644 index 12a4b24..0000000 --- a/lib/rubocop/cop/rubocop_rails_accessibility_cops.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -require "pathname" -require "yaml" - -require_relative "inject" -require_relative "version" -require_relative "rubocop-rails-accessibility/image_has_alt" -require_relative "rubocop-rails-accessibility/no_positive_tabindex" -require_relative "rubocop-rails-accessibility/no_redundant_image_alt" diff --git a/lib/rubocop/cop/version.rb b/lib/rubocop/cop/version.rb deleted file mode 100644 index 97f0e22..0000000 --- a/lib/rubocop/cop/version.rb +++ /dev/null @@ -1,5 +0,0 @@ -# frozen_string_literal: true - -module RubocopRailsAccessibility - VERSION = "0.1.2" -end diff --git a/lib/rubocop/rails_accessibility.rb b/lib/rubocop/rails_accessibility.rb new file mode 100644 index 0000000..290ab6e --- /dev/null +++ b/lib/rubocop/rails_accessibility.rb @@ -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 diff --git a/lib/rubocop/rails_accessibility/inject.rb b/lib/rubocop/rails_accessibility/inject.rb new file mode 100644 index 0000000..f49c1df --- /dev/null +++ b/lib/rubocop/rails_accessibility/inject.rb @@ -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 diff --git a/lib/rubocop/rails_accessibility/version.rb b/lib/rubocop/rails_accessibility/version.rb new file mode 100644 index 0000000..8f718d2 --- /dev/null +++ b/lib/rubocop/rails_accessibility/version.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module RuboCop + module RailsAccessibility + VERSION = "0.1.2" + end +end diff --git a/rubocop-rails-accessibility.gemspec b/rubocop-rails-accessibility.gemspec index 56ff497..a8b1545 100644 --- a/rubocop-rails-accessibility.gemspec +++ b/rubocop-rails-accessibility.gemspec @@ -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 = ["accessibility@github.com"] - 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" @@ -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 diff --git a/test/test_image_has_alt.rb b/test/test_image_has_alt.rb index d9f35d8..7e79b47 100644 --- a/test/test_image_has_alt.rb +++ b/test/test_image_has_alt.rb @@ -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 diff --git a/test/test_no_positive_tabindex.rb b/test/test_no_positive_tabindex.rb index b4736ff..cfb611b 100644 --- a/test/test_no_positive_tabindex.rb +++ b/test/test_no_positive_tabindex.rb @@ -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 diff --git a/test/test_no_redundant_image_alt.rb b/test/test_no_redundant_image_alt.rb index 5aa5661..01b5fdf 100644 --- a/test/test_no_redundant_image_alt.rb +++ b/test/test_no_redundant_image_alt.rb @@ -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
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: