Skip to content

feat: throw error on malformed tsconfig reference #423

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 3 commits into from
Mar 29, 2025
Merged

Conversation

JounQin
Copy link
Collaborator

@JounQin JounQin commented Mar 29, 2025

close #415

Summary by CodeRabbit

  • New Features
    • Improved error handling now reports clear errors when an invalid TypeScript configuration is detected.
  • Tests
    • Expanded test coverage to verify that malformed TypeScript configuration references trigger the appropriate error responses.
  • Chores
    • Updated size limit for the file located at ./lib/index.js from "1.4kB" to "1.5kB".

@JounQin JounQin requested review from SukkaW and Copilot March 29, 2025 15:55
Copy link

changeset-bot bot commented Mar 29, 2025

🦋 Changeset detected

Latest commit: 03c97f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-import-resolver-typescript Minor

Not sure what this means? Click here to learn what changesets are.

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

Copy link

coderabbitai bot commented Mar 29, 2025

Walkthrough

This change introduces a new error handling feature for the package "eslint-import-resolver-typescript". A new regular expression constant (TSCONFIG_NOT_FOUND_REGEXP) is added to detect malformed tsconfig references. The resolver function now checks errors against this constant, throwing an error when a match is found. A new changeset entry documents the version bump and error handling update. Additionally, test files have been modified to cover this new behavior, including a new tsconfig.json with a non-existent reference and an updated unit test.

Changes

File(s) Change Summary
.changeset/wise-singers-own.md Added changeset record with a minor version bump and noted the new error throwing feature for malformed tsconfig references.
src/constants.ts Added new constant TSCONFIG_NOT_FOUND_REGEXP with a regex matching "Tsconfig not found\b".
src/index.ts Imported TSCONFIG_NOT_FOUND_REGEXP and updated unrsResolve to throw an error if the result error matches the regex.
tests/unit/malformed-reference/tsconfig.json, tests/unit/unit.spec.ts Introduced a new tsconfig file simulating a malformed reference and updated test cases to verify the resolver throws an error for this scenario.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant R as unrsResolve()
    participant C as TSCONFIG_NOT_FOUND_REGEXP
    participant E as Error Handler

    U->>R: Call resolver function
    R->>R: Execute resolving logic
    R->>R: Check if result.error matches C
    alt Error matches malformed tsconfig
        R->>E: Throw new error with message
        E-->>U: Return error response
    else Error does not match
        R-->>U: Return normal result
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Throw error for a missing/malformed tsconfig reference (#415)

Poem

Hi there, I'm a rabbit, leaping through the code,
Hopping on new tests, where errors are now bestowed.
A regex guard stands firm, catching tsconfig's slight flaw,
Ensuring every reference is found without a draw.
With code so crisp and tests so tight, I cheer with all my might! 🐰


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 259c061 and 03c97f3.

📒 Files selected for processing (1)
  • .size-limit.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .size-limit.json
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 on windows-latest

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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

@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 introduces error handling for malformed tsconfig references by throwing an error when a tsconfig file isn’t found. The key changes include:

  • Updating tests to include a new test case for a malformed tsconfig reference.
  • Enhancing the resolver in src/index.ts to throw an error when the tsconfig is not found.
  • Adding a new constant (TSCONFIG_NOT_FOUND_REGEXP) to define the expected error pattern.

Reviewed Changes

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

File Description
tests/unit/unit.spec.ts Adds tests for pnp functionality and malformed tsconfig handling.
src/index.ts Checks error messages and throws an error when the tsconfig is missing.
src/constants.ts Introduces a new regexp constant for matching tsconfig not found errors.
Files not reviewed (1)
  • tests/unit/malformed-reference/tsconfig.json: Language not supported
Comments suppressed due to low confidence (1)

src/index.ts:54

  • Rethrowing the error with a new Error(result.error) may lose context from the original error. Consider preserving the original error by using the Error's cause property (e.g., new Error(result.error, { cause: result.error })) if supported.
if (TSCONFIG_NOT_FOUND_REGEXP.test(result.error)) {

Copy link

codesandbox-ci bot commented Mar 29, 2025

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

pkg-pr-new bot commented Mar 29, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eslint-import-resolver-typescript@423

commit: 03c97f3

Copy link
Contributor

github-actions bot commented Mar 29, 2025

size-limit report 📦

Path Size
lib/index.js 1.41 KB (+3.75% 🔺)

Copy link

codecov bot commented Mar 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.58%. Comparing base (ffb8ddf) to head (03c97f3).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #423      +/-   ##
==========================================
+ Coverage   57.41%   63.58%   +6.16%     
==========================================
  Files           6        6              
  Lines         364      368       +4     
  Branches       29       48      +19     
==========================================
+ Hits          209      234      +25     
+ Misses        155      134      -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.

@JounQin JounQin enabled auto-merge (squash) March 29, 2025 17:04
@JounQin JounQin merged commit 2fcb947 into master Mar 29, 2025
39 of 40 checks passed
@JounQin JounQin deleted the feat/resolve_error branch March 29, 2025 17:13
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Mar 29, 2025
| datasource | package                           | from  | to    |
| ---------- | --------------------------------- | ----- | ----- |
| npm        | eslint-import-resolver-typescript | 4.2.2 | 4.3.1 |


## [v4.3.1](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#431)

##### Patch Changes

-   [#425](import-js/eslint-import-resolver-typescript#425) [`2ced0ba`](import-js/eslint-import-resolver-typescript@2ced0ba) Thanks [@JounQin](https://github.com/JounQin)! - chore: bump `unrs-resolver` to v1.3.3


## [v4.3.0](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#430)

##### Minor Changes

-   [#423](import-js/eslint-import-resolver-typescript#423) [`2fcb947`](import-js/eslint-import-resolver-typescript@2fcb947) Thanks [@JounQin](https://github.com/JounQin)! - feat: throw error on malformed `tsconfig` reference


## [v4.2.7](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#427)

##### Patch Changes

-   [`aeb558f`](import-js/eslint-import-resolver-typescript@aeb558f) Thanks [@JounQin](https://github.com/JounQin)! - fix: add missing `index.d.cts` file


## [v4.2.6](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#426)

##### Patch Changes

-   [#417](import-js/eslint-import-resolver-typescript#417) [`c3f678b`](import-js/eslint-import-resolver-typescript@c3f678b) Thanks [@JounQin](https://github.com/JounQin)! - fix: `require` entry types, add `module-sync` entry


## [v4.2.5](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#425)

##### Patch Changes

-   [#410](import-js/eslint-import-resolver-typescript#410) [`ec59d22`](import-js/eslint-import-resolver-typescript@ec59d22) Thanks [@JounQin](https://github.com/JounQin)! - fix: absolute path aliasing should not be skipped


## [v4.2.4](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#424)

##### Patch Changes

-   [#407](import-js/eslint-import-resolver-typescript#407) [`6b183ff`](import-js/eslint-import-resolver-typescript@6b183ff) Thanks [@JounQin](https://github.com/JounQin)! - chore: migrate to rebranding `unrs-resolver` with new targets supported:

    -   `i686-pc-windows-msvc`
    -   `armv7-unknown-linux-musleabihf`
    -   `powerpc64le-unknown-linux-gnu`
    -   `s390x-unknown-linux-gnu`


## [v4.2.3](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#423)

##### Patch Changes

-   [#402](import-js/eslint-import-resolver-typescript#402) [`f21bf15`](import-js/eslint-import-resolver-typescript@f21bf15) Thanks [@SunsetTechuila](https://github.com/SunsetTechuila)! - fix: don't resolve not implemented node modules in `bun`

    `is-bun-module` is marked as `dependency`, again, for correctness, see [`isBunImplementedNodeModule`](https://github.com/SunsetTechuila/is-bun-module#isbunimplementednodemodulemodulename-bunversion) for more details

    For `Bun` users: you don't need to install `is-bun-module` any more but `bun: true` option is still required if you're running without `bun --bun` nor [`run#bun`](https://bun.sh/docs/runtime/bunfig#run-bun-auto-alias-node-to-bun) enabled
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Mar 29, 2025
| datasource | package                           | from  | to    |
| ---------- | --------------------------------- | ----- | ----- |
| npm        | eslint-import-resolver-typescript | 4.2.2 | 4.3.1 |


## [v4.3.1](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#431)

##### Patch Changes

-   [#425](import-js/eslint-import-resolver-typescript#425) [`2ced0ba`](import-js/eslint-import-resolver-typescript@2ced0ba) Thanks [@JounQin](https://github.com/JounQin)! - chore: bump `unrs-resolver` to v1.3.3


## [v4.3.0](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#430)

##### Minor Changes

-   [#423](import-js/eslint-import-resolver-typescript#423) [`2fcb947`](import-js/eslint-import-resolver-typescript@2fcb947) Thanks [@JounQin](https://github.com/JounQin)! - feat: throw error on malformed `tsconfig` reference


## [v4.2.7](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#427)

##### Patch Changes

-   [`aeb558f`](import-js/eslint-import-resolver-typescript@aeb558f) Thanks [@JounQin](https://github.com/JounQin)! - fix: add missing `index.d.cts` file


## [v4.2.6](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#426)

##### Patch Changes

-   [#417](import-js/eslint-import-resolver-typescript#417) [`c3f678b`](import-js/eslint-import-resolver-typescript@c3f678b) Thanks [@JounQin](https://github.com/JounQin)! - fix: `require` entry types, add `module-sync` entry


## [v4.2.5](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#425)

##### Patch Changes

-   [#410](import-js/eslint-import-resolver-typescript#410) [`ec59d22`](import-js/eslint-import-resolver-typescript@ec59d22) Thanks [@JounQin](https://github.com/JounQin)! - fix: absolute path aliasing should not be skipped


## [v4.2.4](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#424)

##### Patch Changes

-   [#407](import-js/eslint-import-resolver-typescript#407) [`6b183ff`](import-js/eslint-import-resolver-typescript@6b183ff) Thanks [@JounQin](https://github.com/JounQin)! - chore: migrate to rebranding `unrs-resolver` with new targets supported:

    -   `i686-pc-windows-msvc`
    -   `armv7-unknown-linux-musleabihf`
    -   `powerpc64le-unknown-linux-gnu`
    -   `s390x-unknown-linux-gnu`


## [v4.2.3](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#423)

##### Patch Changes

-   [#402](import-js/eslint-import-resolver-typescript#402) [`f21bf15`](import-js/eslint-import-resolver-typescript@f21bf15) Thanks [@SunsetTechuila](https://github.com/SunsetTechuila)! - fix: don't resolve not implemented node modules in `bun`

    `is-bun-module` is marked as `dependency`, again, for correctness, see [`isBunImplementedNodeModule`](https://github.com/SunsetTechuila/is-bun-module#isbunimplementednodemodulemodulename-bunversion) for more details

    For `Bun` users: you don't need to install `is-bun-module` any more but `bun: true` option is still required if you're running without `bun --bun` nor [`run#bun`](https://bun.sh/docs/runtime/bunfig#run-bun-auto-alias-node-to-bun) enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Unable to resolve path to module if name of tsconfig.my-reference.json is misspelled
2 participants