Skip to content

[docs-utils] 4️⃣ Add param doc mismatch validation#250820

Merged
clintandrewhall merged 3 commits intoelastic:mainfrom
clintandrewhall:feat/docs-utils/4-param-mismatch
Feb 11, 2026
Merged

[docs-utils] 4️⃣ Add param doc mismatch validation#250820
clintandrewhall merged 3 commits intoelastic:mainfrom
clintandrewhall:feat/docs-utils/4-param-mismatch

Conversation

@clintandrewhall
Copy link
Copy Markdown
Contributor

@clintandrewhall clintandrewhall commented Jan 28, 2026

Summary

Adds a new paramDocMismatches validation to kbn-docs-utils that flags functions where not all parameters have JSDoc documentation. This complements the existing missingComments check, which only flags APIs that are completely undocumented.

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:

/**
 * Searches for documents matching the query.
 * @param query The search query string.   // ✅ Documented
 * @param options Search options.          // ✅ Documented
 */
export const search = (query: string, options: SearchOptions): Results => { /* ... */ };

/**
 * Fetches user data from the API.
 * @param id The user ID.                  // ✅ Documented
 */
export const getUser = (
  id: string,      // ✅ Has @param
  includeRoles: boolean,  // ❌ Missing @param!
  timeout?: number        // ❌ Missing @param!
): Promise<User> => { /* ... */ };

/** Logs a message. */  // No @param tags at all
export const log = (msg: string): void => { /* ... */ };

Before this PR:

No validation existed for partially-documented parameters. missingComments only flagged APIs with no description at all:

{
  "counts": {
    "missingComments": 0
  }
}
// getUser passes silently despite incomplete param docs!

After this PR:

Functions with incomplete parameter documentation are flagged:

{
  "counts": {
    "missingComments": 0,
    "paramDocMismatches": 1  // ✅ getUser flagged!
  },
  "paramDocMismatches": [
    {
      "id": "def-public.getUser",
      "label": "getUser",
      "type": "Function",
      "lineNumber": 8
    }
    // search NOT flagged (all params documented)
    // log NOT flagged (no params documented - all-or-nothing is OK)
  ]
}

Detection Logic

Scenario Flagged? Reason
All params have @param No Fully documented
No params have @param No Consistently undocumented (caught by missingComments if no description)
Some params have @param Yes Inconsistent - partial documentation is confusing
Zero-param function No Nothing to document

Why This Matters

Partial parameter documentation is worse than no documentation:

  • Readers assume undocumented params are intentionally omitted
  • Creates false confidence that docs are complete
  • Often indicates docs fell out of sync with code changes

Changes

  • ApiStats.paramDocMismatches: New field to track functions with incomplete parameter documentation
  • isFunctionLike(): Helper function that detects function declarations and function-typed aliases by checking for TypeKind.FunctionKind or => in the signature
  • trackParamDocMismatches(): Collects functions where some (but not all) parameters have descriptions
  • Fixture script update - Updated update_fixture_comments.js to include the new paramDocMismatches category

Impact

  • Test plugin shows 18 functions with incomplete parameter 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 incomplete parameter documentation in function declarations. The new paramDocMismatches check identifies functions where some parameters have JSDoc descriptions while others don't, encouraging consistent documentation practices.

Changes:

  • Adds paramDocMismatches field to ApiStats to track functions with incomplete parameter documentation
  • Introduces IssuesByPlugin interface to consolidate issue collections passed to collectApiStatsForPlugin
  • Implements isFunctionLike() and trackParamDocMismatches() helpers to detect and flag functions with partial parameter documentation

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/kbn-docs-utils/src/types.ts Adds paramDocMismatches to ApiStats and defines IssuesByPlugin interface
packages/kbn-docs-utils/src/stats.ts Refactors function signature to use IssuesByPlugin, implements parameter documentation validation logic
packages/kbn-docs-utils/src/stats.test.ts Adds comprehensive test coverage for the new validation including edge cases
packages/kbn-docs-utils/src/integration_tests/api_doc_suite.test.ts Updates integration tests to use refactored API
packages/kbn-docs-utils/src/integration_tests/snapshots/*.mdx Updates snapshot dates to reflect test execution time
packages/kbn-docs-utils/src/integration_tests/snapshots/plugin_a.stats.json Adds baseline data for detected parameter documentation mismatches
packages/kbn-docs-utils/src/integration_tests/fixtures/src/plugin_a/public/*.ts Documents expected validation failures in fixture comments
packages/kbn-docs-utils/src/cli/tasks/collect_stats.ts Updates to use new IssuesByPlugin interface
packages/kbn-docs-utils/src/cli/tasks/collect_stats.test.ts Initializes paramDocMismatches in mock stats
packages/kbn-docs-utils/src/test_helpers/mocks.ts Adds paramDocMismatches to mock factory functions
packages/kbn-docs-utils/src/README.md Updates documentation to reflect validation capabilities
packages/kbn-docs-utils/scripts/update_fixture_comments.js Registers new validation category for fixture comment generation

@@ -1,25 +1,26 @@
# Autogenerated API documentation
# Autogenerated API documentation.
Copy link

Copilot AI Jan 28, 2026

Choose a reason for hiding this comment

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

Corrected 'Autogenerated' to 'Auto-generated'.

Suggested change
# Autogenerated API documentation.
# Auto-generated API documentation.

Copilot uses AI. Check for mistakes.
@clintandrewhall clintandrewhall force-pushed the feat/docs-utils/4-param-mismatch branch from eb88dfd to 95845b8 Compare January 28, 2026 21:42
@clintandrewhall clintandrewhall changed the title [docs-utils] Add param doc mismatch validation [docs-utils] 4️⃣ Add param doc mismatch validation Jan 29, 2026
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 force-pushed the feat/docs-utils/4-param-mismatch branch from 95845b8 to 771d747 Compare February 10, 2026 20:24
@clintandrewhall clintandrewhall marked this pull request as ready for review February 10, 2026 20:25
@clintandrewhall clintandrewhall requested a review from a team as a code owner February 10, 2026 20:25
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@clintandrewhall clintandrewhall enabled auto-merge (squash) February 10, 2026 20:25
@clintandrewhall clintandrewhall force-pushed the feat/docs-utils/4-param-mismatch branch from 771d747 to 645da0c Compare February 10, 2026 21:01
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #133 / Fleet Multi Cluster Sync Integrations E2E "after all" hook for "should sync integrations to remote cluster when enabled on remote ES output"
  • [job] [logs] FTR Configs #133 / Fleet Multi Cluster Sync Integrations E2E should sync integrations to remote cluster when enabled on remote ES output

Metrics [docs]

✅ unchanged

History

- Add paramDocMismatches field to ApiStats.
- Add trackParamDocMismatches function.
- Update integration tests
@clintandrewhall clintandrewhall force-pushed the feat/docs-utils/4-param-mismatch branch from 645da0c to 0bea7f0 Compare February 11, 2026 00:05
@clintandrewhall clintandrewhall merged commit 070aa4b into elastic:main Feb 11, 2026
16 checks passed
@clintandrewhall clintandrewhall deleted the feat/docs-utils/4-param-mismatch branch February 11, 2026 01:36
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