Skip to content

docs(guardrails): enforce JSDoc on every new or modified function#3555

Merged
PierreBrisorgueil merged 12 commits into
masterfrom
docs/enforce-jsdoc-on-functions
Feb 22, 2026
Merged

docs(guardrails): enforce JSDoc on every new or modified function#3555
PierreBrisorgueil merged 12 commits into
masterfrom
docs/enforce-jsdoc-on-functions

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Collaborator

@PierreBrisorgueil PierreBrisorgueil commented Feb 22, 2026

Summary

  • Add JSDoc rule to `CLAUDE.md` guardrails: every new or modified function must have a JSDoc header (description + `@param` + `@returns`)
  • Add JSDoc rule to `.github/copilot-instructions.md` to keep both AI instruction files in sync
  • Migrate existing `@return` → `@returns` in src/lib/helpers and src/lib/middlewares to match JSDoc standard
  • Fix `isDark` logic to handle both string and boolean theme values
  • Add entry to `ERRORS.md` to reinforce the lesson from PRs where functions were added without documentation

Why

Recent PRs introduced functions without JSDoc headers. This rule makes it an always-on constraint for all AI interactions rather than a post-hoc catch.

Scope

Docs + JSDoc migration in src/lib — no business logic change (isDark logic fix aligns implementation with documented behavior)

Summary by CodeRabbit

Release Notes

  • Documentation

    • Enhanced code documentation standards with consistent JSDoc formatting, comprehensive parameter descriptions, and improved return value documentation across all helper functions and middleware.
  • Refactor

    • Refined theme handling logic to provide more consistent and predictable behavior when processing different theme value types.
  • Tests

    • Updated test suite to validate improved theme handling behavior and ensure consistency across test cases.

Copilot AI review requested due to automatic review settings February 22, 2026 09:27
Copy link
Copy Markdown

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 a JSDoc documentation requirement to the project's AI guardrails, mandating that every new or modified function must have a JSDoc header with description, parameter documentation, and return value documentation. The change responds to recent PRs where functions were added without proper documentation.

Changes:

  • Added JSDoc requirement to CLAUDE.md guardrails section
  • Added corresponding entry to ERRORS.md for AI mistake tracking

Reviewed changes

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

File Description
CLAUDE.md Adds JSDoc requirement to "Always-on guardrails" section
ERRORS.md Records the recurring mistake of missing JSDoc headers

Comment thread CLAUDE.md Outdated
Comment thread ERRORS.md Outdated
Comment thread CLAUDE.md Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.93%. Comparing base (cc67bcb) to head (568f2b3).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3555   +/-   ##
=======================================
  Coverage   95.93%   95.93%           
=======================================
  Files          20       20           
  Lines         516      516           
  Branches      140      140           
=======================================
  Hits          495      495           
  Misses         21       21           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…rule, sync copilot-instructions

- Use @return (no trailing s) to match codebase convention (CLAUDE.md, ERRORS.md)
- Clarify when @return is required: non-void returns + always for async functions
- Add JSDoc guardrail to .github/copilot-instructions.md to keep both AI instruction files in sync
@PierreBrisorgueil
Copy link
Copy Markdown
Collaborator Author

@copilot review

Copy link
Copy Markdown

Copilot AI commented Feb 22, 2026

@PierreBrisorgueil I've opened a new pull request, #3556, to work on those changes. Once the pull request is ready, I'll request review from you.

@PierreBrisorgueil
Copy link
Copy Markdown
Collaborator Author

@copilot review

Copy link
Copy Markdown

Copilot AI commented Feb 22, 2026

@PierreBrisorgueil I've opened a new pull request, #3557, to work on those changes. Once the pull request is ready, I'll request review from you.

@PierreBrisorgueil
Copy link
Copy Markdown
Collaborator Author

@copilot review

Copy link
Copy Markdown

Copilot AI commented Feb 22, 2026

@PierreBrisorgueil I've opened a new pull request, #3558, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Copy Markdown

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

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

Comment thread ERRORS.md Outdated
Comment thread CLAUDE.md Outdated
Copy link
Copy Markdown

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

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

… and src

- Migrate @return@returns in src/lib/helpers/theme.js, tools.js, middlewares/model.js
- Update CLAUDE.md, copilot-instructions.md and ERRORS.md to use @returns
- Ensures full consistency with JSDoc standard and Node stack convention
Copy link
Copy Markdown

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

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

Comments suppressed due to low confidence (1)

src/lib/helpers/tools.js:14

  • This JSDoc @param entry is missing the parameter name (should document release), and the @returns type/value looks incorrect: the function returns an array (after split('.')/pop()), not a string like "23". Please correct the JSDoc to match the actual signature and return type.
 * @desc Function to evaluate numbers of release from last release
 * @param {String} 2.3.4
 * @returns {String} 23
 */
export const releasesNumber = (release) => {
  const numbers = release[0] === 'v' ? release.substr(1).split('.') : release.split('.'); // get numbers last release
  numbers.pop();
  numbers[0] = numbers[0] === '1' ? '1' : String(parseInt(numbers[0], 10) * 10); // calc aproximativly number of release
  return numbers;

Comment thread src/lib/helpers/theme.js
Comment thread CLAUDE.md Outdated
Comment thread .github/copilot-instructions.md Outdated
Comment thread src/lib/middlewares/model.js Outdated
Comment thread src/lib/helpers/tools.js Outdated
Comment thread src/lib/helpers/theme.js Outdated
- theme.js: add param names to isDark and style, document both args
- tools.js: fix releasesNumber param name and Array return type
- tools.js: fix serverItemsLength @returns to number
- model.js: fix description (null only) and improve @param/@returns
- CLAUDE.md, copilot-instructions.md: remove /pr row (wrong PR)
Copy link
Copy Markdown

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

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

Comment thread src/lib/helpers/tools.js Outdated
@PierreBrisorgueil
Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 22, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 22, 2026

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 2 minutes and 51 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

Adds a requirement for JSDoc headers for new/modified functions across docs; normalizes JSDoc tags and clarifies descriptions in helper and middleware files; updates tests to match adjusted isDark semantics. No exported/public API signatures were changed.

Changes

Cohort / File(s) Summary
Documentation guidelines
\.github/copilot-instructions.md, CLAUDE.md, ERRORS.md
Inserted a rule requiring every new or modified function to include a one-line JSDoc description, @param for each argument, and @returns for non-void (and async) functions; duplication noted in CLAUDE.md.
Theme helper & tests
src/lib/helpers/theme.js, src/lib/helpers/tests/theme.spec.js
Clarified isDark JSDoc (explicit 'dark' check, allowed values `'dark'
Tools helper JSDoc updates
src/lib/helpers/tools.js
Refined JSDoc for releasesNumber, pageRequest, and serverItemsLength (param/return descriptions). No implementation or signature changes.
Middleware JSDoc update
src/lib/middlewares/model.js
Updated clean JSDoc to clarify model is an array of keys and returned values exclude nulls; implementation unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped through lines of docs with cheer,

Lined up params and returns so clear.
A nibble here, a tidy there,
Now every function's got its care.
Hop, happy code—your notes appear! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main objective of the pull request: enforcing JSDoc requirements on all new or modified functions across the codebase.
Description check ✅ Passed The description covers the key changes (JSDoc rules, migration, isDark fix, ERRORS.md entry) and explains the motivation, but is missing several required template sections: Scope details, Validation checklist, Guardrails checks, and reviewer notes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/enforce-jsdoc-on-functions

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/lib/helpers/theme.js (1)

3-10: ⚠️ Potential issue | 🟡 Minor

JSDoc/behavior mismatch risk for isDark.

Line 3–5 states theme can be 'dark' | 'light' | 'auto' and returns a dark value, but the implementation (Line 10) returns true for any truthy non‑'auto' value (so 'light' becomes true). If 'light' should map to false, please adjust logic or tighten the doc to reflect current behavior.

Suggested logic fix (only if 'light' should be false)
-  return !!theme;
+  return theme === true || theme === 'dark';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/helpers/theme.js` around lines 3 - 10, The isDark function currently
treats any truthy non-'auto' theme as dark, which makes 'light' return true;
update isDark so it explicitly returns true only for theme === 'dark', returns
the prefers-color-scheme check when theme === 'auto', and returns false for
theme === 'light' or any other value (adjust the JSDoc on the top of the
function to match this behavior if needed); locate and modify the exported
function isDark in src/lib/helpers/theme.js.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/lib/helpers/theme.js`:
- Around line 3-10: The isDark function currently treats any truthy non-'auto'
theme as dark, which makes 'light' return true; update isDark so it explicitly
returns true only for theme === 'dark', returns the prefers-color-scheme check
when theme === 'auto', and returns false for theme === 'light' or any other
value (adjust the JSDoc on the top of the function to match this behavior if
needed); locate and modify the exported function isDark in
src/lib/helpers/theme.js.

Copilot AI review requested due to automatic review settings February 22, 2026 11:38
Copy link
Copy Markdown

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

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

Comment thread src/lib/helpers/theme.js
Copilot AI review requested due to automatic review settings February 22, 2026 11:42
Copy link
Copy Markdown

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

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

Comment thread CLAUDE.md
Copy link
Copy Markdown

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings February 22, 2026 12:00
@PierreBrisorgueil PierreBrisorgueil merged commit 2a67eb4 into master Feb 22, 2026
5 checks passed
Copy link
Copy Markdown

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Comment thread src/lib/helpers/theme.js
Comment on lines +3 to 6
* @param {String} theme - Theme option from config ('dark', 'light', or 'auto')
* @returns {Boolean} true if dark mode is active, false otherwise
*/
export const isDark = (theme) => {
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The JSDoc for isDark documents theme as {String}, but the config comment indicates it can also be a boolean. Once boolean handling is restored, please update the param type/description to reflect the accepted union (e.g. Boolean|String).

Suggested change
* @param {String} theme - Theme option from config ('dark', 'light', or 'auto')
* @returns {Boolean} true if dark mode is active, false otherwise
*/
export const isDark = (theme) => {
* @param {Boolean|String} theme - Theme option from config: boolean (true = dark, false = light) or string ('dark', 'light', or 'auto')
* @returns {Boolean} true if dark mode is active, false otherwise
*/
export const isDark = (theme) => {
if (typeof theme === 'boolean') {
return theme;
}

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +22
it('should return true when theme is dark', () => {
expect(isDark('dark')).toBe(true);
});

it('should return false when theme is explicitly false', () => {
expect(isDark(false)).toBe(false);
it('should return false when theme is light', () => {
expect(isDark('light')).toBe(false);
});

it('should return false when theme is undefined', () => {
it('should return false for unknown or missing theme (light by default)', () => {
expect(isDark(undefined)).toBe(false);
});

it('should return false when theme is null', () => {
expect(isDark(null)).toBe(false);
expect(isDark('')).toBe(false);
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

PR description says isDark should handle both string and boolean theme values, but the updated tests only cover string/undefined/null cases. Add boolean test cases (true/false) to prevent regressions and to reflect the documented config behavior.

Copilot uses AI. Check for mistakes.
Comment thread src/lib/helpers/tools.js
* @param {String} 2.3.4
* @return {String} 23
* @param {String} release - Version string (e.g. '2.3.4' or 'v2.3.4')
* @returns {Array} Array of version number parts
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

The releasesNumber JSDoc says it returns {Array}, but the function actually returns an array of strings (e.g. ['20','3']) and always drops the patch segment. Consider documenting this more precisely (e.g. Array<String> and mention that the result is [majorAdjusted, minor]).

Suggested change
* @returns {Array} Array of version number parts
* @returns {Array<String>} Array of version number parts as strings: [majorAdjusted, minor] (patch segment is dropped)

Copilot uses AI. Check for mistakes.
* @return {Object} result
* @desc Function to clean object (pick from model, remove null values)
* @param {Object} data - Source object to clean
* @param {Array} model - Array of keys to pick from data
Copy link

Copilot AI Feb 22, 2026

Choose a reason for hiding this comment

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

In clean, the model param is documented as {Array}, but it’s expected to be an array of field names. Consider tightening this to Array<String> (or similar) to make the contract clear and help catch misuse in editors/IDE tooling.

Suggested change
* @param {Array} model - Array of keys to pick from data
* @param {Array<string>} model - Array of keys to pick from data

Copilot uses AI. Check for mistakes.
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.

3 participants