Skip to content

Commit

Permalink
Include standard.rb tool
Browse files Browse the repository at this point in the history
  • Loading branch information
berniechiu committed Oct 18, 2024
1 parent 58c14c9 commit 2fc6857
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
64 changes: 35 additions & 29 deletions doc_generation/rubocop_doc/generator.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env ruby

# Plugins with patterns documentation should be added here
$plugins = ["rubocop-performance",
"rubocop-rails",
"rubocop-sorbet",
"rubocop-graphql",
"rubocop-thread_safety",
"rubocop-minitest",
"rubocop-rake",
"rubocop-rspec",
"rubocop-i18n",
"rubocop-faker",
"rubocop-factory_bot",
"rubocop-md",
"rubocop-mdsol",
"rubocop-rspec_rails",
"rubocop-capybara",
"rubocop-rubycw"
]
$plugins = %w[rubocop-performance
rubocop-rails
rubocop-sorbet
rubocop-graphql
rubocop-thread_safety
rubocop-minitest
rubocop-rake
rubocop-rspec
rubocop-i18n
rubocop-faker
rubocop-factory_bot
rubocop-md
rubocop-mdsol
rubocop-rspec_rails
rubocop-capybara
rubocop-rubycw
standard]

# frozen_string_literal: true
require 'rubocop'
Expand All @@ -39,12 +39,12 @@ def initialize(cop, config)

# Reverses what this method does: RuboCop::Config#make_excludes_absolute
def make_excludes_relative(config, base_dir)
config["Exclude"]&.map! do |exclude_elem|
config['Exclude']&.map! do |exclude_elem|
if exclude_elem.is_a?(String)
exclude_path = Pathname.new(exclude_elem)
base_dri = Pathname.new(base_dir)

if base_dri.relative?() != exclude_path.relative?()
if base_dri.relative? != exclude_path.relative?
exclude_elem
else
exclude_path.relative_path_from(base_dri).to_s
Expand Down Expand Up @@ -77,24 +77,28 @@ def configurable_attributes

def yard_object
return @yard_object if @yard_object

result = nil

YARD::Registry.all(:class).detect do |code_object|
next unless RuboCop::Cop::Badge.for(code_object.to_s) == cop.badge

result = code_object
end
@yard_object = result
end

def description
return '' unless yard_object

yard_object.docstring.to_s
end

def examples_description
return '' unless yard_object
return '' if yard_object.tags('example').empty?
result = "```ruby\n".dup

result = +"```ruby\n"
yard_object.tags('example').map do |x|
result << x.text
end
Expand All @@ -104,12 +108,12 @@ def examples_description

def as_json
{
name: name,
department_name: department_name,
description: description,
examples_description: examples_description,
configuration: configuration,
configurable_attributes: configurable_attributes,
name:,
department_name:,
description:,
examples_description:,
configuration:,
configurable_attributes:
}
end
end
Expand All @@ -122,7 +126,8 @@ def self.rubocop_source_code_path(plugin_with_version)
end

def self.run
blacklist = ["Lint/RedundantCopDisableDirective", "Sorbet/SignatureCop", "GraphQL/OrderedArguments", "GraphQL/OrderedFields"]
blacklist = ['Lint/RedundantCopDisableDirective', 'Sorbet/SignatureCop', 'GraphQL/OrderedArguments',
'GraphQL/OrderedFields']

# Each plugin has a Version, so we retrieve that to know where to look on the gem files for the Cops documentation
plugins_with_versions = $plugins.map do |plugin|
Expand All @@ -133,9 +138,9 @@ def self.run
# Add rubocop itself as a source of Cops
plugins_with_versions << "rubocop-#{RuboCop::Version::STRING}"

puts "Generating documentation based on Rubocop and plugins:"
puts 'Generating documentation based on Rubocop and plugins:'
puts plugins_with_versions
puts "^^^^ MAKE SURE THE PLUGIN YOU ADDED IS ON THE LIST ABOVE, OTHERWISE WILL NOT BE PART OF THE patterns.json"
puts '^^^^ MAKE SURE THE PLUGIN YOU ADDED IS ON THE LIST ABOVE, OTHERWISE WILL NOT BE PART OF THE patterns.json'

YARD::Rake::YardocTask.new(:yard_for_generate_documentation) do |task|
task.files = plugins_with_versions.map(&method(:rubocop_source_code_path))
Expand All @@ -149,6 +154,7 @@ def self.run
result = []
cops.each do |cop|
next if blacklist.include? cop.cop_name

result << RubocopDocs::CopDoc.new(cop, config)
end
result = result.map(&:as_json)
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/codacy/rubocop/Rubocop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ object Rubocop extends Tool {
"rubocop-md",
"rubocop-mdsol",
"rubocop-rspec_rails",
"rubocop-capybara"
"rubocop-capybara",
"standard"
)

// Gemfile is analysed
Expand Down

0 comments on commit 2fc6857

Please sign in to comment.