Skip to content

fix(no-export): check for exports global - #1988

Merged
G-Rath merged 1 commit into
mainfrom
no-exports-exports
Aug 27, 2026
Merged

G-Rath merged 1 commit into
mainfrom
no-exports-exports

Conversation

@G-Rath

@G-Rath G-Rath commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Resolves #1986

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates the no-export ESLint rule so test files that use CommonJS-style exports are detected more reliably, expanding checks beyond just module.exports usage.

Changes:

  • Extend the rule’s MemberExpression handling to recognize the global exports identifier (while still ignoring locally shadowed bindings via scope resolution).
  • Add tests for exports.* assignment patterns and expand valid examples to ensure non-exports member chains aren’t flagged.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/rules/no-export.ts Expands export detection logic to include global exports and adjusts MemberExpression gating.
src/rules/__tests__/no-export.test.ts Adds coverage for exports.* usage and new valid cases to prevent false positives.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 17 to 21
'module.somethingElse = "foo";',
'my.exports.myThing = "valid";',
'report.myThing = "valid";',
'export const myThing = "valid"',
'export default function () {}',
Comment on lines +104 to +117
{
code: 'exports["invalid"] = function() {}; ; test("a test", () => { expect(1).toBe(1);});',
errors: [{ endColumn: 19, column: 1, messageId: 'unexpectedExport' }],
},
{
code: dedent`
exports.invalid = function () {};

describe('a test', () => {
expect(1).toBe(1);
});
`,
errors: [{ endColumn: 16, column: 1, messageId: 'unexpectedExport' }],
},
Comment thread src/rules/no-export.ts
Comment on lines 53 to +57
if (object.type === AST_NODE_TYPES.MemberExpression) {
({ object, property } = object);
}

if (object.type !== AST_NODE_TYPES.Identifier) {
Comment thread src/rules/no-export.ts
Comment on lines 72 to 76
if (
property.type === AST_NODE_TYPES.Identifier &&
/^exports?$/u.test(property.name)
object.name === 'exports' ||
(property.type === AST_NODE_TYPES.Identifier &&
/^exports?$/u.test(property.name))
) {
Co-authored-by: eryue0220 <eryue0220@gmail.com>
@G-Rath
G-Rath force-pushed the no-exports-exports branch from ba1e806 to c4cab29 Compare August 27, 2026 19:24
@G-Rath
G-Rath merged commit f506cb2 into main Aug 27, 2026
27 checks passed
@G-Rath
G-Rath deleted the no-exports-exports branch August 27, 2026 19:27
github-actions Bot pushed a commit that referenced this pull request Aug 27, 2026
## [29.16.3](v29.16.2...v29.16.3) (2026-08-27)

### Bug Fixes

* **no-export:** check for `exports` global ([#1988](#1988)) ([f506cb2](f506cb2))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 29.16.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants