Skip to content

[eslint-plugin] Don't flag class names in dynamic imports or re-exports (classes-constants)#8158

Open
adityasingh2400 wants to merge 1 commit into
palantir:developfrom
adityasingh2400:fix-6209-eslint-dynamic-import
Open

[eslint-plugin] Don't flag class names in dynamic imports or re-exports (classes-constants)#8158
adityasingh2400 wants to merge 1 commit into
palantir:developfrom
adityasingh2400:fix-6209-eslint-dynamic-import

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

Fixes #6209

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

The classes-constants rule skips string literals that are part of static imports (ImportDeclaration) and named re-exports (ExportNamedDeclaration), so module specifiers are never treated as class-name strings. It did not skip:

  • dynamic imports: import("...") (ImportExpression)
  • re-exports: export * from "..." (ExportAllDeclaration)

So a module specifier that happens to contain a Blueprint-like substring (for example a package whose name contains pt-) was wrongly reported, and --fix would rewrite the import path into a Classes.* constant, breaking the import.

This extends the early-return guard to also skip ImportExpression and ExportAllDeclaration parents.

Reviewers should focus on:

packages/eslint-plugin/src/rules/classes-constants.ts (the guard at the top of create). Two new valid test cases cover a dynamic import and an export * from whose specifiers contain pt-.

@changelog-app

changelog-app Bot commented Jun 9, 2026

Copy link
Copy Markdown

Generate changelog in packages/eslint-plugin/changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

[eslint-plugin] Don't flag class names in dynamic imports or re-exports (classes-constants)

Check the box to generate changelog(s)

  • Generate changelog entry

The classes-constants rule skipped string literals in static imports and named
re-exports, but not in dynamic imports (import("...")) or export-all
re-exports (export * from "..."). A module specifier that happened to contain
a Blueprint-like substring (e.g. a package named "...pt-...") was wrongly
reported and auto-fixed. Extend the guard to also skip ImportExpression and
ExportAllDeclaration parents.

Fixes palantir#6209
@adityasingh2400
adityasingh2400 force-pushed the fix-6209-eslint-dynamic-import branch from c0b4ec3 to fa6db07 Compare June 9, 2026 10:34
@adityasingh2400

Copy link
Copy Markdown
Contributor Author

This change is a Fix. The changelog entry is already committed in this PR at packages/eslint-plugin/changelog/@unreleased/pr-8158.v2.yml, so the @unreleased entry is in place. If you would prefer it be generated through this bot instead, the type is Fix and the description matches the PR title.

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.

Dynamic imports false positive on class-constants ESLint rule

1 participant