Skip to content

Bug: one-var separateRequires misidentifies shadowed require calls #21180

Closed

Description

@sethamus

Environment

Node version:
npm version:
Local ESLint version:
Global ESLint version:
Operating System:

What parser are you using?

Default (Espree)

What did you do?

Configuration
export default [
	{
		rules: {
			"one-var": [
				"error",
				{
					separateRequires: true,
					const: "always",
				},
			],
		},
	},
];
function foo(require) {
	const bar = require("bar"), baz = "baz";
}

What did you expect to happen?

No lint errors. The require function parameter shadows the global require, so this is not a CommonJS require() call.

What actually happened?

Split requires to be separated into a single block.

Link to Minimal Reproducible Example

https://eslint.org/play/#eyJ0ZXh0IjoiLyogZXNsaW50IG9uZS12YXI6IFtcImVycm9yXCIsIHsgc2VwYXJhdGVSZXF1aXJlczogdHJ1ZSwgY29uc3Q6IFwiYWx3YXlzXCIgfV0gKi9cblxuZnVuY3Rpb24gZm9vKHJlcXVpcmUpIHtcblx0Y29uc3QgYmFyID0gcmVxdWlyZShcImJhclwiKSwgYmF6ID0gXCJiYXpcIjtcbn0iLCJvcHRpb25zIjp7InJ1bGVzIjp7fSwibGFuZ3VhZ2VPcHRpb25zIjp7InBhcnNlck9wdGlvbnMiOnsiZWNtYUZlYXR1cmVzIjp7fX19fX0=

Participation

  • I am willing to submit a pull request for this issue.

AI acknowledgment

  • I did not use AI to generate this issue report.
  • (If the above is not checked) I have reviewed the AI-generated content before submitting.

Additional comments

No response

Activity

  1. added
    bugESLint is working incorrectly
    repro:neededThis issue should include a reproducible example
    on Aug 1, 2026
  2. moved this to Needs Triage in Triageon Aug 1, 2026
  3. DMartens commented on Aug 1, 2026

    @DMartens
    Contributor

    I agree that we should require that the require should resolve to a global.
    Should we also require sourceType: commonjs?
    Feel free to open a PR for this.

  4. moved this from Needs Triage to Ready to Implement in Triageon Aug 1, 2026
  5. added
    acceptedThere is consensus among the team that this change meets the criteria for inclusion
    repro:yesIssues with a reproducible example
    and removed
    repro:neededThis issue should include a reproducible example
    on Aug 1, 2026
  6. eslint-github-bot commented on Aug 2, 2026

    @eslint-github-bot

    👋 Hi! This issue is being addressed in pull request #21181. Thanks, @aalhadxx!

  7. eslint-github-bot commented on Aug 6, 2026

    @eslint-github-bot

    👋 Hi! This issue is being addressed in pull request #21192. Thanks, @sethamus!

  8. sethamus commented on Aug 6, 2026

    @sethamus
    ContributorAuthor

    Should we also require sourceType: commonjs?

    The rule is frozen, so I don't think we can make that change.

  9. moved this from Ready to Implement to Implementing in Triageon Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionbugESLint is working incorrectlyrepro:yesIssues with a reproducible example

Type

No type

Projects

  • Status
    Complete

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions