Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[review] fix: ドキュメントリンク付加スクリプト #151

Merged
merged 1 commit into from
Sep 21, 2023
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
27 changes: 17 additions & 10 deletions add_doc_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 15 additions & 25 deletions rails/rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 <<next>>
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