Skip to content

Commit

Permalink
Autocorrect linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Aug 15, 2023
1 parent b85740f commit da0fe27
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions yard/extensions.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

TOP_LEVEL_MODULE_FILE = 'lib/ddtrace.rb'
TOP_LEVEL_MODULE_FILE = "lib/ddtrace.rb"

# The top-level `Datadog` module gets its docstring overwritten by
# on almost every file in the repo, due to comments at the top of the file
Expand All @@ -14,7 +14,7 @@
# and directives in the first lines of a file.
module EnsureTopLevelModuleCommentConsistency
def register_docstring(object, *args)
if object.is_a?(YARD::CodeObjects::ModuleObject) && object.path == 'Datadog' && parser.file != TOP_LEVEL_MODULE_FILE
if object.is_a?(YARD::CodeObjects::ModuleObject) && object.path == "Datadog" && parser.file != TOP_LEVEL_MODULE_FILE
super(object, nil)
else
super
Expand All @@ -35,19 +35,19 @@ def register_docstring(object, *args)
case obj
when YARD::CodeObjects::ModuleObject, YARD::CodeObjects::ClassObject
# Mark modules and classes as private if they are not tagged with @public_api
unless obj.has_tag?('public_api')
unless obj.has_tag?("public_api")
obj.visibility = :private
next
end
else
# Do not change visibility of individual objects.
# We'll handle their visibility in their encompassing modules and classes instead.

if obj.has_tag?('public_api')
if obj.has_tag?("public_api")
log.warn(
"The @public_api tag should be added to modules and classes only: #{obj.files.join(':')}.\n" \
'Please move the tag to the encompassing module or class. ' \
'You can hide non-public methods, attributes, and constants with the `@!visibility private` directive.'
"The @public_api tag should be added to modules and classes only: #{obj.files.join(":")}.\n" \
"Please move the tag to the encompassing module or class. " \
"You can hide non-public methods, attributes, and constants with the `@!visibility private` directive."
)
end

Expand All @@ -71,8 +71,8 @@ def register_docstring(object, *args)
docstring = obj.docstring
next if docstring.empty?

docstring.replace(docstring.all.gsub(/^[A-Z]+: .*/, '')) # Removes TODO:, DEV:
docstring.replace(docstring.all.gsub(/^rubocop:.*/, '')) # Removes rubocop:...
docstring.replace(docstring.all.gsub(/^[A-Z]+: .*/, "")) # Removes TODO:, DEV:
docstring.replace(docstring.all.gsub(/^rubocop:.*/, "")) # Removes rubocop:...
end
end

Expand All @@ -94,33 +94,33 @@ class DatadogConfigurationSettingsHandler < YARD::Handlers::Ruby::Base
parent_module = namespace
else
# If not, create a DSL module to host generated classes
parent_module = YARD::CodeObjects::ModuleObject.new(namespace, 'DSL')
parent_module = YARD::CodeObjects::ModuleObject.new(namespace, "DSL")

register(parent_module)

parent_module.docstring = 'Namespace for dynamically generated configuration classes.'
parent_module.docstring = "Namespace for dynamically generated configuration classes."
end

# The generated class inherits the docstring from the current statement.
generated_class = YARD::CodeObjects::ClassObject.new(parent_module, camelize(name))

register(generated_class)

generated_class.add_tag(YARD::Tags::Tag.new(:dsl, 'dsl'))
generated_class.add_tag(YARD::Tags::Tag.new(:dsl, "dsl"))

# Remove @public_api tag from this statement, as `setting :option` is a method call
# and @public_api tags should only exists in modules and classes.
# The encompassing DSL modules and classes will inherit this tag, this only
# applies to the accessor method.
new_docstring = statement.docstring.to_s.sub(/^\s*@public_api\b.*/, '')
new_docstring = statement.docstring.to_s.sub(/^\s*@public_api\b.*/, "")

statement.docstring = <<~YARD
#{new_docstring}
@return [#{generated_class.path}] a configuration object
YARD

statement.block.last.each do |node|
parse_block(node, :namespace => generated_class)
parse_block(node, namespace: generated_class)
end
end
end
Expand Down Expand Up @@ -153,5 +153,5 @@ class DatadogConfigurationOptionHandler < YARD::Handlers::Ruby::Base
end

def camelize(str)
str.split('_').collect(&:capitalize).join
str.split("_").collect(&:capitalize).join
end

0 comments on commit da0fe27

Please sign in to comment.