fix(no-export): check for exports global#1988
Open
G-Rath wants to merge 1 commit into
Open
Conversation
Co-authored-by: eryue0220 <eryue0220@gmail.com>
LogDetails |
There was a problem hiding this comment.
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
exportsidentifier (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 on lines
53
to
+57
| if (object.type === AST_NODE_TYPES.MemberExpression) { | ||
| ({ object, property } = object); | ||
| } | ||
|
|
||
| if (object.type !== AST_NODE_TYPES.Identifier) { |
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)) | ||
| ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1986