Skip to content

docs: add jsdoc for import-type util #307

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
Apr 17, 2025

Conversation

Shinigami92
Copy link
Member

@Shinigami92 Shinigami92 commented Apr 17, 2025

As commented in #287 (comment), here are a start of some JSDocs


Important

Add JSDoc comments to functions in import-type.ts for improved documentation.

  • Documentation:
    • Add JSDoc comments to functions in import-type.ts including baseModule, isInternalRegexMatch, isAbsolute, isBuiltIn, isModule, isScoped, isRelativeToParent, isIndex, isRelativeToSibling, isExternalPath, isInternalPath, isExternalLookingName, typeTest, and importType.
    • Each JSDoc comment includes a description, parameters, return type, and examples where applicable.

This description was created by Ellipsis for 5de8cdc. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Introduced new helper functions for module name and path classification.
  • Documentation

    • Added comprehensive documentation and usage examples for all utility functions related to import type detection.

@Shinigami92 Shinigami92 added the documentation Improvements or additions to documentation label Apr 17, 2025
@Shinigami92 Shinigami92 requested a review from JounQin April 17, 2025 08:20
@Shinigami92 Shinigami92 self-assigned this Apr 17, 2025
Copy link

changeset-bot bot commented Apr 17, 2025

⚠️ No Changeset found

Latest commit: 5de8cdc

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 Apr 17, 2025

Walkthrough

This update enhances the src/utils/import-type.ts module by adding thorough JSDoc documentation to nearly all functions, clarifying their usage, parameters, return values, and providing examples. Several new helper functions are introduced, including baseModule for extracting base module names and isInternalRegexMatch for matching module names against internal patterns. Existing functions are refined with expanded documentation, and some gain minor logic clarifications. The core classification and utility functions now have detailed explanations, but no functional logic changes are made—this is a documentation and utility addition update only.

Changes

File(s) Change Summary
src/utils/import-type.ts Added comprehensive JSDoc comments to nearly all functions. Introduced new helper functions: baseModule, isInternalRegexMatch, isRelativeToParent, isIndex, isRelativeToSibling, isExternalPath, isInternalPath, isExternalLookingName. Enhanced documentation for isAbsolute, isBuiltIn, isModule, isScoped, typeTest, and importType. No core logic changes; changes are additive documentation and utility functions.

Poem

🐇
In the warren of code, new docs now bloom,
With helper functions clearing the gloom.
Each import path, with purpose explained,
No more confusion, all doubts are tamed.
Rabbits rejoice, for clarity reigns—
The code is documented, with wisdom it gains!
📚✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/utils/import-type.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)
(node:27952) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.
✨ 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.

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

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

Copy link

pkg-pr-new bot commented Apr 17, 2025

Open in StackBlitz

npm i https://pkg.pr.new/eslint-plugin-import-x@307

commit: 5de8cdc

Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.99%. Comparing base (95dd356) to head (5de8cdc).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #307   +/-   ##
=======================================
  Coverage   95.99%   95.99%           
=======================================
  Files          91       91           
  Lines        4744     4744           
  Branches     1763     1785   +22     
=======================================
  Hits         4554     4554           
  Misses        189      189           
  Partials        1        1           

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

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)
src/utils/import-type.ts (2)

290-297: Good basic documentation for typeTest

The JSDoc adequately describes the core function's purpose, parameters, and return value. Consider enhancing it with examples of different module types that could be returned.

 /**
  * Returns the type of the module.
  *
+ * Possible return types: 'internal', 'absolute', 'builtin', 'parent', 'index', 
+ * 'sibling', 'external', or 'unknown'.
  *
  * @param name The name of the module to check
  * @param context The context of the rule
  * @param path The path of the module to check
  * @returns The type of the module
  */

336-342: Clear importType documentation

The JSDoc effectively documents this exported wrapper function. For completeness, you might consider mentioning that it resolves the module path before passing it to typeTest.

 /**
  * Returns the type of the module.
+ * 
+ * This function is a wrapper around typeTest that first resolves
+ * the module path using the resolve utility.
  *
  * @param name The name of the module to check
  * @param context The context of the rule
  * @returns The type of the module
  */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 95dd356 and 5de8cdc.

📒 Files selected for processing (1)
  • src/utils/import-type.ts (8 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/utils/import-type.ts (1)
src/types.ts (2)
  • PluginSettings (113-113)
  • LiteralNodeValue (198-204)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8.56 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8.56 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8.56 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8.56 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 9 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8.56 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8.56 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 9 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 9 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8.56 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on macos-latest
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (13)
src/utils/import-type.ts (13)

9-21: Well-structured JSDoc for baseModule

The documentation is clear and includes helpful examples showing how the function handles both scoped and unscoped packages, as well as various path patterns. The return value and parameter descriptions are also well-documented.


31-39: Clear documentation for isInternalRegexMatch

The JSDoc clearly explains the function's purpose, its relationship to plugin settings, and provides appropriate parameter and return value descriptions.


45-50: Concise documentation for isAbsolute

The JSDoc is straightforward and effectively communicates the function's purpose.


55-71: Comprehensive documentation for isBuiltIn with helpful inline comment

The JSDoc thoroughly explains built-in modules, references the plugin settings, and provides examples. The added inline comment on line 77 also helps clarify the conditional logic in the implementation.

Also applies to: 77-77


114-131: Clear documentation with examples for isModule

The JSDoc effectively explains the "loose check" nature of this function and provides excellent examples of what does and doesn't qualify as a module name according to this function's criteria.


144-154: Good examples in isScoped documentation

The JSDoc includes helpful examples that clarify what qualifies as a scoped module name, which is particularly useful given the specific regex pattern being tested.


165-179: Thorough documentation for isRelativeToParent

The documentation clearly explains the function's purpose with multiple examples showing both matching and non-matching patterns.


186-199: Clear isIndex documentation with comprehensive examples

The JSDoc clearly documents all the patterns that qualify as index files, which is helpful since this relies on a Set of predefined patterns.


204-216: Good contrast examples in isRelativeToSibling documentation

The JSDoc effectively shows both matching and non-matching examples, which helps clarify the difference between sibling and parent relative paths.


221-230: Detailed explanation for isExternalPath

The documentation clearly explains what constitutes an external path and references the relevant plugin settings that affect this determination.


256-264: Concise isInternalPath documentation

The JSDoc succinctly explains what constitutes an internal path, which complements the isExternalPath documentation.


276-285: Clear examples for isExternalLookingName

The documentation effectively shows what types of module names are considered "external looking" and matches the implementation that checks for both regular and scoped modules.


9-342: Overall excellent documentation effort

This PR adds comprehensive JSDoc to almost every function in the file, significantly improving code readability and maintainability. The documentation follows a consistent style, includes clear examples where appropriate, and accurately reflects the function implementations.

🧰 Tools
🪛 Biome (1.9.4)

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

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

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.

❌ Changes requested. Reviewed everything up to 5de8cdc in 3 minutes and 0 seconds

More details
  • Looked at 254 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. src/utils/import-type.ts:120
  • Draft comment:
    Clarify 'isModule' JSDoc: The examples indicate that 'package-name' is false, but npm package names often include hyphens. Consider updating the description or examples to avoid confusion.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.
2. src/utils/import-type.ts:293
  • Draft comment:
    Consider renaming the parameter 'path' in 'typeTest' to something like 'modulePath' for clarity, as 'path' is a common module name and could be confused with the Node.js 'path' module.
  • 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.
3. src/utils/import-type.ts:341
  • Draft comment:
    The new JSDoc comments across the utility functions are very helpful. Ensure that any future changes to function logic also update the JSDoc to stay consistent.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
4. src/utils/import-type.ts:55
  • Draft comment:
    For clarity, consider noting the difference in naming between the exported function isBuiltIn and the imported isBuiltin from 'node:module' in the documentation.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None

Workflow ID: wflow_bb3ZQLZK02GpeZge


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@Shinigami92
Copy link
Member Author

@JounQin I found some functions inside import-type.ts which are not in use at all anywhere anymore, like isScopedMain.

Also I'm not sure if we could add index.ts and stuff like cjs,mjs,cts,mts and even tsx to indexFiles.

But these are stuff for another PR 😉

Copy link
Member

@JounQin JounQin left a comment

Choose a reason for hiding this comment

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

Great job!

@JounQin
Copy link
Member

JounQin commented Apr 17, 2025

Also I'm not sure if we could add index.ts and stuff like cjs,mjs,cts,mts and even tsx to indexFiles.

@Shinigami92 Those are excluded as intended, they are all needed to be imported with the extension explicitly, . won't resolve ./index.cjs nor ./index.mjs, ts/tsx can be considered though, in TypeScript context.

@JounQin JounQin merged commit bd5f67f into un-ts:master Apr 17, 2025
39 checks passed
@Shinigami92 Shinigami92 deleted the docs-add-jsdoc-for-import-type branch April 17, 2025 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants