-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as not planned
Closed as not planned
Copy link
Labels
blocked by external APIBlocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship APIBlocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship APIpackage: rule-testerIssues related to the @typescript-eslint/rule-tester packageIssues related to the @typescript-eslint/rule-tester package
Description
Description
@typescript-eslint/rule-tester does not provide a way to set custom cwd for the linter used in tests. This makes it impossible to test rules that depend on path resolution with custom working directories or alias imports (like @/).
Expected Behavior
The RuleTesterConfig should support a cwd option that would be passed to the Linter constructor, similar to how it works in ESLint core.
const ruleTester = new RuleTester({
languageOptions: { /* ... */ },
cwd: '/custom/working/directory',
});Current Behavior
- There is no
cwdoption inRuleTesterConfig - The linter is created internally with a computed
basePathbased ontsconfigRootDirand filename - Custom working directories cannot be set for test scenarios
Use Case
We have ESLint rules that need to:
- Resolve alias imports (e.g.,
@/mapped tosrc/) - Work with specific project structures that depend on
context.getCwd() - Test behavior with different working directories
Workaround
Currently, we have to skip tests that require custom cwd:
describe.skip('tests with custom cwd', () => {
// Tests that need custom cwd
});Implementation Suggestion
The Linter is created in #getLinterForFilename method. The cwd could be:
- Added to
RuleTesterConfiginterface - Passed to the
Linterconstructor instead of the computedbasePathwhen explicitly set
Environment
@typescript-eslint/rule-tester: ^8.45.0eslint: ^9.11.1- Node.js: v22.18.0
Would appreciate any guidance or if there's an existing way to achieve this that I'm missing!
Metadata
Metadata
Assignees
Labels
blocked by external APIBlocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship APIBlocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship APIpackage: rule-testerIssues related to the @typescript-eslint/rule-tester packageIssues related to the @typescript-eslint/rule-tester package