From 1049fd9d303e8352f50e5ff151c5c352a293c44a Mon Sep 17 00:00:00 2001 From: Kate Higa Date: Mon, 22 Aug 2022 15:49:52 -0700 Subject: [PATCH 1/3] Move gem requirements to gemspec, run rubocop to autocorrect mistakes --- .gitignore | 2 +- .rubocop.yml | 8 ++-- Gemfile | 6 +-- Gemfile.lock | 21 +++++++++- Rakefile | 16 ++++---- config/default.yml | 1 - lib/rubocop/cop/inject.rb | 2 +- .../image_has_alt.rb | 6 +-- .../link_has_href.rb | 6 +-- .../no_positive_tabindex.rb | 4 +- .../no_redundant_image_alt.rb | 6 +-- .../cop/rubocop_rails_accessibility_cops.rb | 16 ++++---- lib/rubocop/cop/version.rb | 2 +- rubocop-rails-accessibility.gemspec | 41 +++++++++++-------- test/cop_test.rb | 4 +- test/test_image_has_alt.rb | 13 +++--- test/test_link_has_href.rb | 16 ++++---- test/test_no_positive_tabindex.rb | 12 +++--- test/test_no_redundant_image_alt.rb | 13 +++--- 19 files changed, 107 insertions(+), 88 deletions(-) diff --git a/.gitignore b/.gitignore index b04a8c8..4936e10 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ /pkg/ /spec/reports/ /tmp/ - +vendor/ # rspec failure tracking .rspec_status diff --git a/.rubocop.yml b/.rubocop.yml index fbbc036..5a46109 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ -AllCops: - NewCops: enable - SuggestExtensions: false - TargetRubyVersion: 2.6 +inherit_gem: + rubocop-github: + - config/default.yml + - config/rails.yml Naming/FileName: Enabled: true diff --git a/Gemfile b/Gemfile index fbfb8dc..fb446d7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,6 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in rubocop-rails-accessibility.gemspec gemspec - -gem 'rake', '~> 13.0' -gem 'rspec', '~> 3.0' -gem 'rubocop', '~> 1.21' diff --git a/Gemfile.lock b/Gemfile.lock index 64ba245..ecc1cb7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,7 @@ PATH remote: . specs: rubocop-rails-accessibility (0.1.0) - rubocop + rubocop (>= 1.0.0) GEM remote: https://rubygems.org/ @@ -31,12 +31,15 @@ GEM crass (~> 1.0.2) nokogiri (>= 1.5.9) minitest (5.16.3) + nokogiri (1.13.8-x86_64-darwin) + racc (~> 1.4) nokogiri (1.13.8-x86_64-linux) racc (~> 1.4) parallel (1.22.1) parser (3.1.2.0) ast (~> 2.4.1) racc (1.6.0) + rack (2.2.4) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) @@ -71,12 +74,24 @@ GEM unicode-display_width (>= 1.4.0, < 3.0) rubocop-ast (1.19.1) parser (>= 3.1.1.0) + rubocop-github (0.18.0) + rubocop (>= 1.0.0) + rubocop-performance + rubocop-rails + rubocop-performance (1.14.3) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + rubocop-rails (2.15.2) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.7.0, < 2.0) ruby-progressbar (1.11.0) tzinfo (2.0.5) concurrent-ruby (~> 1.0) unicode-display_width (2.2.0) PLATFORMS + x86_64-darwin-19 x86_64-linux DEPENDENCIES @@ -84,7 +99,9 @@ DEPENDENCIES minitest rake (~> 13.0) rspec (~> 3.0) - rubocop (~> 1.21) + rubocop-github + rubocop-performance + rubocop-rails rubocop-rails-accessibility! BUNDLED WITH diff --git a/Rakefile b/Rakefile index 1956e2e..10da0ea 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,22 @@ # frozen_string_literal: true -require 'bundler/gem_tasks' -require 'rake/testtask' -require 'rspec/core/rake_task' +require "bundler/gem_tasks" +require "rake/testtask" +require "rspec/core/rake_task" Rake::TestTask.new RSpec::Core::RakeTask.new(:spec) -require 'rubocop/rake_task' +require "rubocop/rake_task" RuboCop::RakeTask.new task default: %i[test rubocop] -desc 'Generate a new cop with a template' +desc "Generate a new cop with a template" task :new_cop, [:cop] do |_task, args| - require 'rubocop' + require "rubocop" cop_name = args.fetch(:cop) do warn "usage: bundle exec rake 'new_cop[Department/Name]'" @@ -27,8 +27,8 @@ task :new_cop, [:cop] do |_task, args| generator.write_source generator.write_spec - generator.inject_require(root_file_path: 'lib/rubocop-rails-accessibility.rb') - generator.inject_config(config_file_path: 'config/default.yml') + generator.inject_require(root_file_path: "lib/rubocop-rails-accessibility.rb") + generator.inject_config(config_file_path: "config/default.yml") puts generator.todo end diff --git a/config/default.yml b/config/default.yml index ba92bf2..c5cbbd3 100644 --- a/config/default.yml +++ b/config/default.yml @@ -1,6 +1,5 @@ require: - rubocop/cop/rubocop_rails_accessibility_cops - - rubocop-performance AllCops: DisabledByDefault: true diff --git a/lib/rubocop/cop/inject.rb b/lib/rubocop/cop/inject.rb index ee0f10c..77ccd2e 100644 --- a/lib/rubocop/cop/inject.rb +++ b/lib/rubocop/cop/inject.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rubocop' +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 diff --git a/lib/rubocop/cop/rubocop-rails-accessibility/image_has_alt.rb b/lib/rubocop/cop/rubocop-rails-accessibility/image_has_alt.rb index 7b987f4..0558fd6 100644 --- a/lib/rubocop/cop/rubocop-rails-accessibility/image_has_alt.rb +++ b/lib/rubocop/cop/rubocop-rails-accessibility/image_has_alt.rb @@ -1,14 +1,14 @@ # frozen_string_literal: true -require 'rubocop' +require "rubocop" module RuboCop module Cop module RubocopRailsAccessibility class ImageHasAlt < Base - MSG = 'Images should have an alt prop with meaningful text or an empty string for decorative images' + MSG = "Images should have an alt prop with meaningful text or an empty string for decorative images" - def_node_search :has_alt_attribute?, '(sym :alt)' + def_node_search :has_alt_attribute?, "(sym :alt)" def on_send(node) receiver, method_name, = *node diff --git a/lib/rubocop/cop/rubocop-rails-accessibility/link_has_href.rb b/lib/rubocop/cop/rubocop-rails-accessibility/link_has_href.rb index 3fcab22..44537d4 100644 --- a/lib/rubocop/cop/rubocop-rails-accessibility/link_has_href.rb +++ b/lib/rubocop/cop/rubocop-rails-accessibility/link_has_href.rb @@ -1,19 +1,19 @@ # frozen_string_literal: true -require 'rubocop' +require "rubocop" module RuboCop module Cop module RubocopRailsAccessibility class LinkHasHref < Base - MSG = 'Links should go somewhere, you probably want to use a `