Skip to content

chore: migrate @typedefjsdoc to @import #729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2025
Merged

Conversation

yashtech00
Copy link
Contributor

@yashtech00 yashtech00 commented May 3, 2025

Summary

This PR migrates the JSDoc @typedef declarations to @import syntax in:

  • worker.js
  • eslint-plugin-prettier.js

close #728


Important

Migrates JSDoc @typedef to @import syntax in worker.js and eslint-plugin-prettier.js, centralizing types in types.d.ts and fixing formatting issues.

  • Type Definitions:
    • Migrated JSDoc @typedef to @import syntax in worker.js and eslint-plugin-prettier.js.
    • Centralized type definitions in types.d.ts.
  • Formatting:
    • Fixed Prettier formatting issues in worker.js and eslint-plugin-prettier.js.

This description was created by Ellipsis for 18973d6. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Chores
    • Added Prettier plugins for JSDoc formatting and type annotations to the configuration and development dependencies.
    • Updated type annotations and imports for improved type safety and compatibility with newer ESLint APIs.
  • Style
    • Reformatted and condensed JSDoc comments for improved readability in test files.

Copy link

changeset-bot bot commented May 3, 2025

⚠️ No Changeset found

Latest commit: 6ca913e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented May 3, 2025

"""

Walkthrough

This set of changes focuses on updating type annotations and JSDoc typedef imports across several files. Type imports are migrated from multiple @typedef statements to consolidated @import statements, improving clarity and maintainability. ESLint API usages are updated to their latest property-based forms, and type assertions are made more explicit. Prettier plugins related to JSDoc formatting are added to the configuration and development dependencies. All modifications are internal, affecting type safety, code style, and formatting without altering runtime behavior or public APIs.

Changes

Files / Groups Change Summary
eslint-plugin-prettier.js Migrated typedefs from individual @typedef to grouped @import statements; updated type annotations; replaced deprecated ESLint API usages; improved internal type safety and error handling.
worker.js Switched typedef imports to use local aliases and @import statements; updated internal type definitions and JSDoc annotations.
.prettierrc, package.json Added Prettier plugin prettier-plugin-jsdoc to config plugins and devDependencies.
test/prettier.mjs Reformatted JSDoc comments for brevity and style; added JSDoc type imports; no code or logic changes.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Migrate @typedef jsdoc to @import (#728)

Poem

In the warren, code grows neat and bright,
With JSDoc imports, types take flight.
Prettier plugins hop into the mix,
ESLint's new ways, we swiftly fix.
No logic changed, just clarity won—
This rabbit’s work is finely done!

((\
( -.-)
o_(")(")
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 18973d6 in 44 seconds. Click for details.
  • Reviewed 72 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 8 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. eslint-plugin-prettier.js:9
  • Draft comment:
    Ensure './types' path is correct relative to this file. Migration looks good.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. types.d.ts:21
  • Draft comment:
    Add a trailing newline at the end of file for consistency with best practices.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. worker.js:3
  • Draft comment:
    Typedef migrations referencing './types' are consistent. Verify type definitions match expectations.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
4. eslint-plugin-prettier.js:9
  • Draft comment:
    Good refactor: centralizing typedefs by importing from './types' improves maintainability.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
5. worker.js:3
  • Draft comment:
    Typedef migration in worker.js to use './types' is clear and consistent.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
6. types.d.ts:21
  • Draft comment:
    Consider adding a trailing newline at the end of the file for consistency.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
7. types.d.ts:21
  • Draft comment:
    The file currently doesn't end with a newline. Adding a newline at the end can help maintain consistency with standard formatting practices.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 20% <= threshold 50% This comment is purely informative and does not provide a specific code suggestion or highlight a potential issue. It suggests adding a newline for consistency, which is a minor formatting preference and not a critical issue.
8. worker.js:106
  • Draft comment:
    It appears that the string literal on line 106 uses a mismatched closing character: it starts with a single quote but ends with a backtick (). Please verify if this is intentional or if it should be corrected (e.g., to 'ESLintPluginGraphQLFile' or ESLintPluginGraphQLFile`) to ensure consistency.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_BoFrPaHtPlg5RM5M

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin changed the title chore: migrate typedefs to @import in worker.js and eslint-plugin-prettier.js chore: migrate @typedefjsdoc to @import May 3, 2025
@JounQin
Copy link
Member

JounQin commented May 3, 2025

@yashtech00 Thanks for your efforts first! But that's not what I was proposing, I meant something like the following:

/**
 * @import { AST, ESLint } from 'eslint'
 */

@yashtech00
Copy link
Contributor Author

yashtech00 commented May 3, 2025

/**
 * @import { AST, ESLint } from 'eslint'
 */

so migrate @typedef jsdoc to @import, eslint-plugin-prettier.js needs to convert the file into .ts , am i right ?

@JounQin
Copy link
Member

JounQin commented May 3, 2025

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
eslint-plugin-prettier.js (1)

138-141: Consider using optional chaining for cleaner code.

The static analysis tool suggests using optional chaining here, which would make the code more concise.

-const fileInfoOptions = (options && options.fileInfoOptions) || {};
+const fileInfoOptions = options?.fileInfoOptions || {};
🧰 Tools
🪛 Biome (1.9.4)

[error] 141-141: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18973d6 and c4d301f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .prettierrc (1 hunks)
  • eslint-plugin-prettier.js (9 hunks)
  • package.json (1 hunks)
  • test/prettier.mjs (3 hunks)
  • worker.js (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • package.json
  • .prettierrc
🚧 Files skipped from review as they are similar to previous changes (1)
  • worker.js
🧰 Additional context used
🪛 Biome (1.9.4)
eslint-plugin-prettier.js

[error] 141-141: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (9)
test/prettier.mjs (1)

294-294: Added helpful reference link.

The added JSDoc comment provides a useful reference to the Svelte package.json file that defines Node.js version requirements, which helps explain the conditional logic in the next line that checks for Node.js version compatibility.

eslint-plugin-prettier.js (8)

9-12: Good migration to JSDoc @import syntax.

The migration from multiple @typedef declarations to consolidated @import statements improves code organization and follows TypeScript's recommended JSDoc approach. This aligns perfectly with the PR objective.


14-22: Well-structured type definition with proper references.

The Options type is now well-structured with explicit property types that reference the imported types. This improves code readability and type safety.


59-61: Good parameter type annotations.

Proper type annotations for function parameters improve type safety and documentation.


65-66: Helpful type annotation for range variable.

Adding explicit type annotation for the range variable enhances type safety and code clarity.


146-148: Good explicit type casting for sourceCode.

This explicit type casting handles the ESLint API compatibility layer properly while ensuring type safety.


175-180: Appropriate type annotations for better safety.

These type annotations improve code quality by making types explicit and providing better IDE support.


217-222: Improved error type definition.

The detailed error type definition with properties like codeFrame and loc improves error handling and type safety.


249-252: Explicit casting ensures type safety.

Explicit type casting for context ensures proper type checking when calling reportDifference.

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
eslint-plugin-prettier.js (1)

138-141: Consider using optional chaining

The code can be improved with optional chaining for better readability.

- const fileInfoOptions = (options && options.fileInfoOptions) || {};
+ const fileInfoOptions = options?.fileInfoOptions || {};
🧰 Tools
🪛 Biome (1.9.4)

[error] 141-141: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c4d301f and 3212c1e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .prettierrc (1 hunks)
  • eslint-plugin-prettier.js (9 hunks)
  • package.json (1 hunks)
  • test/prettier.mjs (4 hunks)
  • worker.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • package.json
  • .prettierrc
  • test/prettier.mjs
  • worker.js
🧰 Additional context used
🪛 Biome (1.9.4)
eslint-plugin-prettier.js

[error] 141-141: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (6)
eslint-plugin-prettier.js (6)

9-12: Great job migrating to @import syntax!

The migration from multiple @typedef declarations to consolidated @import statements from 'eslint', 'prettier', and 'prettier-linter-helpers' improves code organization and aligns with the PR objectives.


14-22: Good type definition improvement

Nice restructuring of the Options typedef to extend PrettierOptions with explicit property types. This multiline JSDoc format improves readability and provides better type clarity.


146-148: Good type assertion for sourceCode

The explicit type casting for sourceCode improves type safety while maintaining backward compatibility with different ESLint versions.


178-180: Good type assertion for parser

The explicit type casting for the parser with proper type definition improves type safety when accessing the parser properties.


217-222: Improved error type definition

Good enhancement of the error type definition with specific properties like codeFrame and loc. This provides better type safety when accessing these properties later in the code.


249-252: Good explicit type casting

The explicit type casting for the context parameter in the reportDifference function call ensures type safety.

@JounQin JounQin force-pushed the main branch 2 times, most recently from 6ca913e to becc77b Compare May 4, 2025 02:17
@JounQin JounQin requested a review from Copilot May 4, 2025 02:23
@JounQin JounQin added the internal Hidden internal changes label May 4, 2025
Copy link

@Copilot 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 migrates JSDoc @typedef declarations to the new @import syntax, centralizing type definitions in types.d.ts and addressing formatting issues.

  • Migrated type declarations in worker.js and eslint-plugin-prettier.js using @import.
  • Updated documentation comments in test/prettier.mjs for formatting consistency.

Reviewed Changes

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

File Description
worker.js Replaced JSDoc @typedef with @import lines and updated inline type usage.
test/prettier.mjs Reformatted JSDoc comments and adjusted inline annotations.
eslint-plugin-prettier.js Migrated type definitions to @import syntax and refined type casts.
Files not reviewed (3)
  • .prettierrc: Language not supported
  • package.json: Language not supported
  • pnpm-lock.yaml: Language not supported

@JounQin
Copy link
Member

JounQin commented May 4, 2025

@coderabbitai full review

Copy link

coderabbitai bot commented May 4, 2025

✅ Actions performed

Full review triggered.

Copy link

@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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
worker.js (2)

4-11: Ensure correct JSDoc import order for typedef.

The @typedef block references PrettierOptions and ESLint types before the corresponding @import tags. TypeScript JSDoc parsers usually expect @import declarations to appear prior to their use in @typedef. Consider moving the two @import lines above the @typedef definition or to a separate import-only JSDoc block at the top of this file. This will improve clarity and reduce the risk of unresolved types under // @ts-check.


17-19: Reorder JSDoc @import before @type.

In the second JSDoc block the @type {typeof Prettier} tag precedes the @import * as Prettier tag. For consistency and correct resolution by the TS checker, swap these lines so that the import appears first:

- * @type {typeof Prettier}
- * @import * as Prettier from 'prettier'
+ * @import * as Prettier from 'prettier'
+ * @type {typeof Prettier}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 27030dd and cb1dead.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • .prettierrc (1 hunks)
  • eslint-plugin-prettier.js (9 hunks)
  • package.json (1 hunks)
  • test/prettier.mjs (4 hunks)
  • worker.js (2 hunks)
🔇 Additional comments (19)
package.json (1)

95-95: Great addition of the JSDoc plugin for consistent formatting.

Adding the prettier-plugin-jsdoc dependency aligns with the PR's objective to improve JSDoc comment formatting in the codebase. This package will help ensure consistent formatting of JSDoc blocks.

.prettierrc (1)

6-6: Good configuration to enable the JSDoc plugin.

Adding prettier-plugin-jsdoc to the plugins array properly enables the plugin in the Prettier configuration, which is consistent with the new development dependency added in package.json.

test/prettier.mjs (5)

294-294: Properly formatted JSDoc comment.

The multi-line @see comment has been condensed into a single line, improving readability while maintaining the reference link.


387-392: Well-formatted JSDoc block.

The JSDoc comment for loadInvalidFixture function has been reformatted to be more concise and readable, without changing the meaning or content.


422-424: Improved JSDoc formatting.

The JSDoc comment for getPrettierRcJsFilename function has been reformatted to be more concise and readable.


435-438: Good type annotation with @import syntax.

The addition of proper type annotation for the eslint variable using both @type and @import syntax from ESLint correctly implements the JSDoc import pattern requested in the PR.


441-447: Correctly implemented JSDoc import for function parameter.

The type annotation for the runFixture function's parameter now uses the proper @import syntax to reference the Linter type from ESLint, which aligns with the PR's goal.

eslint-plugin-prettier.js (11)

9-12: Excellent migration from @typedef to @import syntax.

The code properly consolidates multiple individual @typedef imports into grouped @import statements importing types from 'eslint', 'prettier', and 'prettier-linter-helpers'. This implementation exactly follows the requested pattern of using JSDoc @import syntax rather than converting to TypeScript files.


14-28: Well-structured Options typedef with explicit property types.

The Options typedef has been reformatted into a clean multiline JSDoc with explicit property types referencing the imported ESLint types. The PrettierFormat typedef is also reformatted to multiline style for better readability.


53-54: Proper type annotation for prettierFormat variable.

Added a JSDoc type annotation for the lazily-loaded Prettier format function, improving type safety.


67-71: Improved type safety with explicit AST.Range type.

The range variable's type annotation was changed from an inline cast to a proper JSDoc type declaration, improving code readability and type safety.


93-94: Good type annotation for the plugin object.

Added a JSDoc type annotation for the eslintPluginPrettier object, improving type safety.


142-146: Enhanced type safety for options extraction.

The option extraction in the create method was refactored to assign context.options[1] to a typed options variable, improving clarity and type safety. The fileInfoOptions variable is also properly typed.


150-152: Updated to use modern ESLint API with fallback.

The code now properly uses the newer context.sourceCode property with fallback to the deprecated context.getSourceCode() method, and includes an explicit type assertion for better type safety.


179-185: Improved type annotations for Prettier options and parser.

Added proper type annotations for eslintPrettierOptions and parser variables, increasing type safety while maintaining the same functionality.


194-195: Added missing type annotation.

Added a type annotation for the prettierSource variable that was previously missing, improving code clarity and type safety.


221-227: Enhanced error type definition for better error handling.

The error object now has a more precise type definition that includes codeFrame and loc properties, improving type safety and making the error handling more robust.


253-257: Added proper type casting for context parameter.

The reportDifference function call now explicitly casts context to Rule.RuleContext, ensuring type safety and preventing potential type errors.

worker.js (1)

185-185: Typed prettierOptions is consistent with imported alias.

The usage of /** @type {PrettierOptions} */ for the prettierOptions constant aligns correctly with the Options as PrettierOptions alias imported from prettier. This ensures proper type checking under // @ts-check. Looks good!

@JounQin JounQin merged commit 3e30777 into prettier:main May 4, 2025
9 checks passed
JounQin added a commit that referenced this pull request May 4, 2025
Co-authored-by: JounQin <admin@1stg.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Hidden internal changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate @typedef jsdoc to @import
2 participants