Skip to content

fix: detect imported any in restrict-plus-operands - #1287

Merged
fireairforce merged 2 commits into
mainfrom
zoomdong-1285-imported-any-operands
Sep 26, 2026
Merged

fireairforce merged 2 commits into
mainfrom
zoomdong-1285-imported-any-operands

Conversation

@fireairforce

@fireairforce fireairforce commented Sep 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #1285.

  • Read explicit value and function return annotations from named imports in relative TypeScript modules, including function-valued constants and declaration files.
  • Prefer TypeScript source and declaration files over JavaScript implementations when resolving these imported types.
  • Feed imported type hints into @typescript-eslint/restrict-plus-operands so allowAny: false catches imported any values and call results while preserving shadowing and typeof narrowing.

Test Plan

  • zig fmt --check build.zig src tests
  • zig build test -Doptimize=ReleaseFast -j1 (including 77 rule snapshots)
  • Regression cases cover function and constant imports, aliases, function-valued constants, declaration-only modules, JavaScript plus declaration companions, TypeScript resolution order, numeric controls, narrowing, and shadowing.
  • Reproduced all four issue CLI cases with both files supplied: imported function/constant any each produce one diagnostic; the number controls produce none.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-26T10:05:02.186187Z 082dc55 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 082dc55914

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +179 to +180
const binding = tree.data(declarator.id).binding_identifier;
found.add(.{ .value = annotationType(tree, binding.type_annotation) });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Inspect function-valued exported constants

When a named import refers to a common function-valued constant such as export const readAny = (): any => 1, the binding identifier has no type annotation, so this records an entirely unknown binding and readAny() + 1 remains unreported with allowAny: false. The same omission occurs for const readAny: () => any = ..., because the function type is treated only as an unknown value rather than a callable return type; inspect the initializer or callable annotation and populate return_type for these declarations.

Useful? React with 👍 / 👎.

Comment on lines +54 to +55
const source = import_export_map.importSource(tree, declaration) orelse continue;
const path = try import_export_map.resolveRelativeModule(allocator, io, file_path, source) orelse continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve extensionless imports to declaration files

For import { anyValue } from './values' backed only by values.d.ts, this resolution returns null because the shared resolver probes .ts, .tsx, JavaScript variants, and their index forms but never .d.ts. Consequently, exported declare values and functions annotated as any are skipped even though declaration files are the normal source of imported TypeScript types; this collector needs declaration-file probing for extensionless relative imports.

Useful? React with 👍 / 👎.

@codspeed

codspeed Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 5 untouched benchmarks


Comparing zoomdong-1285-imported-any-operands (6508b8c) with main (cef5b7d)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (9a90490) during the generation of this report, so cef5b7d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@fireairforce
fireairforce merged commit c03bddd into main Sep 26, 2026
5 checks passed
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.

[0.4.6] restrict-plus-operands misses any values and return types imported from another file

1 participant