From 7a4a6f1098d12874b5c810ad5debaab731933082 Mon Sep 17 00:00:00 2001 From: Shunichi Ikegami Date: Thu, 21 Sep 2023 11:45:08 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=83=AA=E3=83=B3=E3=82=AF=E4=BB=98=E5=8A=A0?= =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- add_doc_links.rb | 27 +++++++++++++++++---------- rails/rubocop.yml | 40 +++++++++++++++------------------------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/add_doc_links.rb b/add_doc_links.rb index 78d649a..09be8dc 100644 --- a/add_doc_links.rb +++ b/add_doc_links.rb @@ -2,29 +2,36 @@ require 'fileutils' +TOP_CATEGORY_MAP = { + 'Rails' => 'rails', + 'RSpec' => 'rspec', + 'Performance' => 'performance', + 'Capybara' => 'capybara', + 'FactoryBot' => 'factory_bot' +} +DOC_COMMENT_REGEXP = %r{\A# https://docs\.rubocop\.org/} + def add_doc_link_comments(filename) - prev_line = nil tmp_filename = filename + ".tmp" File.open(tmp_filename, 'w') do |io| IO.foreach(filename) do |line| - if (m = %r{^(.+/.+):}.match(line)) + if DOC_COMMENT_REGEXP.match?(line) + next + elsif (m = %r{^(.+/.+):}.match(line)) words = m[1].split('/') - top_category = words[0].downcase + top_category = words[0] category = words[0..-2].join('_').downcase name = words.join('').downcase + top_category_path_name = TOP_CATEGORY_MAP[top_category] comment = - case top_category - when 'rails', 'rspec', 'performance' - "# https://docs.rubocop.org/rubocop-#{top_category}/cops_#{category}.html##{name}" + if top_category_path_name + "# https://docs.rubocop.org/rubocop-#{top_category_path_name}/cops_#{category}.html##{name}" else "# https://docs.rubocop.org/rubocop/cops_#{category}.html##{name}" end - if prev_line.nil? || prev_line.chomp != comment - io.puts(comment) - end + io.puts(comment) end io.write(line) - prev_line = line end end FileUtils.mv(tmp_filename, filename) diff --git a/rails/rubocop.yml b/rails/rubocop.yml index c2e257a..ffd335e 100644 --- a/rails/rubocop.yml +++ b/rails/rubocop.yml @@ -145,8 +145,6 @@ RSpec: - assert_no_enqueued_jobs # backgroundとかであるクラスの全インスタンスをstubしてるなど意図してやると思うので -# https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecanyinstance - # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecanyinstance RSpec/AnyInstance: Enabled: false @@ -457,8 +455,7 @@ RSpec/BeEq: # new in 2.9.0 RSpec/BeNil: # new in 2.9.0 Enabled: true # NOTE: あえて付ける派も見かけるので -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_factorybot.html#rspecfactorybotsyntaxmethods -# https://docs.rubocop.org/rubocop/cops_factorybot.html#factorybotsyntaxmethods +# https://docs.rubocop.org/rubocop-factory_bot/cops_factorybot.html#factorybotsyntaxmethods FactoryBot/SyntaxMethods: # new in 2.7 Enabled: false # https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancestringidentifierargument @@ -470,8 +467,7 @@ RSpec/VerifiedDoubleReference: # new in 2.10.0 # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecchangebyzero RSpec/ChangeByZero: # new in 2.11.0 Enabled: true -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_capybara.html#rspeccapybaraspecificmatcher -# https://docs.rubocop.org/rubocop/cops_capybara.html#capybaraspecificmatcher +# https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaraspecificmatcher Capybara/SpecificMatcher: # new in 2.12 Enabled: true # https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html#rspecrailshavehttpstatus @@ -483,23 +479,19 @@ RSpec/ClassCheck: # new in 2.13 # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecnoexpectationexample RSpec/NoExpectationExample: # new in 2.13 Enabled: true -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_capybara.html#rspeccapybaraspecificfinders -# https://docs.rubocop.org/rubocop/cops_capybara.html#capybaraspecificfinders +# https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaraspecificfinders Capybara/SpecificFinders: # new in 2.13 Enabled: true # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecsortmetadata RSpec/SortMetadata: # new in 2.14 Enabled: true -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_capybara.html#rspeccapybaranegationmatcher -# https://docs.rubocop.org/rubocop/cops_capybara.html#capybaranegationmatcher +# https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaranegationmatcher Capybara/NegationMatcher: # new in 2.14 Enabled: false -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_capybara.html#rspeccapybaraspecificactions -# https://docs.rubocop.org/rubocop/cops_capybara.html#capybaraspecificactions +# https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaraspecificactions Capybara/SpecificActions: # new in 2.14 Enabled: true -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_factorybot.html#rspecfactorybotconsistentparenthesesstyle -# https://docs.rubocop.org/rubocop/cops_factorybot.html#factorybotconsistentparenthesesstyle +# https://docs.rubocop.org/rubocop-factory_bot/cops_factorybot.html#factorybotconsistentparenthesesstyle FactoryBot/ConsistentParenthesesStyle: # new in 2.14 Enabled: false # https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html#rspecrailsinferredspectype @@ -511,12 +503,10 @@ RSpec/DuplicatedMetadata: # new in 2.16 # https://docs.rubocop.org/rubocop-rspec/cops_rspec.html#rspecpendingwithoutreason RSpec/PendingWithoutReason: # new in 2.16 Enabled: true -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_factorybot.html#rspecfactorybotfactorynamestyle -# https://docs.rubocop.org/rubocop/cops_factorybot.html#factorybotfactorynamestyle +# https://docs.rubocop.org/rubocop-factory_bot/cops_factorybot.html#factorybotfactorynamestyle FactoryBot/FactoryNameStyle: # new in 2.16 Enabled: true -# https://docs.rubocop.org/rubocop-rspec/cops_rspec_capybara.html#rspeccapybaramatchstyle -# https://docs.rubocop.org/rubocop/cops_capybara.html#capybaramatchstyle +# https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaramatchstyle Capybara/MatchStyle: # new in 2.17 Enabled: true # https://docs.rubocop.org/rubocop-rspec/cops_rspec_rails.html#rspecrailsminitestassertions @@ -565,25 +555,25 @@ RSpec/SpecFilePathFormat: # new in 2.24 RSpec/SpecFilePathSuffix: # new in 2.24 Enabled: true -# https://docs.rubocop.org/rubocop/cops_factorybot.html#factorybotassociationstyle +# https://docs.rubocop.org/rubocop-factory_bot/cops_factorybot.html#factorybotassociationstyle FactoryBot/AssociationStyle: # new in 2.23 Enabled: true -# https://docs.rubocop.org/rubocop/cops_factorybot.html#factorybotfactoryassociationwithstrategy +# https://docs.rubocop.org/rubocop-factory_bot/cops_factorybot.html#factorybotfactoryassociationwithstrategy FactoryBot/FactoryAssociationWithStrategy: # new in 2.23 Enabled: true -# https://docs.rubocop.org/rubocop/cops_factorybot.html#factorybotredundantfactoryoption +# https://docs.rubocop.org/rubocop-factory_bot/cops_factorybot.html#factorybotredundantfactoryoption FactoryBot/RedundantFactoryOption: # new in 2.23 Enabled: true -# https://docs.rubocop.org/rubocop/cops_factorybot.html#factorybotidsequence +# https://docs.rubocop.org/rubocop-factory_bot/cops_factorybot.html#factorybotidsequence FactoryBot/IdSequence: # new in <> Enabled: true -# https://docs.rubocop.org/rubocop/cops_capybara.html#capybaraclicklinkorbuttonstyle +# https://docs.rubocop.org/rubocop-capybara/cops_capybara.html#capybaraclicklinkorbuttonstyle Capybara/ClickLinkOrButtonStyle: # new in 2.19 Enabled: false -# https://docs.rubocop.org/rubocop/cops_capybara_rspec.html#capybararspechaveselector +# https://docs.rubocop.org/rubocop-capybara/cops_capybara_rspec.html#capybararspechaveselector Capybara/RSpec/HaveSelector: # new in 2.19 Enabled: false -# https://docs.rubocop.org/rubocop/cops_capybara_rspec.html#capybararspecpredicatematcher +# https://docs.rubocop.org/rubocop-capybara/cops_capybara_rspec.html#capybararspecpredicatematcher Capybara/RSpec/PredicateMatcher: # new in 2.19 Enabled: true