Skip to content

Licensing comments, standardrb, and top-level module documentation #1605

@dmlary

Description

@dmlary

This issue is a confluence of multiple pieces (SPDX licensing comments & standardrb) that is resulting in yard replacing top-level module documentation with required licensing comments. I'm hoping there is some workaround to allow me to write the top-level module documentation in the top-level file.

Problem description

First off the layout of the project is something like this:

lib/my_module.rb
lib/my_module/my_class.rb
# 30+ more classes in the MyModule namespace

At the top of each file is SPDX1 licensing comment:

# SPDX-FileCopyrightText: 2025 Company Name
# SPDX-License-Identifier: MIT

The contents of the top-level file (lib/my_module.rb) is:

# SPDX-FileCopyrightText: 2025 Company Name
# SPDX-License-Identifier: MIT

require_relative "my_module/my_class"

# This is the documentation for MyModule
# @example
#    ...
module MyModule
end

All classes and modules within the gem are declared as follows so they can easily access things in the MyModule namespace.

# SPDX-FileCopyrightText: 2025 Company Name
# SPDX-License-Identifier: MIT

module MyModule
  # This is the documentation for MyClass
  # @example using MyClass
  class MyClass
  end
end

Running yard doc in that repo, the documentation for MyModule written in lib/my_module.rb is replaced with the license block from lib/my_module/my_class.rb. In reality it's replaced with an obscure file about 5 levels lower, and not the last file required.

Using the --load script described in #1173 (comment) I'm able to see that in my codebase, the top-level module documentation is being overwritten with an obscure file four directories below the top-level module source file.

Attempted work-around or standardrb gets in the way

I found in some old issue that yard will ignore higher blocks of comments if you separate them with two newlines. I tried it, and standardrb immediately deleted the two blank lines because extra blank lines are not permitted2.

Suggested solution

Is there any way to expand the ignored comment selection used for encoding: and frozen_string_literal: comments to include SPDX license comments?

Footnotes

  1. https://spdx.dev/learn/handling-license-info/

  2. https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Layout/EmptyLines

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions