Skip to content

docs: complete the YARD @param tags and correct six docstrings - #177

Merged
tas50 merged 1 commit into
mainfrom
docs/complete-yard-params
Aug 30, 2026
Merged

docs: complete the YARD @param tags and correct six docstrings#177
tas50 merged 1 commit into
mainfrom
docs/complete-yard-params

Conversation

@tas50

@tas50 tas50 commented Aug 30, 2026

Copy link
Copy Markdown
Member

Every method in lib/ already had a docstring and yard stats already reported 100.00%, but coverage counts docstrings, not tags. Measured over the .yardopts scope, three methods took a parameter that no @param described.

Before:

methods=119 missing_@param=3 missing_@return=0
PARAM:
Kitchen::Driver::Gce#state=
Kitchen::Driver::Gce#check_api_call
Kitchen::Driver::Gce#wait_for_status

After:

methods=119 missing_@param=0 missing_@return=0

The three

state= is generated by attr_accessor :state, so the reader and writer share one docstring. Putting a bare @param value on it documents the writer but makes YARD warn that #state has no such parameter, so the writer is documented separately with a @!method state=(value) directive placed after the accessor. yard is warning-free before and after.

check_api_call and wait_for_status take an explicit &block. They keep their @yield / @yieldreturn tags and gain a @param block so the documented signature matches the real one.

Six docstrings that contradicted the code

Reading each method against its docstring turned up six claims the code does not support:

Method Claim Reality
authorization @return [Google::Auth::Credentials] Google::Auth.get_application_default returns a Signet::OAuth2::Client subclass (ServiceAccountCredentials, UserRefreshCredentials, GCECredentials). Google::Auth::Credentials is an unrelated wrapper class, never in that return path.
metadata Hash{String => String} user_metadata only stringifies keys, so count: 3 in kitchen.yml stays an Integer. user_metadata already documented this correctly as Hash{String => Object}.
max_server_name_length raises when a disk name "leaves no room at all" raises once fewer than fallback_server_name_length (39) characters remain, so up to 39 characters of room can still exist.
validate! enumerates its raise conditions omits email, which raises under the WinRM transport.
normalize_disks enumerates its raise conditions omits the two it propagates from assign_boot_disk ("No disks specified", "no disk is eligible to become one"). assign_boot_disk's own docstring lists all three.
create mutates :server_name, :hostname, :zone also writes :created_disks (via create_instance_objectcreate_diskscreated_disk_names) and :password for Windows guests. destroy's docstring already named :created_disks.

Prose that was already accurate is left alone.

Not changed

The YARD rake tasks (yard, yard:stats, yard:server) and .yardopts already existed; both tasks were run and are untouched.

One nit found and deliberately left, because it is a behaviour change and this PR is comments-only: normalize_disks raises "Disk name invalid. Must match #{DISK_NAME_REGEX}.", interpolating the Regexp object so the message reads (?-mix:...). The instance-name path at check_server_name uses RESOURCE_NAME_REGEX.source and reads cleanly. Worth a separate fix: PR.

Verification

  • bundle exec rake test — 344 examples, 0 failures (unchanged; comments only)
  • bundle exec cookstyle --chefstyle — 18 files inspected, no offenses detected (Cookstyle 9.0.0, RuboCop 1.90.0)
  • bundle exec yard — no warnings
  • bundle exec yard stats — 100.00% documented

The diff touches only comment lines; git diff -U0 -- lib/ filtered to non-comment lines is empty.

Merge order

No conflict with the open PRs. #176 touches spec/ only, #174 adds integration files, and #175 (README) is already merged into main. This is the sole change to lib/kitchen/driver/gce.rb, so it can merge in any order relative to those.

Every method already carried a docstring, but three took a parameter that
no @PARAM tag described:

  Kitchen::Driver::Gce#state=
  Kitchen::Driver::Gce#check_api_call
  Kitchen::Driver::Gce#wait_for_status

`state=` is generated by `attr_accessor :state`, so the reader and the
writer share one docstring and a bare `@param value` on it made YARD warn
that `#state` has no such parameter. A `@!method state=(value)` directive
placed after the accessor documents the writer on its own instead.

The other two take an explicit `&block`; they keep their `@yield` tags and
gain a `@param block` so the documented signature matches the real one.

While reading each method against its docstring, six doc claims turned out
to contradict the code:

  * `authorization` documented `@return [Google::Auth::Credentials]`, but
    `Google::Auth.get_application_default` returns a `Signet::OAuth2::Client`
    subclass; `Google::Auth::Credentials` is an unrelated wrapper class that
    is never in that return path.
  * `metadata` documented `Hash{String => String}`, but `user_metadata` only
    stringifies keys, so a `kitchen.yml` value such as `count: 3` reaches it
    as an Integer. `user_metadata` already documented this correctly.
  * `max_server_name_length` said it raises when a disk name "leaves no room
    at all"; it actually raises once fewer than `fallback_server_name_length`
    characters remain.
  * `validate!` did not list the `email` setting among its raise conditions.
  * `normalize_disks` did not list the two raises it propagates from
    `assign_boot_disk`.
  * `create` named three state keys it mutates but also writes
    `:created_disks` and, for Windows guests, `:password`.

Comments only; no code changed.

Signed-off-by: Tim Smith <tim@mondoo.com>
@tas50
tas50 merged commit 6778948 into main Aug 30, 2026
8 checks passed
@tas50
tas50 deleted the docs/complete-yard-params branch August 30, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant