-
-
Notifications
You must be signed in to change notification settings - Fork 70
feat: integrate eslint-import-context
to get correct context.cwd
#453
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
Conversation
🦋 Changeset detectedLatest commit: 2b346d7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
WalkthroughThis update refactors type declaration paths in package.json, removes the index.d.cts file, introduces new build and clean scripts, and upgrades several dependencies. The src/index.ts module now supports context-aware resolution by dynamically updating the working directory and resolver based on the rule context. The CI workflow updates the Codecov action version. Several TypeScript configuration files were added, simplified, or deleted to consolidate project settings. Changes
Sequence Diagram(s)sequenceDiagram
participant ESLintRuleContext
participant src/index.ts
participant ResolverFactory
ESLintRuleContext->>src/index.ts: Call resolve(source, file, options, resolver)
src/index.ts->>src/index.ts: Extract cwd from useRuleContext() or process.cwd()
src/index.ts->>ResolverFactory: If cwd changed, clone resolver with new options
src/index.ts->>ResolverFactory: Resolve import with current cwd and options
ResolverFactory-->>src/index.ts: Return ResolvedResult
src/index.ts-->>ESLintRuleContext: Return ResolvedResult
Possibly related PRs
Suggested reviewers
Poem
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
yarn install v1.22.22 ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 integrates the eslint-import-context package to correctly derive the current working directory (cwd) for import resolution and updates several dependency versions.
- Updates the drag-and-drop dependency in tests.
- Refactors how the resolver obtains the cwd by using useRuleContext.
- Upgrades various dependencies and adjusts package exports and build scripts.
Reviewed Changes
Copilot reviewed 85 out of 85 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
tests/unit/pnp/package.json | Bumps @atlaskit/pragmatic-drag-and-drop version for testing. |
src/index.ts | Integrates useRuleContext and updates caching logic to correctly incorporate cwd. |
package.json | Updates exports, dependency versions, and adjusts the types entry to reflect new file naming. |
index.d.cts | Removes obsolete type declaration file. |
.github/workflows/ci.yml | Upgrades the Codecov action version. |
Comments suppressed due to low confidence (3)
index.d.cts:1
- The removal of 'index.d.cts' suggests a change in how type declarations are handled. Please confirm that this removal does not adversely affect consumers who might depend on this file for type resolution.
import * as eslintImportResolverTypeScript from './lib/index.js'
src/index.ts:88
- Using '\0' as a separator in the cache key improves uniqueness; please verify that this separator behaves as expected in all target environments to avoid unexpected issues.
const cacheKey = `${optionsHash}\0${cwd}`
package.json:18
- The types entry has been updated from 'lib/index.d.ts' to 'lib/index.d.cts'. Ensure that this change aligns with the intended module output and that consumers are informed of the new type declaration file naming convention.
"types": "lib/index.d.cts",
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. |
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Changes requested ❌
Reviewed everything up to 61d2c19 in 1 minute and 54 seconds. Click for details.
- Reviewed
196
lines of code in5
files - Skipped
80
files when reviewing. - Skipped posting
4
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. package.json:18
- Draft comment:
Inconsistent types configuration: the package-level "types" field is set to "lib/index.d.cts" while the exports under the "import" key still refer to "./lib/index.d.ts". Consider aligning these to avoid confusion for TS consumers. - 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.
2. src/index.ts:216
- Draft comment:
In createTypeScriptImportResolver, when the context’s cwd differs from the stored value, the resolver is cloned via cloneWithOptions. If the resolver is undefined (e.g. when options.project is provided), ensure this fallback is intentional and consider documenting the behavior. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
3. tests/unit/pnp/package.json:6
- Draft comment:
The dependency '@atlaskit/pragmatic-drag-and-drop' has been updated to ^1.7.0. Please verify that this version change does not introduce breaking changes in the test suite. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
4. package.json:18
- Draft comment:
I noticed that the "types" field now points to "lib/index.d.cts". Typically, type declaration files use the ".d.ts" extension. Was this intentional, or is it a typographical error? - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 0% vs. threshold = 50% The comment questions something that is actually correct and intentional. The package.json shows a dual package setup with both CJS and ESM support. The .d.cts extension is specifically for CommonJS type declarations, while .d.ts is used for ESM, as shown in the exports field. This is a modern, correct pattern. I might be missing some TypeScript-specific best practices or requirements that would make .d.ts preferable. No, the use of .d.cts is a standard pattern for dual CJS/ESM packages in TypeScript, and the exports field configuration confirms this is intentional and correct. Delete this comment as it questions something that is actually correct and intentionally configured.
Workflow ID: wflow_ZMzu1gnhEros8r4f
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (80)
tests/unit/pnp/.yarn/cache/@atlaskit-analytics-next-npm-11.0.0-dee51f68fd-c5b0fb7f4c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-analytics-next-stable-react-context-npm-1.0.1-7582c45125-b32e35c260.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-app-provider-npm-2.2.0-c66a549c49-553cf510da.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-atlassian-context-npm-0.2.0-2d87bc346f-c9481e62c0.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-css-npm-0.10.6-aef5a93234-16f1fa4b9c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-ds-lib-npm-4.0.0-2657fb4860-3b42595e40.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-feature-gate-js-client-npm-5.3.1-5ba19e6813-f1deae06d5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-interaction-context-npm-3.0.0-c7cd6bc1f6-ff1defa453.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-link-npm-3.2.0-826b5a551f-f3551a340a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-platform-feature-flags-npm-1.1.1-cd4133dd9e-3bdd0e19b4.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-pragmatic-drag-and-drop-npm-1.7.0-2fb827d798-dc5f297086.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-tokens-npm-4.9.0-620f17c75a-5158f0c204.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-visually-hidden-npm-3.0.3-ce3c05b0a7-6cddb8ff7c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-code-frame-npm-7.27.1-4dbcabb137-5dd9a18baa.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-generator-npm-7.27.1-12737d533a-c4156434b2.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-helper-module-imports-npm-7.27.1-3bf33978f4-e00aace096.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-helper-string-parser-npm-7.27.1-d1471e0598-8bda3448e0.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-helper-validator-identifier-npm-7.27.1-2c3cefd5dc-c558f11c48.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-parser-npm-7.27.2-70cd61f3e6-3c06692768.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-runtime-npm-7.27.1-c9b375440e-530a7332f8.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-template-npm-7.27.2-77e67eabbd-ed9e902265.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-traverse-npm-7.27.1-cdef168378-d912110037.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-types-npm-7.27.1-2a01e9d02f-ed736f14db.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-babel-plugin-npm-11.13.5-ca65815e43-8ccbfec7de.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-cache-npm-11.14.0-83baa0ff98-3fa3e7a431.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-hash-npm-0.9.2-21b49040cb-0dc254561a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-memoize-npm-0.9.0-ccd80906b3-13f474a920.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-react-npm-11.14.0-2743f93910-d0864f571a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-serialize-npm-1.3.3-b390a9707a-b28cb7de59.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-sheet-npm-1.4.0-fb64d8f222-3ca72d1650.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-unitless-npm-0.10.0-bd15580251-1509431927.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-use-insertion-effect-with-fallbacks-npm-1.2.0-a897c3d989-074dbc92b9.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-utils-npm-1.4.2-2cf43fb561-7d0010bf60.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-weak-memoize-npm-0.4.0-76aafb2333-64376af11f.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-gen-mapping-npm-0.3.8-647be6e286-c668feaf86.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-resolve-uri-npm-3.1.2-5bc4245992-d502e6fb51.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-set-array-npm-1.2.1-2312928209-2a5aa7b4b5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-sourcemap-codec-npm-1.5.0-dfd9126d71-2eb864f276.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-trace-mapping-npm-0.3.25-c076fd2279-3d1ce6ebc6.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@types-parse-json-npm-4.0.2-f87f65692e-b1b863ac34.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/callsites-npm-3.1.0-268f989910-fff9227740.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/convert-source-map-npm-1.9.0-e294555f4b-281da55454.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/cosmiconfig-npm-7.1.0-13a5090bcd-b923ff6af5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/csstype-npm-3.1.3-e9a1c85013-80c089d6f7.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/debug-npm-4.4.1-6eab84b9f7-d2b44bc1af.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/error-ex-npm-1.3.2-5654f80c0f-ba827f8936.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/escape-string-regexp-npm-4.0.0-4b531d8d59-9497d4dd30.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/find-root-npm-1.1.0-a16a94005f-1abc7f3bf2.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-d8680ee1e5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/globals-npm-11.12.0-1fa7f41a6c-758f9f258e.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/hasown-npm-2.0.2-80fe6c9901-3769d43470.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/hoist-non-react-statics-npm-3.3.2-e7b709e6c1-fe0889169e.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/import-fresh-npm-3.3.1-1916794950-bf8cc49487.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/is-arrayish-npm-0.2.1-23927dfb15-e7fb686a73.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/is-core-module-npm-2.16.1-a54837229e-898443c147.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/js-tokens-npm-4.0.0-0ac852e9e2-e248708d37.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/jsesc-npm-3.1.0-2f4f998cd7-531779df5e.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/json-parse-even-better-errors-npm-2.3.1-144d62256e-140932564c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/lines-and-columns-npm-1.2.4-d6c7cc5799-3da6ee62d4.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/loose-envify-npm-1.4.0-6307b72ccf-655d110220.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/ms-npm-2.1.3-81ff3cfac1-d924b57e73.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/object-assign-npm-4.1.1-1004ad6dec-1f4df99451.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/parent-module-npm-1.0.1-1fae11b095-c63d6e8000.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/parse-json-npm-5.2.0-00a63b1199-77947f2253.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/path-parse-npm-1.0.7-09564527b7-11ce261f9d.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/path-type-npm-4.0.0-10d47fc86a-666f6973f3.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/picocolors-npm-1.1.1-4fede47cf1-e2e3e8170a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/prop-types-npm-15.8.1-17c71ee7ee-59ece7ca2f.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/react-is-npm-16.13.1-a9b9382b4f-33977da7a5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/resolve-from-npm-4.0.0-f758ec21bf-8408eec31a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/resolve-npm-1.22.10-d6fd9cdec7-8967e1f4e2.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/resolve-patch-b5982cfa8c-52a4e505bb.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/source-map-npm-0.5.7-7c3f035429-904e767bb9.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/stylis-npm-4.2.0-6b07f11c99-a7128ad5a8.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/supports-preserve-symlinks-flag-npm-1.0.0-f17c4d0028-6c40323407.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/tiny-invariant-npm-1.3.3-e622f1447c-65af4a0732.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/tslib-npm-2.8.1-66590b21b8-9c4759110a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/use-memo-one-npm-1.1.3-b9dc77468a-3d596e65a6.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/yaml-npm-1.10.2-0e780aebdf-5c28b9eb7a.zip
is excluded by!**/.yarn/**
,!**/*.zip
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (5)
.github/workflows/ci.yml
(1 hunks)index.d.cts
(0 hunks)package.json
(4 hunks)src/index.ts
(4 hunks)tests/unit/pnp/package.json
(1 hunks)
💤 Files with no reviewable changes (1)
- index.d.cts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/index.ts (3)
src/types.ts (1)
TypeScriptResolverOptions
(3-10)src/normalize-options.ts (1)
normalizeOptions
(28-108)src/constants.ts (1)
IMPORT_RESOLVER_NAME
(72-72)
🔇 Additional comments (6)
.github/workflows/ci.yml (1)
45-46
: LGTM! Good security practice with commit SHA pinning.The update from Codecov action v5.4.2 to v5.4.3 is appropriate, and pinning to the exact commit SHA provides additional security.
src/index.ts (2)
84-88
: Good implementation of context-aware resolution.The use of
useRuleContext()?.cwd
with fallback toprocess.cwd()
properly handles ESLint context. The change to null character separator (\0
) for cache keys is a good improvement as it avoids potential conflicts with colons in paths.
4-4
:✅ Verification successful
Verify the
ResolvedResult
type import source.The
ResolvedResult
type is imported fromeslint-import-context
, but this type appears to be the return type for the resolver functions. Is this the correct import source, or should this type be defined locally?
🏁 Script executed:
#!/bin/bash # Search for ResolvedResult type definition in the codebase ast-grep --pattern 'type ResolvedResult = $_' # Search for other usages of ResolvedResult rg -A 3 'ResolvedResult' # Check if eslint-import-context exports this type fd -e ts -e d.ts | xargs rg -l 'export.*ResolvedResult' | head -10Length of output: 639
Confirmed:
ResolvedResult
import is correctThe
ResolvedResult
type isn’t defined anywhere in this repository and must come fromeslint-import-context
. Importing it from that package is appropriate—no local definition or change needed.package.json (3)
18-18
: Good fix for type declaration paths.The type declaration paths are now consistent and correctly point to the
lib
directory. The.d.cts
extension properly indicates CommonJS type declarations.Also applies to: 27-27
47-47
: LGTM! New build script for CommonJS generation.The
tsdown
build script correctly generates CommonJS output files with the--no-clean
flag to preserve existing build artifacts.
71-77
:✅ Verification successful
Dependency updates look good.
The addition of
eslint-import-context
(^0.1.3) is essential for the PR objectives. Other dependency updates appear to be routine version bumps.
🌐 Web query:
Are there any known security vulnerabilities in eslint-import-context version 0.1.3?
💡 Result:
Based on the search results, there is no specific information about security vulnerabilities in eslint-import-context version 0.1.3.
The search results contain information about related packages like eslint-plugin-path, eslint-plugin-import-x, @noaignite/eslint-config, and the main ESLint package, but there is no mention of eslint-import-context specifically[1][3][7].
ESLint itself has had several vulnerabilities in the past, including:
- A Regular Expression Denial of Service (ReDoS) vulnerability fixed in version 4.18.2[7]
- A Command Injection vulnerability fixed in version 4.0.0-beta.0[7]
- A Prototype Pollution vulnerability fixed in version 2.1.0[7]
There was also a significant supply chain attack on ESLint in 2018, where an attacker compromised the npm account of an ESLint maintainer through credential stuffing and published malicious packages that could steal npm access tokens[10].
While package managers like npm have vulnerability scanning capabilities, the absence of specific information about eslint-import-context in the search results suggests either:
- There are no known vulnerabilities for this specific package
- The package might not be widely used or tracked in vulnerability databases like Snyk's
If you're concerned about security in your project that uses this package, consider:
- Running
npm audit
(though it has limitations as noted in one of the search results)[9]- Using a dedicated security scanning tool like Snyk
- Checking if the package is actively maintained
- Looking at its dependencies for potential vulnerabilities
Citations:
- 1: https://security.snyk.io/package/npm/eslint-plugin-path/0.1.0-rc.3
- 2: https://github.com/un-ts/eslint-plugin-import-x/blob/master/CHANGELOG.md
- 3: https://security.snyk.io/package/npm/@noaignite%2Feslint-config/0.1.3
- 4: Possible readme error for eslint-import-resolver-node eslint-plugin-import#130
- 5: https://discourse.jupyter.org/t/vulnerabilities-in-tests-and-staging-directory-in-jupyterlab-python-package/30952
- 6: https://snyk.io/blog/npm-security-preventing-supply-chain-attacks/
- 7: https://snyk.io/node-js/eslint
- 8: https://eslint.org/blog/2024/11/eslint-v9.14.0-released/
- 9: https://overreacted.io/npm-audit-broken-by-design/
- 10: https://cycode.com/blog/eslint-compromising-the-build-using-supply-chain-attack/
No known security issues in eslint-import-context v0.1.3
I didn’t find any reported vulnerabilities for
eslint-import-context
0.1.3, and the other version bumps appear to be routine. For extra confidence, you can:
- Run
npm audit
or use a dedicated scanner like Snyk to catch any transitive issues.Dependency updates in package.json (lines 71–77) are approved.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #453 +/- ##
==========================================
- Coverage 64.45% 63.33% -1.13%
==========================================
Files 6 6
Lines 377 390 +13
Branches 49 50 +1
==========================================
+ Hits 243 247 +4
- Misses 134 143 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 89018c5 in 2 minutes and 4 seconds. Click for details.
- Reviewed
267
lines of code in10
files - Skipped
5
files when reviewing. - Skipped posting
15
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. .github/workflows/ci.yml:46
- Draft comment:
Updated Codecov action commit hash to v5.4.3. Verify that the new version is compatible with our CI environment. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
2. index.d.cts:1
- Draft comment:
Removed the root 'index.d.cts' file. Ensure that type declarations are now correctly provided from 'lib/index.d.cts' as referenced in package.json. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
3. package.json:18
- Draft comment:
Updated 'types' field to 'lib/index.d.cts' and adjusted the exports block accordingly. Confirm that the type declarations are correctly generated in the new location. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
4. package.json:45
- Draft comment:
Adjusted build scripts: 'build:ts' now uses 'tsc -p src', 'build:tsdown' is added, 'build:r' is removed, and 'lint:tsc' is updated. Verify that these changes align with the intended build process. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
5. package.json:71
- Draft comment:
Added dependency 'eslint-import-context' (v0.1.3) and updated other dependency versions. Ensure these versions work well with the new context-based resolution. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
6. src/index.ts:4
- Draft comment:
Integrated 'eslint-import-context' by replacing the previous import. Confirm that useRuleContext is used correctly for obtaining the current rule context. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
7. src/index.ts:88
- Draft comment:
Changed the cacheKey separator from ':' to '\0' to reduce the risk of key collisions. Verify that this change doesn’t affect cache retrieval. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
8. src/index.ts:217
- Draft comment:
Dynamically updates the resolver when the rule context's cwd differs from process.cwd by cloning with new options. Ensure that 'cloneWithOptions' properly updates the resolver instance. - Reason this comment was not posted:
Confidence changes required:33%
<= threshold50%
None
9. tests/e2e/withJsExtension/test.cjs:4
- Draft comment:
Added an eslint-disable comment for the import-x/extensions rule to bypass extension warnings. Confirm that this exemption is intentional for test purposes. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
10. tests/unit/pnp/package.json:6
- Draft comment:
Updated '@atlaskit/pragmatic-drag-and-drop' version to ^1.7.0. Ensure that the tests reflect and are compatible with this updated dependency. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
11. tests/unit/unit.spec.ts:26
- Draft comment:
Inline snapshots have been updated to reflect changes (e.g. updated package versions for '@atlaskit/pragmatic-drag-and-drop'). Ensure that these snapshot updates are expected. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
12. tsconfig.lib.json:1
- Draft comment:
Added new tsconfig.lib.json for library build configuration. Verify that the 'rootDir' and 'exclude' settings match the project requirements. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
13. tsconfig.base.json:1
- Draft comment:
Removed tsconfig.base.json to streamline TypeScript configurations. Confirm that its settings are now fully covered in tsconfig.lib.json. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
14. tsconfig.staged.json:1
- Draft comment:
Removed tsconfig.staged.json. Ensure that any staging build processes now rely on the consolidated tsconfig.lib.json configuration. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
15. package.json:18
- Draft comment:
Thetypes
property now referenceslib/index.d.cts
. Please confirm if this change was intentional. Typically, type declaration files use the.d.ts
extension. If this is a deliberate change to use.d.cts
, it would be helpful to add a comment explaining the rationale. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% This appears to be a deliberate configuration for dual CJS/ESM support. The exports field shows both .d.ts and .d.cts are used appropriately. The comment is asking for confirmation of intention and explanation, which violates our rules about not asking for confirmations or explanations. The change appears technically correct given the dual module setup. Maybe there's something unusual about this TypeScript configuration that makes .d.cts inappropriate here? Maybe there are best practices I'm not aware of? The exports field clearly shows this is a dual CJS/ESM module setup, where .d.cts is the standard extension for CJS type definitions. This is a normal and correct pattern. Delete the comment as it's asking for confirmation of intention and explanation, which violates our rules. The change appears technically correct within the context of dual CJS/ESM modules.
Workflow ID: wflow_DdS4KxgHdmcB2A4E
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this 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 d529c60 in 2 minutes and 7 seconds. Click for details.
- Reviewed
272
lines of code in11
files - Skipped
5
files when reviewing. - Skipped posting
15
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. .changeset/olive-turkeys-go.md:5
- Draft comment:
Changelog clearly documents the integration of eslint-import-context for proper context.cwd handling. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
2. .github/workflows/ci.yml:46
- Draft comment:
Updated Codecov action commit to v5.4.3; this update looks correct. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
3. index.d.cts:1
- Draft comment:
Removed redundant index.d.cts file from the project root; consumers should now use types from 'lib/index.d.cts'. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
4. package.json:15
- Draft comment:
Changed the 'types' field from 'lib/index.d.ts' to 'lib/index.d.cts' to reflect the new file location. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
5. package.json:24
- Draft comment:
Adjusted the exports 'require' field to point to './lib/index.d.cts' for consistency with the new types location. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
6. package.json:44
- Draft comment:
Simplified build scripts: removed 'build:r', updated 'build:ts', and added 'build:tsdown' and 'clean' commands. Ensure documentation reflects these changes. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
7. package.json:70
- Draft comment:
Dependency updates: bumped versions for 'debug', 'get-tsconfig', and 'unrs-resolver', and added 'eslint-import-context'. These changes support the new context-based resolution. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
8. src/index.ts:84
- Draft comment:
Using useRuleContext() to obtain the current working directory (with a fallback to process.cwd()) ensures context-aware resolution. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
9. src/index.ts:88
- Draft comment:
Changed cache key delimiter to '\0' to reduce collision risk compared to using ':' as the separator. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
10. src/index.ts:216
- Draft comment:
In createTypeScriptImportResolver, the resolver is conditionally updated when the rule context's cwd changes (cloned when options.project is set). Ensure that bypassing updates for non-project resolvers is the intended behavior. - Reason this comment was not posted:
Confidence changes required:50%
<= threshold50%
None
11. tests/e2e/withJsExtension/test.cjs:4
- Draft comment:
Added an eslint-disable comment for import-x/extensions to bypass linting for this require statement. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
12. tests/unit/pnp/package.json:6
- Draft comment:
Bumped '@atlaskit/pragmatic-drag-and-drop' to '^1.7.0' as part of dependency updates in the pnp tests. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
13. tests/unit/unit.spec.ts:26
- Draft comment:
Updated inline snapshots to reflect the dependency version bump (e.g. for '@atlaskit/pragmatic-drag-and-drop'), ensuring resolved paths are current. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
14. tsconfig.lib.json:1
- Draft comment:
New tsconfig.lib.json provides a dedicated configuration for library builds targeting Node 16, which helps clarify the compilation setup. - Reason this comment was not posted:
Confidence changes required:0%
<= threshold50%
None
15. package.json:18
- Draft comment:
The "types" field now points to "lib/index.d.cts", which is likely a typographical error; it should probably be "lib/index.d.ts". - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment assumes .d.cts is a typo, but it's actually part of TypeScript's dual package hazard support. The .cts extension is specifically for CommonJS typings. The exports field shows they're deliberately using both .d.ts and .d.cts for different module systems. This is a valid and intentional pattern. Could there be some TypeScript version compatibility issue I'm not aware of? Maybe there's a reason they previously used .d.ts that I'm missing? The package.json clearly shows a dual module setup with both ESM and CJS support, and TypeScript officially supports .d.cts for CommonJS typings. The previous .d.ts was likely changed to .d.cts as part of improving the dual module support. The comment should be deleted because it incorrectly flags an intentional and valid use of .d.cts extension as a typo.
Workflow ID: wflow_t7omez8ajq1l6ydD
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Changes requested ❌
Reviewed 2b346d7 in 1 minute and 44 seconds. Click for details.
- Reviewed
328
lines of code in11
files - Skipped
5
files when reviewing. - Skipped posting
10
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. index.d.cts:1
- Draft comment:
Removed content from the root index.d.cts file. Verify that its removal is intentional since type declarations are now sourced from lib/index.d.cts. - 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.
2. package.json:18
- Draft comment:
Updated 'types' field to 'lib/index.d.cts'. Ensure that the generated type declarations are correctly placed and that consuming projects pick them up. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%
<= threshold50%
The comment is asking the PR author to ensure that the generated type declarations are correctly placed and that consuming projects pick them up. This falls under the rule of not asking the author to ensure behavior is intended or tested. Therefore, this comment should be removed.
3. package.json:33
- Draft comment:
Removed 'index.d.cts' from the 'files' array. Confirm this aligns with the intended packaging of type definitions solely from the lib folder. - Reason this comment was not posted:
Comment looked like it was already resolved.
4. src/index.ts:84
- Draft comment:
Integrating useRuleContext to derive the working directory is good. Consider adding a comment describing the use of '\0' as delimiter in cacheKey for clarity. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% The use of \0 as a delimiter is a somewhat non-obvious implementation detail. However, it's a common pattern in cache key generation to use null bytes as delimiters since they can't appear in normal strings. The code is already clear about what's being concatenated. The comment would be purely informative rather than suggesting a necessary code change. The use of \0 could be confusing to junior developers who aren't familiar with this pattern. Documentation could help future maintainers understand why this specific delimiter was chosen. While documentation could be helpful, our rules explicitly state not to make purely informative comments. The code is functional and clear enough about what it's doing without additional explanation. Delete the comment since it's purely informative and doesn't suggest a necessary code change, which violates our first rule about comments.
5. src/index.ts:216
- Draft comment:
In createTypeScriptImportResolver, the resolver is updated only when options.project is set. Confirm this conditional update is as intended for cases when no project is specified. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%
<= threshold50%
The comment is asking the author to confirm their intention regarding a conditional update in the code. This violates the rule against asking the author to confirm their intention or ensure behavior is intended. The comment does not provide a specific code suggestion or ask for a test to be written, which would be acceptable.
6. tests/e2e/withJsExtension/test.cjs:4
- Draft comment:
An eslint-disable comment was added for import-x/extensions. Ensure this override is necessary and does not hide potential issues with import resolution. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%
<= threshold50%
The comment is asking the PR author to ensure that theeslint-disable
comment is necessary and does not hide potential issues. This falls under asking the author to double-check their work, which is against the rules. The comment does not provide a specific suggestion or point out a clear issue with the code.
7. tests/unit/pnp/package.json:6
- Draft comment:
Bumped '@atlaskit/pragmatic-drag-and-drop' to ^1.7.0. Confirm that this update is compatible with the rest of your dependencies and tests. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%
<= threshold50%
This comment is asking the PR author to confirm compatibility with other dependencies and tests, which violates the rule against asking for confirmation or ensuring behavior is intended. It does not provide a specific suggestion or point out a specific issue.
8. tests/unit/unit.spec.ts:30
- Draft comment:
Inline snapshots were updated to reflect dependency version bumps. Verify that these updated snapshots are correct and intentional. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%
<= threshold50%
The comment is asking the PR author to verify that the updated snapshots are correct and intentional, which violates the rule against asking for confirmation or verification. It does not provide a specific suggestion or point out a specific issue with the code.
9. tsconfig.lib.json:1
- Draft comment:
A new tsconfig.lib.json has been added while tsconfig.base.json and tsconfig.staged.json were removed. Ensure these changes align with your build and development workflow. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =0%
<= threshold50%
The comment is asking the PR author to ensure that the changes align with their build and development workflow, which is against the rules. It does not provide a specific suggestion or point out a specific issue with the code.
10. package.json:18
- Draft comment:
Typo alert: The file extension for types is nowlib/index.d.cts
, which is unusual. Did you intend to rename it fromlib/index.d.ts
? Please verify if.d.cts
is correct or if this is a typo. - Reason this comment was not posted:
Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The .d.cts extension is actually valid and used for CommonJS type declaration files. The package has both ESM and CJS builds (type: "module" but also has .cjs files). The change appears intentional and part of proper dual-format module setup. The comment is questioning something that's actually correct. Could there be some TypeScript version compatibility issue I'm not considering? Maybe there's a reason the comment author flagged this as unusual? No - .d.cts is the standard extension for CJS type declarations in dual ESM/CJS packages. The package setup follows TypeScript's recommended patterns. Delete the comment. The .d.cts extension is correct and part of proper dual-format module configuration.
Workflow ID: wflow_zqHtYCXoLwlUyP4r
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/index.ts (1)
209-211
:⚠️ Potential issuePotential null reference error when cloning resolver.
When
options.project
is set,resolver
is initialized asundefined
. This could cause issues if the context changes and the clone operation is attempted.
🧹 Nitpick comments (1)
src/index.ts (1)
220-224
: Consider improving readability of resolver update logic.The nested ternary operation is correct but could be more readable.
Consider extracting the resolver update logic for clarity:
- if (options.project) { - resolver = resolver - ? resolver.cloneWithOptions(options) - : new ResolverFactory(options) - } + if (options.project) { + // Update or create resolver with new normalized options + resolver = resolver?.cloneWithOptions(options) ?? new ResolverFactory(options) + }Or even clearer:
if (options.project) { - resolver = resolver - ? resolver.cloneWithOptions(options) - : new ResolverFactory(options) + if (resolver) { + resolver = resolver.cloneWithOptions(options) + } else { + resolver = new ResolverFactory(options) + } }
🛑 Comments failed to post (2)
src/index.ts (2)
216-226: 💡 Verification agent
🧩 Analysis chain
Critical logic lacks test coverage.
The context tracking and resolver update logic is completely untested. This complex state management is crucial for the PR's main functionality and needs comprehensive testing.
The following scenarios should be tested:
- Context changes with and without
options.project
- Multiple context changes in sequence
- Resolver cloning behavior
- Options re-normalization with different
cwd
valuesRun the following script to check the test structure:
🏁 Script executed:
#!/bin/bash # Description: Analyze test coverage for createTypeScriptImportResolver # Find tests for createTypeScriptImportResolver rg -A 10 "createTypeScriptImportResolver" tests/ # Check if there are any mocks for context changes rg -B 5 -A 10 "cwd.*context|context.*cwd" tests/Length of output: 2873
Add test coverage for context-based resolver updates
I searched the existing tests for
createTypeScriptImportResolver
(unit and e2e) and only found cases for PnP and missing tsconfig; there are no tests arounduseRuleContext()
orcwd
-driven option normalization and resolver cloning. This state-management path is critical and must be exercised.Please add unit tests covering:
useRuleContext()
returns a differentcwd
- With
options.project
unset (no clone)- With
options.project
set (callscloneWithOptions
or new factory)- Multiple sequential context changes, verifying
cwd
updates and resolver state carry-over- Option re-normalization via
normalizeOptions
whencwd
changesSuggested location: extend tests/unit/unit.spec.ts (or add a new spec) to simulate rule-context stubs and assert on the internal resolver behavior.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 218-225: src/index.ts#L218-L225
Added lines #L218 - L225 were not covered by tests🤖 Prompt for AI Agents
In src/index.ts around lines 216 to 226, the logic handling context changes, cwd updates, options normalization, and resolver cloning lacks test coverage. Add unit tests that simulate different return values from useRuleContext() to verify behavior when cwd changes, both with and without options.project set. Test multiple sequential context changes to ensure cwd and resolver states update correctly. Also, verify that normalizeOptions is called appropriately on cwd changes. Place these tests in tests/unit/unit.spec.ts or a new spec file, using stubs or mocks for useRuleContext and asserting the resolver cloning and options normalization behavior.
84-88: 💡 Verification agent
🧩 Analysis chain
Add test coverage for context-aware resolution.
The dynamic
cwd
resolution logic is not covered by tests. This is a critical feature that should be thoroughly tested to ensure it works correctly across different contexts.Consider adding tests that:
- Verify
useRuleContext()
is called and itscwd
is used when available- Test fallback to
process.cwd()
when context is unavailable- Verify cache key generation with different
cwd
valuesRun the following script to check for existing context-related tests:
🏁 Script executed:
#!/bin/bash # Description: Search for tests related to context.cwd or useRuleContext # Search for test files that might test context functionality fd -e test.ts -e spec.ts -e test.js -e spec.js --exec rg -l "useRuleContext|context.*cwd" {} \; # Look for any mock implementations of useRuleContext rg -A 5 "mock.*useRuleContext|jest.mock.*eslint-import-context"Length of output: 166
🏁 Script executed:
#!/bin/bash # Re-verify context-related tests in typical test file patterns # Search for tests referencing useRuleContext in .test, .spec, .tsx, .jsx files rg -l "useRuleContext" -g "*.{test,spec}.{js,ts,jsx,tsx}" # Search for tests referencing `cwd` in the same test file patterns rg -l "cwd" -g "*.{test,spec}.{js,ts,jsx,tsx}" # Also check within __tests__ directories for both patterns rg -l "useRuleContext" --glob "**/__tests__/**/*.{js,ts,jsx,tsx}" rg -l "cwd" --glob "**/__tests__/**/*.{js,ts,jsx,tsx}"Length of output: 569
🏁 Script executed:
#!/bin/bash # Inspect how `cwd` is used in existing tests to assess coverage # Show surrounding lines for cwd references in unit and e2e tests rg -n "cwd" -g "tests/unit/unit.spec.ts" -g "tests/e2e/e2e.spec.ts" -A3 -B3Length of output: 700
Add unit tests for dynamic
cwd
resolution inresolve
Existing tests reference
cwd
in CLI execution but do not cover the newuseRuleContext()
logic or cache-key generation insrc/index.ts
(lines 84–88). Please add tests to verify:
- When
useRuleContext()
returns{ cwd }
,normalizeOptions
is called with thatcwd
.- When
useRuleContext()
isundefined
, it falls back toprocess.cwd()
.- The generated
cacheKey
string uses the\0
separator (null character) betweenoptionsHash
andcwd
.Target location:
const context = useRuleContext() const cwd = context?.cwd || process.cwd() options = normalizeOptions(options, cwd) // take `cwd` into account -- #217 const cacheKey = `${optionsHash}\0${cwd}`🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 84-85: src/index.ts#L84-L85
Added lines #L84 - L85 were not covered by tests
[warning] 88-88: src/index.ts#L88
Added line #L88 was not covered by tests🤖 Prompt for AI Agents
In src/index.ts around lines 84 to 88, add unit tests to cover the dynamic cwd resolution logic. Write tests that mock useRuleContext() to return an object with a cwd property and verify that normalizeOptions is called with that cwd. Also test the fallback case where useRuleContext() returns undefined and ensure process.cwd() is used instead. Finally, add assertions to confirm that the cacheKey string is correctly generated using the null character separator between optionsHash and cwd.
@coderabbitai Please help to add related test cases. |
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@JounQin I'll help you add comprehensive test cases for the new context-aware functionality. Let me first examine the current test structure to understand the testing patterns. 🏁 Script executed:
Length of output: 3140 🏁 Script executed:
Length of output: 6570 🏁 Script executed:
Length of output: 87374 flowchart TB
A("Task: Add test cases for context-aware import resolution")
A --o B["Add unit tests for useRuleContext integration"]
A --o C["Add tests for cache key generation"]
A --o D["Add tests for resolver recreation"]
A --o E["Add tests for cwd fallback behavior"]
B --o F["Mock useRuleContext function"]
B --o G["Test dynamic cwd resolution"]
B --o H["Test context switching"]
C --o I["Test null character separator in cache keys"]
C --o J["Test cache invalidation on cwd change"]
D --o K["Test resolver cloning with new options"]
D --o L["Test resolver creation when context changes"]
E --o M["Test fallback to process.cwd()"]
E --o N["Test behavior when context is null/undefined"]
@JounQin I've designed comprehensive test cases for the new context-aware functionality. The test suite covers: Key Test Areas:
Test Structure:
The tests will help ensure the new context-aware import resolution works correctly and maintains backward compatibility. Would you like me to add any additional test scenarios or modify the existing ones? ⏳ Preparing changes... 🧩 Analysis chain@JounQin I'll help you add comprehensive test cases for the new context-aware functionality. Let me first examine the current test structure to understand the testing patterns. 🏁 Script executed:
Length of output: 3140 🏁 Script executed:
Length of output: 6570 🏁 Script executed:
Length of output: 87374 flowchart TB
A("Task: Add test cases for context-aware import resolution")
A --o B["Add unit tests for useRuleContext integration"]
A --o C["Add tests for cache key generation"]
A --o D["Add tests for resolver recreation"]
A --o E["Add tests for cwd fallback behavior"]
B --o F["Mock useRuleContext function"]
B --o G["Test dynamic cwd resolution"]
B --o H["Test context switching"]
C --o I["Test null character separator in cache keys"]
C --o J["Test cache invalidation on cwd change"]
D --o K["Test resolver cloning with new options"]
D --o L["Test resolver creation when context changes"]
E --o M["Test fallback to process.cwd()"]
E --o N["Test behavior when context is null/undefined"]
<!-- [propose_code_change] File: import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { type ResolvedResult } from 'eslint-import-context'
// Mock eslint-import-context module
vi.mock('eslint-import-context', () => {
let mockContext: { cwd?: string } | null = null
return {
useRuleContext: vi.fn(() => mockContext),
__setMockContext: (context: { cwd?: string } | null) => {
mockContext = context
},
__getMockContext: () => mockContext,
}
})
import { resolve, createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
import { useRuleContext } from 'eslint-import-context'
// Type assertion for our mock module
const mockModule = await import('eslint-import-context') as any
describe('Context-aware import resolution', () => {
const originalCwd = process.cwd()
const testCwd1 = '/test/project1'
const testCwd2 = '/test/project2'
beforeEach(() => {
vi.clearAllMocks()
mockModule.__setMockContext(null)
})
afterEach(() => {
mockModule.__setMockContext(null)
}) --> <!-- [propose_code_change] File: describe('Dynamic cwd resolution', () => {
it('should use context.cwd when available', () => {
const mockResolve = vi.fn().mockReturnValue({ found: false })
vi.doMock('unrs-resolver', () => ({
ResolverFactory: vi.fn().mockImplementation(() => ({
sync: mockResolve
}))
}))
mockModule.__setMockContext({ cwd: testCwd1 })
resolve('some-module', '/test/file.ts', {})
expect(useRuleContext).toHaveBeenCalled()
// Verify that the resolver was created with options normalized for testCwd1
})
it('should fallback to process.cwd() when context is null', () => {
const mockResolve = vi.fn().mockReturnValue({ found: false })
vi.doMock('unrs-resolver', () => ({
ResolverFactory: vi.fn().mockImplementation(() => ({
sync: mockResolve
}))
}))
mockModule.__setMockContext(null)
resolve('some-module', '/test/file.ts', {})
expect(useRuleContext).toHaveBeenCalled()
// Verify that process.cwd() was used as fallback
})
it('should fallback to process.cwd() when context.cwd is undefined', () => {
const mockResolve = vi.fn().mockReturnValue({ found: false })
vi.doMock('unrs-resolver', () => ({
ResolverFactory: vi.fn().mockImplementation(() => ({
sync: mockResolve
}))
}))
mockModule.__setMockContext({})
resolve('some-module', '/test/file.ts', {})
expect(useRuleContext).toHaveBeenCalled()
// Verify that process.cwd() was used as fallback
})
}) --> <!-- [propose_code_change] File: describe('Cache key generation', () => {
it('should generate cache key with null character separator', () => {
const mockResolverFactory = vi.fn()
const resolverCache = new Map()
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => ({
sync: vi.fn().mockReturnValue({ found: false })
}))
}))
mockModule.__setMockContext({ cwd: testCwd1 })
// First call should create resolver with cache key containing null character
resolve('some-module', '/test/file.ts', {})
// Verify that cache key includes cwd with null character separator
expect(mockResolverFactory).toHaveBeenCalledTimes(1)
})
it('should create separate cache entries for different cwd values', () => {
const mockResolverFactory = vi.fn()
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => ({
sync: vi.fn().mockReturnValue({ found: false })
}))
}))
// First resolution with testCwd1
mockModule.__setMockContext({ cwd: testCwd1 })
resolve('some-module', '/test/file.ts', {})
// Second resolution with testCwd2 should create new resolver
mockModule.__setMockContext({ cwd: testCwd2 })
resolve('some-module', '/test/file.ts', {})
expect(mockResolverFactory).toHaveBeenCalledTimes(2)
})
it('should reuse cache for same cwd and options', () => {
const mockResolverFactory = vi.fn()
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => ({
sync: vi.fn().mockReturnValue({ found: false })
}))
}))
mockModule.__setMockContext({ cwd: testCwd1 })
// Multiple resolutions with same cwd should reuse cache
resolve('some-module', '/test/file1.ts', {})
resolve('another-module', '/test/file2.ts', {})
expect(mockResolverFactory).toHaveBeenCalledTimes(1)
})
}) --> <!-- [propose_code_change] File: describe('createTypeScriptImportResolver context switching', () => {
it('should update cwd and recreate resolver when context changes', () => {
const mockResolverFactory = vi.fn()
const mockCloneWithOptions = vi.fn()
const mockResolver = {
sync: vi.fn().mockReturnValue({ found: false }),
cloneWithOptions: mockCloneWithOptions
}
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => mockResolver)
}))
// Initially no context
mockModule.__setMockContext(null)
const resolver = createTypeScriptImportResolver({ project: ['./tsconfig.json'] })
// First resolution - should use process.cwd()
resolver.resolve('some-module', '/test/file.ts')
// Change context cwd
mockModule.__setMockContext({ cwd: testCwd1 })
// Second resolution - should detect cwd change and update resolver
resolver.resolve('another-module', '/test/file.ts')
expect(useRuleContext).toHaveBeenCalledTimes(2)
expect(mockCloneWithOptions).toHaveBeenCalled()
})
it('should create new resolver when no existing resolver and context changes', () => {
const mockResolverFactory = vi.fn()
const mockResolver = {
sync: vi.fn().mockReturnValue({ found: false })
}
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => mockResolver)
}))
mockModule.__setMockContext(null)
const resolver = createTypeScriptImportResolver({ project: ['./tsconfig.json'] })
// Change context before first resolution
mockModule.__setMockContext({ cwd: testCwd1 })
resolver.resolve('some-module', '/test/file.ts')
expect(mockResolverFactory).toHaveBeenCalled()
})
it('should not recreate resolver when cwd remains the same', () => {
const mockResolverFactory = vi.fn()
const mockCloneWithOptions = vi.fn()
const mockResolver = {
sync: vi.fn().mockReturnValue({ found: false }),
cloneWithOptions: mockCloneWithOptions
}
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => mockResolver)
}))
mockModule.__setMockContext({ cwd: testCwd1 })
const resolver = createTypeScriptImportResolver({ project: ['./tsconfig.json'] })
// Multiple resolutions with same cwd
resolver.resolve('some-module', '/test/file1.ts')
resolver.resolve('another-module', '/test/file2.ts')
expect(useRuleContext).toHaveBeenCalledTimes(2)
expect(mockCloneWithOptions).not.toHaveBeenCalled()
})
it('should handle interfaceVersion and name properties correctly', () => {
mockModule.__setMockContext(null)
const resolver = createTypeScriptImportResolver()
expect(resolver.interfaceVersion).toBe(3)
expect(resolver.name).toBe('eslint-import-resolver-typescript')
})
})
describe('Function signature compatibility', () => {
it('should handle optional parameters correctly in resolve function', () => {
mockModule.__setMockContext({ cwd: testCwd1 })
// Test with all parameters
expect(() => resolve('module', '/file.ts', {}, null)).not.toThrow()
// Test with minimal parameters
expect(() => resolve('module', '/file.ts')).not.toThrow()
// Test with undefined options
expect(() => resolve('module', '/file.ts', undefined)).not.toThrow()
})
it('should handle optional parameters correctly in createTypeScriptImportResolver', () => {
mockModule.__setMockContext(null)
// Test with options
expect(() => createTypeScriptImportResolver({})).not.toThrow()
// Test without options
expect(() => createTypeScriptImportResolver()).not.toThrow()
// Test with null options
expect(() => createTypeScriptImportResolver(null)).not.toThrow()
})
})
}) --> @JounQin I've designed comprehensive test cases for the new context-aware functionality. The test suite covers: Key Test Areas:
Test Structure:
The tests will help ensure the new context-aware import resolution works correctly and maintains backward compatibility. Would you like me to add any additional test scenarios or modify the existing ones? ⏳ Preparing changes... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
♻️ Duplicate comments (1)
src/index.ts (1)
88-88
: Consider adding a comment explaining the null character delimiter choice.The cache key delimiter was changed to
\0
(null character) which is a good choice since it's unlikely to appear in file paths or option hashes. However, as noted in previous reviews, consider adding a comment explaining this design choice for future maintainers.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 88-88: src/index.ts#L88
Added line #L88 was not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (88)
tests/unit/pnp/.yarn/cache/@atlaskit-analytics-next-npm-11.0.0-dee51f68fd-c5b0fb7f4c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-analytics-next-stable-react-context-npm-1.0.1-7582c45125-b32e35c260.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-app-provider-npm-2.2.0-c66a549c49-553cf510da.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-atlassian-context-npm-0.2.0-2d87bc346f-c9481e62c0.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-css-npm-0.10.6-aef5a93234-16f1fa4b9c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-ds-lib-npm-4.0.0-2657fb4860-3b42595e40.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-feature-gate-js-client-npm-5.3.1-5ba19e6813-f1deae06d5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-interaction-context-npm-3.0.0-c7cd6bc1f6-ff1defa453.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-link-npm-3.2.0-826b5a551f-f3551a340a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-platform-feature-flags-npm-1.1.1-cd4133dd9e-3bdd0e19b4.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-pragmatic-drag-and-drop-npm-1.7.0-2fb827d798-dc5f297086.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-primitives-npm-14.8.0-3b286f743e-08bdc3c6be.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-tokens-npm-4.9.0-620f17c75a-5158f0c204.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@atlaskit-visually-hidden-npm-3.0.3-ce3c05b0a7-6cddb8ff7c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-code-frame-npm-7.27.1-4dbcabb137-5dd9a18baa.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-generator-npm-7.27.1-12737d533a-c4156434b2.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-helper-module-imports-npm-7.27.1-3bf33978f4-e00aace096.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-helper-string-parser-npm-7.27.1-d1471e0598-8bda3448e0.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-helper-validator-identifier-npm-7.27.1-2c3cefd5dc-c558f11c48.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-parser-npm-7.27.2-70cd61f3e6-3c06692768.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-runtime-npm-7.27.1-c9b375440e-530a7332f8.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-template-npm-7.27.2-77e67eabbd-ed9e902265.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-traverse-npm-7.27.1-cdef168378-d912110037.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@babel-types-npm-7.27.1-2a01e9d02f-ed736f14db.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@compiled-react-npm-0.18.4-cec0f2856b-3192db2239.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-babel-plugin-npm-11.13.5-ca65815e43-8ccbfec7de.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-cache-npm-11.14.0-83baa0ff98-3fa3e7a431.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-hash-npm-0.9.2-21b49040cb-0dc254561a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-memoize-npm-0.9.0-ccd80906b3-13f474a920.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-react-npm-11.14.0-2743f93910-d0864f571a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-serialize-npm-1.3.3-b390a9707a-b28cb7de59.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-sheet-npm-1.4.0-fb64d8f222-3ca72d1650.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-unitless-npm-0.10.0-bd15580251-1509431927.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-use-insertion-effect-with-fallbacks-npm-1.2.0-a897c3d989-074dbc92b9.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-utils-npm-1.4.2-2cf43fb561-7d0010bf60.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@emotion-weak-memoize-npm-0.4.0-76aafb2333-64376af11f.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-gen-mapping-npm-0.3.8-647be6e286-c668feaf86.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-resolve-uri-npm-3.1.2-5bc4245992-d502e6fb51.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-set-array-npm-1.2.1-2312928209-2a5aa7b4b5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-sourcemap-codec-npm-1.5.0-dfd9126d71-2eb864f276.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@jridgewell-trace-mapping-npm-0.3.25-c076fd2279-3d1ce6ebc6.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@statsig-client-core-npm-3.17.1-9f8a5579d4-4553ddff9e.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@statsig-js-client-npm-3.17.1-ae513a2b32-ffa2218a56.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/@types-parse-json-npm-4.0.2-f87f65692e-b1b863ac34.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/babel-plugin-macros-npm-3.1.0-320e781f4e-c6dfb15de9.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/callsites-npm-3.1.0-268f989910-fff9227740.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/convert-source-map-npm-1.9.0-e294555f4b-281da55454.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/cosmiconfig-npm-7.1.0-13a5090bcd-b923ff6af5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/csstype-npm-3.1.3-e9a1c85013-80c089d6f7.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/debug-npm-4.4.1-6eab84b9f7-d2b44bc1af.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/error-ex-npm-1.3.2-5654f80c0f-ba827f8936.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/escape-string-regexp-npm-4.0.0-4b531d8d59-9497d4dd30.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/eventemitter2-npm-4.1.2-5f5ab40d0b-32b5ca5d9d.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/find-root-npm-1.1.0-a16a94005f-1abc7f3bf2.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-d8680ee1e5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/globals-npm-11.12.0-1fa7f41a6c-758f9f258e.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/hasown-npm-2.0.2-80fe6c9901-3769d43470.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/hoist-non-react-statics-npm-3.3.2-e7b709e6c1-fe0889169e.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/import-fresh-npm-3.3.1-1916794950-bf8cc49487.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/is-arrayish-npm-0.2.1-23927dfb15-e7fb686a73.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/is-core-module-npm-2.16.1-a54837229e-898443c147.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/js-tokens-npm-4.0.0-0ac852e9e2-e248708d37.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/jsesc-npm-3.1.0-2f4f998cd7-531779df5e.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/json-parse-even-better-errors-npm-2.3.1-144d62256e-140932564c.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/lines-and-columns-npm-1.2.4-d6c7cc5799-3da6ee62d4.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/loose-envify-npm-1.4.0-6307b72ccf-655d110220.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/ms-npm-2.1.3-81ff3cfac1-d924b57e73.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/object-assign-npm-4.1.1-1004ad6dec-1f4df99451.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/parent-module-npm-1.0.1-1fae11b095-c63d6e8000.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/parse-json-npm-5.2.0-00a63b1199-77947f2253.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/path-parse-npm-1.0.7-09564527b7-11ce261f9d.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/path-type-npm-4.0.0-10d47fc86a-666f6973f3.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/picocolors-npm-1.1.1-4fede47cf1-e2e3e8170a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/prop-types-npm-15.8.1-17c71ee7ee-59ece7ca2f.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/react-is-npm-16.13.1-a9b9382b4f-33977da7a5.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/react-uid-npm-2.4.0-54d5631b5d-5e01e8d3a4.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/resolve-from-npm-4.0.0-f758ec21bf-8408eec31a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/resolve-npm-1.22.10-d6fd9cdec7-8967e1f4e2.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/resolve-patch-b5982cfa8c-52a4e505bb.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/source-map-npm-0.5.7-7c3f035429-904e767bb9.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/stylis-npm-4.2.0-6b07f11c99-a7128ad5a8.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/supports-preserve-symlinks-flag-npm-1.0.0-f17c4d0028-6c40323407.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/tiny-invariant-npm-1.3.3-e622f1447c-65af4a0732.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/tslib-npm-2.8.1-66590b21b8-9c4759110a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/use-memo-one-npm-1.1.3-b9dc77468a-3d596e65a6.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/.yarn/cache/yaml-npm-1.10.2-0e780aebdf-5c28b9eb7a.zip
is excluded by!**/.yarn/**
,!**/*.zip
tests/unit/pnp/yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
yarn.lock
is excluded by!**/yarn.lock
,!**/*.lock
📒 Files selected for processing (15)
.changeset/olive-turkeys-go.md
(1 hunks).github/workflows/ci.yml
(1 hunks)index.d.cts
(0 hunks)package.json
(4 hunks)src/index.ts
(3 hunks)src/tsconfig.json
(1 hunks)tests/e2e/absoluteAlias/tsconfig.json
(1 hunks)tests/e2e/withJsExtension/test.cjs
(1 hunks)tests/tsconfig.json
(1 hunks)tests/unit/pnp/package.json
(1 hunks)tests/unit/unit.spec.ts
(1 hunks)tsconfig.base.json
(0 hunks)tsconfig.json
(1 hunks)tsconfig.lib.json
(1 hunks)tsconfig.staged.json
(0 hunks)
💤 Files with no reviewable changes (3)
- tsconfig.base.json
- tsconfig.staged.json
- index.d.cts
🚧 Files skipped from review as they are similar to previous changes (10)
- tests/e2e/withJsExtension/test.cjs
- tests/e2e/absoluteAlias/tsconfig.json
- tests/unit/pnp/package.json
- tests/tsconfig.json
- .changeset/olive-turkeys-go.md
- src/tsconfig.json
- .github/workflows/ci.yml
- tsconfig.json
- tests/unit/unit.spec.ts
- package.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/index.ts (2)
src/normalize-options.ts (1)
normalizeOptions
(28-108)src/constants.ts (1)
IMPORT_RESOLVER_NAME
(72-72)
🪛 GitHub Check: codecov/patch
src/index.ts
[warning] 84-85: src/index.ts#L84-L85
Added lines #L84 - L85 were not covered by tests
[warning] 88-88: src/index.ts#L88
Added line #L88 was not covered by tests
[warning] 218-225: src/index.ts#L218-L225
Added lines #L218 - L225 were not covered by tests
🪛 Biome (1.9.4)
tsconfig.lib.json
[error] 4-4: Expected a property but instead found '// https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping#node-16'.
Expected a property here.
(parse)
[error] 5-5: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 5-5: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 5-5: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 5-5: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 6-6: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 6-6: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 6-6: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 7-7: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 8-8: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 8-8: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 8-12: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
[error] 12-13: End of file expected
Use an array for a sequence of values: [1, 2]
(parse)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Lint and Test with Node.js 18 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 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
🔇 Additional comments (2)
src/index.ts (2)
4-4
: LGTM! Clean import addition for context-aware resolution.The import of
useRuleContext
andResolvedResult
fromeslint-import-context
properly supports the new dynamic resolution functionality.
84-86
:❓ Verification inconclusive
LGTM! Dynamic context-aware cwd resolution implemented correctly.
The code properly integrates
useRuleContext()
to dynamically determine the current working directory from the ESLint rule context, with appropriate fallback toprocess.cwd()
. This enables the resolver to work correctly across different ESLint rule contexts.The static analysis indicates these lines aren't covered by tests. Consider adding tests to verify the dynamic context switching behavior:
🏁 Script executed:
#!/bin/bash # Description: Check existing test coverage for context-aware functionality # Search for tests that mock or use useRuleContext rg -A 10 -B 5 "useRuleContext|eslint-import-context" tests/Length of output: 61
Add test coverage for dynamic cwd resolution
I don’t see any existing tests exercising the new dynamic
cwd
logic insrc/index.ts
. Please add unit tests that cover both scenarios:
- Context-provided cwd:
useRuleContext()
returns an object with a customcwd
.- Fallback to process.cwd():
useRuleContext()
isundefined
or missing acwd
property.Pinpoint for testing:
- File:
src/index.ts
- Lines: ~84–86 (where
cwd
is determined and passed tonormalizeOptions
)Ensure your tests mock
useRuleContext
and verify thatnormalizeOptions
receives the correct directory in each case.🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 84-85: src/index.ts#L84-L85
Added lines #L84 - L85 were not covered by tests
A summary of the edits CodeRabbit can apply:
A plan of each step that CodeRabbit will take in order to execute the edits for each file (with inline rough draft snippets): 📄 tests/unit/context-aware.spec.tsimport { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { type ResolvedResult } from 'eslint-import-context'
// Mock eslint-import-context module
vi.mock('eslint-import-context', () => {
let mockContext: { cwd?: string } | null = null
return {
useRuleContext: vi.fn(() => mockContext),
__setMockContext: (context: { cwd?: string } | null) => {
mockContext = context
},
__getMockContext: () => mockContext,
}
})
import { resolve, createTypeScriptImportResolver } from 'eslint-import-resolver-typescript'
import { useRuleContext } from 'eslint-import-context'
// Type assertion for our mock module
const mockModule = await import('eslint-import-context') as any
describe('Context-aware import resolution', () => {
const originalCwd = process.cwd()
const testCwd1 = '/test/project1'
const testCwd2 = '/test/project2'
beforeEach(() => {
vi.clearAllMocks()
mockModule.__setMockContext(null)
})
afterEach(() => {
mockModule.__setMockContext(null)
})
describe('Dynamic cwd resolution', () => {
it('should use context.cwd when available', () => {
const mockResolve = vi.fn().mockReturnValue({ found: false })
vi.doMock('unrs-resolver', () => ({
ResolverFactory: vi.fn().mockImplementation(() => ({
sync: mockResolve
}))
}))
mockModule.__setMockContext({ cwd: testCwd1 })
resolve('some-module', '/test/file.ts', {})
expect(useRuleContext).toHaveBeenCalled()
// Verify that the resolver was created with options normalized for testCwd1
})
it('should fallback to process.cwd() when context is null', () => {
const mockResolve = vi.fn().mockReturnValue({ found: false })
vi.doMock('unrs-resolver', () => ({
ResolverFactory: vi.fn().mockImplementation(() => ({
sync: mockResolve
}))
}))
mockModule.__setMockContext(null)
resolve('some-module', '/test/file.ts', {})
expect(useRuleContext).toHaveBeenCalled()
// Verify that process.cwd() was used as fallback
})
it('should fallback to process.cwd() when context.cwd is undefined', () => {
const mockResolve = vi.fn().mockReturnValue({ found: false })
vi.doMock('unrs-resolver', () => ({
ResolverFactory: vi.fn().mockImplementation(() => ({
sync: mockResolve
}))
}))
mockModule.__setMockContext({})
resolve('some-module', '/test/file.ts', {})
expect(useRuleContext).toHaveBeenCalled()
// Verify that process.cwd() was used as fallback
})
})
describe('Cache key generation', () => {
it('should generate cache key with null character separator', () => {
const mockResolverFactory = vi.fn()
const resolverCache = new Map()
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => ({
sync: vi.fn().mockReturnValue({ found: false })
}))
}))
mockModule.__setMockContext({ cwd: testCwd1 })
// First call should create resolver with cache key containing null character
resolve('some-module', '/test/file.ts', {})
// Verify that cache key includes cwd with null character separator
expect(mockResolverFactory).toHaveBeenCalledTimes(1)
})
it('should create separate cache entries for different cwd values', () => {
const mockResolverFactory = vi.fn()
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => ({
sync: vi.fn().mockReturnValue({ found: false })
}))
}))
// First resolution with testCwd1
mockModule.__setMockContext({ cwd: testCwd1 })
resolve('some-module', '/test/file.ts', {})
// Second resolution with testCwd2 should create new resolver
mockModule.__setMockContext({ cwd: testCwd2 })
resolve('some-module', '/test/file.ts', {})
expect(mockResolverFactory).toHaveBeenCalledTimes(2)
})
it('should reuse cache for same cwd and options', () => {
const mockResolverFactory = vi.fn()
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => ({
sync: vi.fn().mockReturnValue({ found: false })
}))
}))
mockModule.__setMockContext({ cwd: testCwd1 })
// Multiple resolutions with same cwd should reuse cache
resolve('some-module', '/test/file1.ts', {})
resolve('another-module', '/test/file2.ts', {})
expect(mockResolverFactory).toHaveBeenCalledTimes(1)
})
})
describe('createTypeScriptImportResolver context switching', () => {
it('should update cwd and recreate resolver when context changes', () => {
const mockResolverFactory = vi.fn()
const mockCloneWithOptions = vi.fn()
const mockResolver = {
sync: vi.fn().mockReturnValue({ found: false }),
cloneWithOptions: mockCloneWithOptions
}
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => mockResolver)
}))
// Initially no context
mockModule.__setMockContext(null)
const resolver = createTypeScriptImportResolver({ project: ['./tsconfig.json'] })
// First resolution - should use process.cwd()
resolver.resolve('some-module', '/test/file.ts')
// Change context cwd
mockModule.__setMockContext({ cwd: testCwd1 })
// Second resolution - should detect cwd change and update resolver
resolver.resolve('another-module', '/test/file.ts')
expect(useRuleContext).toHaveBeenCalledTimes(2)
expect(mockCloneWithOptions).toHaveBeenCalled()
})
it('should create new resolver when no existing resolver and context changes', () => {
const mockResolverFactory = vi.fn()
const mockResolver = {
sync: vi.fn().mockReturnValue({ found: false })
}
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => mockResolver)
}))
mockModule.__setMockContext(null)
const resolver = createTypeScriptImportResolver({ project: ['./tsconfig.json'] })
// Change context before first resolution
mockModule.__setMockContext({ cwd: testCwd1 })
resolver.resolve('some-module', '/test/file.ts')
expect(mockResolverFactory).toHaveBeenCalled()
})
it('should not recreate resolver when cwd remains the same', () => {
const mockResolverFactory = vi.fn()
const mockCloneWithOptions = vi.fn()
const mockResolver = {
sync: vi.fn().mockReturnValue({ found: false }),
cloneWithOptions: mockCloneWithOptions
}
vi.doMock('unrs-resolver', () => ({
ResolverFactory: mockResolverFactory.mockImplementation(() => mockResolver)
}))
mockModule.__setMockContext({ cwd: testCwd1 })
const resolver = createTypeScriptImportResolver({ project: ['./tsconfig.json'] })
// Multiple resolutions with same cwd
resolver.resolve('some-module', '/test/file1.ts')
resolver.resolve('another-module', '/test/file2.ts')
expect(useRuleContext).toHaveBeenCalledTimes(2)
expect(mockCloneWithOptions).not.toHaveBeenCalled()
})
it('should handle interfaceVersion and name properties correctly', () => {
mockModule.__setMockContext(null)
const resolver = createTypeScriptImportResolver()
expect(resolver.interfaceVersion).toBe(3)
expect(resolver.name).toBe('eslint-import-resolver-typescript')
})
})
describe('Function signature compatibility', () => {
it('should handle optional parameters correctly in resolve function', () => {
mockModule.__setMockContext({ cwd: testCwd1 })
// Test with all parameters
expect(() => resolve('module', '/file.ts', {}, null)).not.toThrow()
// Test with minimal parameters
expect(() => resolve('module', '/file.ts')).not.toThrow()
// Test with undefined options
expect(() => resolve('module', '/file.ts', undefined)).not.toThrow()
})
it('should handle optional parameters correctly in createTypeScriptImportResolver', () => {
mockModule.__setMockContext(null)
// Test with options
expect(() => createTypeScriptImportResolver({})).not.toThrow()
// Test without options
expect(() => createTypeScriptImportResolver()).not.toThrow()
// Test with null options
expect(() => createTypeScriptImportResolver(null)).not.toThrow()
})
})
}) A summary of the context that CodeRabbit is considering across the codebase:
|
Creating a PR to execute the edits.... The changes have been created in this pull request: View PR |
| datasource | package | from | to | | ---------- | --------------------------------- | ----- | ----- | | npm | eslint-import-resolver-typescript | 4.3.4 | 4.4.0 | ## [v4.4.0](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#440) ##### Minor Changes - [#453](import-js/eslint-import-resolver-typescript#453) [`7d87517`](import-js/eslint-import-resolver-typescript@7d87517) Thanks [@JounQin](https://github.com/JounQin)! - feat: integrate `eslint-import-context` to get correct `context.cwd` ## [v4.3.5](https://github.com/import-js/eslint-import-resolver-typescript/blob/HEAD/CHANGELOG.md#435) ##### Patch Changes - [#450](import-js/eslint-import-resolver-typescript#450) [`3f1aab1`](import-js/eslint-import-resolver-typescript@3f1aab1) Thanks [@JounQin](https://github.com/JounQin)! - fix: remove buggy `module-sync` exports field
related import-js/eslint-plugin-import#2108
Important
Integrate
eslint-import-context
to handlecontext.cwd
in import resolution, update dependencies and scripts, and adjust tests.eslint-import-context
insrc/index.ts
to correctly handlecontext.cwd
for import resolution.resolve()
andcreateTypeScriptImportResolver()
to usecontext.cwd
.eslint-import-context
topackage.json
dependencies.debug
,get-tsconfig
,unrs-resolver
, and several devDependencies inpackage.json
.build:ts
script inpackage.json
to usetsc -p src
.build:tsdown
andclean
scripts inpackage.json
.tests/e2e/withJsExtension/test.cjs
to disable eslint rule for import extensions.tests/unit/unit.spec.ts
to include a timeout forpnp
test and update snapshots.index.d.cts
andtsconfig.staged.json
files.tsconfig.lib.json
for TypeScript configuration.This description was created by
for 2b346d7. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
New Features
Chores