Skip to content

[docs-utils] 4️⃣ Add missingReturns validation to API stats#250816

Merged
clintandrewhall merged 3 commits intoelastic:mainfrom
clintandrewhall:feat/docs-utils/4-returns
Feb 23, 2026
Merged

[docs-utils] 4️⃣ Add missingReturns validation to API stats#250816
clintandrewhall merged 3 commits intoelastic:mainfrom
clintandrewhall:feat/docs-utils/4-returns

Conversation

@clintandrewhall
Copy link
Copy Markdown
Contributor

@clintandrewhall clintandrewhall commented Jan 28, 2026

Summary

Adds a new missingReturns validation to the kbn-docs-utils API stats collection. This tracks functions that are missing @returns JSDoc documentation, helping improve API documentation quality across the codebase.

Note

This PR is a subset of #247688 for ease of review.

This PR was written with Cursor and claude-4.5-opus-high.

Important

This PR relies on #250810 and includes it as its base commit. This PR will remain draft until that PR is merged and this branch is rebased.

Before / After Example

Given these TypeScript functions:

/** Fetches user data from the API. */
export const getUser = (id: string): Promise<User> => {
  return fetchFromApi(`/users/${id}`);
};

/** Logs a message to the console. */
export const logMessage = (msg: string): void => {
  console.log(msg);
};

/**
 * Creates a new search service.
 * @returns The initialized search service.
 */
export const createSearchService = (): SearchService => {
  return new SearchService();
};

Before this PR:

No validation existed for missing @returns documentation. Functions without return documentation passed silently:

{
  "counts": {
    "missingComments": 0
  }
}

After this PR:

Functions missing @returns are now flagged separately:

{
  "counts": {
    "missingComments": 0,
    "missingReturns": 1     // ✅ getUser flagged (non-void, no @returns)
  },
  "missingReturns": [
    {
      "id": "def-public.getUser",
      "label": "getUser",
      "type": "Function",
      "lineNumber": 2
    }
    // logMessage NOT flagged (returns void - no @returns needed)
    // createSearchService NOT flagged (has @returns comment)
  ]
}

Smart Void Exclusion

Functions returning void-like types are automatically excluded since they don't need @returns documentation:

Return Type Flagged? Reason
string Yes Non-void, needs @returns
Promise<User> Yes Non-void, needs @returns
void No Void return, nothing to document
undefined No Void-like return
Promise<void> No Async void, nothing to document
Promise<undefined> No Async void-like

Changes

  • New missingReturns stat - Added to ApiStats interface to track functions without return documentation.
  • Function detection - Identifies function-like declarations via TypeKind.FunctionKind or arrow syntax (=>) in signatures.
  • Smart void exclusion - Excludes functions with void-like returns (void, undefined, Promise<void>, Promise<undefined>) since these don't require @returns documentation.
  • Fixture script update - Updated update_fixture_comments.js to include the new missingReturns category.

Impact

  • Test plugin shows 23 functions missing @returns documentation
  • Validation integrated with --check comments flag in check_package_docs

@clintandrewhall clintandrewhall added review Team:Operations Kibana-Operations Team release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting v9.4.0 labels Jan 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds validation for missing @returns JSDoc documentation in function declarations. The new missingReturns stat tracks functions that return non-void values but lack return documentation, helping maintain API documentation quality across Kibana plugins.

Changes:

  • Added missingReturns field to ApiStats interface for tracking functions without return documentation
  • Implemented detection logic to identify function-like declarations and exclude void returns from validation
  • Updated test infrastructure and fixture scripts to support the new validation category

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/kbn-docs-utils/src/types.ts Added missingReturns field to ApiStats and introduced IssuesByPlugin interface
packages/kbn-docs-utils/src/stats.ts Implemented function detection, void return checking, and return documentation tracking logic
packages/kbn-docs-utils/src/stats.test.ts Updated tests to use createEmptyIssues helper and new function signature
packages/kbn-docs-utils/src/integration_tests/snapshots/* Updated snapshot dates and added missingReturns data to test fixtures
packages/kbn-docs-utils/src/integration_tests/api_doc_suite.test.ts Updated to use new IssuesByPlugin parameter structure
packages/kbn-docs-utils/src/cli/tasks/collect_stats.ts Updated function call to use IssuesByPlugin object parameter
packages/kbn-docs-utils/src/cli/tasks/collect_stats.test.ts Added missingReturns to mock stats
packages/kbn-docs-utils/src/test_helpers/mocks.ts Added missingReturns initialization to mock helper functions
packages/kbn-docs-utils/src/README.md Reformatted documentation with improved structure and clarity
packages/kbn-docs-utils/scripts/update_fixture_comments.js Added missingReturns to categories array

@clintandrewhall clintandrewhall force-pushed the feat/docs-utils/4-returns branch from 37097ad to 2ab468b Compare January 28, 2026 21:40
@clintandrewhall clintandrewhall changed the title [docs-utils] Add missingReturns validation to API stats [docs-utils] 4️⃣ Add missingReturns validation to API stats Jan 29, 2026
@clintandrewhall clintandrewhall force-pushed the feat/docs-utils/4-returns branch from 2ab468b to 5c0467d Compare February 10, 2026 20:26
@clintandrewhall clintandrewhall marked this pull request as ready for review February 10, 2026 20:26
@clintandrewhall clintandrewhall requested a review from a team as a code owner February 10, 2026 20:26
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@clintandrewhall clintandrewhall enabled auto-merge (squash) February 10, 2026 20:26
@clintandrewhall clintandrewhall force-pushed the feat/docs-utils/4-returns branch from 8ae03a4 to f96fb99 Compare February 11, 2026 02:16
Track functions missing `@returns` documentation, excluding `void` and `Promise<void>` return types.
@clintandrewhall clintandrewhall force-pushed the feat/docs-utils/4-returns branch from f96fb99 to 076b882 Compare February 19, 2026 21:47
Copy link
Copy Markdown
Contributor

@mistic mistic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@clintandrewhall clintandrewhall merged commit 98b66f6 into elastic:main Feb 23, 2026
16 checks passed
@clintandrewhall clintandrewhall deleted the feat/docs-utils/4-returns branch February 23, 2026 23:19
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #6 / discover responsive sidebar should render buttons in data view picker correctly

Metrics [docs]

✅ unchanged

History

bhapas pushed a commit to bhapas/kibana that referenced this pull request Feb 25, 2026
qn895 pushed a commit to qn895/kibana that referenced this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes review Team:Operations Kibana-Operations Team v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants