Skip to content

fix: getTestInfo detects NewExpression and CallExpression depending on ruleTesterConstructors settings - #657

Merged
aladdin-add merged 5 commits into
eslint-community:mainfrom
Vinccool96:bug/654-getTestInfo-better-recognition
Aug 15, 2026
Merged

fix: getTestInfo detects NewExpression and CallExpression depending on ruleTesterConstructors settings#657
aladdin-add merged 5 commits into
eslint-community:mainfrom
Vinccool96:bug/654-getTestInfo-better-recognition

Conversation

@Vinccool96

Copy link
Copy Markdown
Contributor

What is the purpose of this pull request?

Extends getTestInfo to capture NewExpression and CallExpression with name ending in RuleTester

What changes did you make? (Give an overview)

CallExpression is now a valid option to create a RuleTester

Accepted class and function names end in RuleTester instead of only being RuleTester

Related Issues

Fixes #654

Is there anything you'd like reviewers to focus on?

💖

Comment thread lib/utils.ts Outdated
(node.callee.type === 'MemberExpression' &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === 'RuleTester'))
node.callee.property.name.endsWith('RuleTester')))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure whether endsWith is the correct check here
The function to create a RuleTester in typescript-eslint is called createRuleTesterWithTypes, which, IMO, is a reasonable name

Maybe we can add support for settings['eslint-plugin'].additionalRuleTesterConstructors or something similar instead?

(Anyway, if it's too much work, we can probably just rename the function on our end 😄)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What do you think should be the check? I'm not sure I should try to parse all used methods to find what they return, nor all classes to see what they extend.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the idea! something like:

{
  settings: {
   "eslint-plugin": {
      "RuleTesterConstructors": ["RuleTester"] // the default, can be configured to other names.
    }
  }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we just need to check the function names - ESLint is designed to check individual files; if the rule tester is defined in another file, static analysis is not possible.

@Vinccool96 Vinccool96 Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That is a good idea. Do I create two options, one for constructors (ruleTester = new ClassName()) and one for functions (ruleTester = creatorFunction())?

Where in the docs do I put the info for the shared settings? Can every rule related to RuleTester override the settings?

@Vinccool96

Copy link
Copy Markdown
Contributor Author

@aladdin-add @StyleShit I would like to know four things:

  1. Do I create two options, one for constructors (ruleTester = new ClassName()) and one for functions (ruleTester = creatorFunction())?
  2. What are the names of the options?
  3. Can every rule related to RuleTester override the settings?
  4. Where in the docs do I put the info for the shared settings?

@StyleShit

Copy link
Copy Markdown
Contributor
  1. IMO we can have one
  2. @aladdin-add suggested RuleTesterConstructors, sound good to me
  3. Not sure what you mean
  4. I don't think there are currently settings in eslint-plugin-eslint-plugin, so it can probably have its own section. See eslint-plugin-import as a reference https://github.com/import-js/eslint-plugin-import#settings

@aladdin-add

Copy link
Copy Markdown
Contributor

3. Can every rule related to RuleTester override the settings?

I don’t really see the necessity for this at the moment. We can skip it for now, and if needed, we can always add it later.

@aladdin-add aladdin-add left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for updating! the changes look good to me, we just need:

  • revert the change: a8e9dbd
  • add a section in docs.

@aladdin-add
aladdin-add requested review from StyleShit and a lite review from Copilot and removed request for StyleShit August 14, 2026 18:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 extends the getTestInfo static analysis utility so it can recognize additional ways of constructing a RuleTester (including factory calls), and updates tests to cover configurable constructor matching and avoid new false positives in “not a RuleTester” fixtures.

Changes:

  • Added support for treating both NewExpression and CallExpression as potential RuleTester constructions, driven by a new settings['eslint-plugin'].ruleTesterConstructors option.
  • Implemented settings extraction/validation helpers and threaded the resolved options through getTestInfo’s recursive AST scanning.
  • Expanded and adjusted test coverage for settings-driven behavior; updated “Not RuleTester” fixtures to avoid suffix-based matches.

Reviewed changes

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

Show a summary per file
File Description
lib/utils.ts Adds settings parsing/validation and expands RuleTester-construction detection logic.
tests/lib/utils.ts Expands getTestInfo tests across multiple settings permutations and constructor patterns.
tests/lib/rules/test-case-shorthand-strings.ts Renames “Not RuleTester” fixture to avoid new suffix-based detection.
tests/lib/rules/test-case-property-ordering.ts Same fixture rename for suffix-based detection avoidance.
tests/lib/rules/prefer-output-null.ts Same fixture rename for suffix-based detection avoidance.
tests/lib/rules/no-only-tests.ts Same fixture rename for suffix-based detection avoidance.
tests/lib/rules/no-identical-tests.ts Same fixture rename for suffix-based detection avoidance.
tests/lib/rules/consistent-output.ts Same fixture rename for suffix-based detection avoidance.
Suppressed comments (1)

tests/lib/utils.ts:1142

  • Same as above: JSON.stringify(settings) in the test title won’t include RegExp values, which can lead to duplicate/unclear test names. Use a replacer to preserve regexes.
          it(`${testSource} with options ${JSON.stringify(settings)}`, () => {

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/utils.ts Outdated
Comment thread lib/utils.ts
Comment thread tests/lib/utils.ts Outdated
Comment thread tests/lib/utils.ts Outdated
Comment thread lib/utils.ts
@Vinccool96 Vinccool96 changed the title fix: getTestInfo detects NewExpression and CallExpression with name ending in RuleTester fix: getTestInfo detects NewExpression and CallExpression depending on ruleTesterConstructors settings Aug 15, 2026
@Vinccool96

Copy link
Copy Markdown
Contributor Author

I have WebStorm instead of VSCode, so I have no idea what to do with the ToC of the Readme

@Vinccool96
Vinccool96 requested a review from aladdin-add August 15, 2026 18:37

@aladdin-add aladdin-add left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@aladdin-add
aladdin-add merged commit f277bff into eslint-community:main Aug 15, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getTestInfo only recognizes new RuleTester

4 participants