Skip to content

@typescript-eslint/rule-tester: Support for custom cwd in test configuration #11668

@conarti

Description

@conarti

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 cwd option in RuleTesterConfig
  • The linter is created internally with a computed basePath based on tsconfigRootDir and filename
  • Custom working directories cannot be set for test scenarios

Use Case

We have ESLint rules that need to:

  1. Resolve alias imports (e.g., @/ mapped to src/)
  2. Work with specific project structures that depend on context.getCwd()
  3. 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:

  1. Added to RuleTesterConfig interface
  2. Passed to the Linter constructor instead of the computed basePath when explicitly set

Environment

  • @typescript-eslint/rule-tester: ^8.45.0
  • eslint: ^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

No one assigned

    Labels

    blocked by external 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 package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions