fix(no-implicit-declare-namespace-export): skip module augmentations - #1484
fix(no-implicit-declare-namespace-export): skip module augmentations#1484SAY-5 wants to merge 2 commits into
Conversation
|
|
Per denoland/deno#33268, the rule fires on a top-level `declare global { ... }` block and tells users to add `export {}` to suppress it. But TypeScript explicitly rejects `export {}` inside `declare global` ("Exports and export assignments are not permitted in module augmentations"), so the suggested fix doesn't compile. Bail out of the rule when the module declaration's `global` flag is set so the hint is no longer surfaced for these blocks. Add valid-case tests covering `declare global { const ... }` and `declare global { interface Window ... }`. Closes denoland/deno#33268
abfe94e to
1ee9471
Compare
`declare module "foo" { ... }` is a module augmentation when the surrounding
file is itself a module (has a top-level import/export), and TypeScript rejects
`export {}` inside it just like `declare global` (TS2669). Skip those so the
hint does not suggest a fix that fails to compile.
In a plain ambient script, `declare module "foo"` is a real ambient module
declaration where `export {}` is valid, so the rule still fires there.
declare global blocks|
@SAY-5 can you please sign the CLA? |
|
Verdict: LGTM — correct, well-tested fix. Recommend a maintainer merge (rule-behavior change + This fixes a real footgun: the rule told users to add Correctness — verified all branches
Test coverage — good Perf — minor Housekeeping: No changes requested. Good to merge once a maintainer approves; it's a clean false-positive fix aligned with TS semantics. |
Per denoland/deno#33268, the
no-implicit-declare-namespace-exportrulefires on ambient blocks that are module augmentations and tells users to add
export {}to suppress it. TypeScript rejectsexport {}/export { ... }inside an augmentation (TS2669 "Exports and export assignmentsare not permitted in module augmentations"), so the suggested fix does not
compile — the rule effectively makes those blocks unlintable without an ignore
pragma.
This skips a
declaremodule declaration when it is an augmentation:declare global { ... }is unconditionally a global-scope augmentation, soit is always skipped.
declare module "foo" { ... }is an augmentation only when the surroundingfile is itself a module (has a top-level
import/export); those areskipped too. In a plain ambient script,
declare module "foo"is a realambient module declaration where members are implicitly exported and
export {}is valid, so the rule still fires there.Repro (before this PR)
Tests
declare global { ... }blocks, and adeclare module "foo" { ... }augmentation in a module file (top-level
export {}).declare module "foo" { ... }in a script file still fires, sincethere it is an ambient module declaration rather than an augmentation.
Closes denoland/deno#33268