feat(linter): add allow and allowPattern options to react/capitalized-calls

Closed
CH
1mo ago
+308-19

What this PR does

Adds two options to react/capitalized-calls that feed the React Compiler's validateNoCapitalizedCalls environment option:

  • allow: string[]: exact names of capitalized functions that may be called directly, forwarded as the validateNoCapitalizedCalls entries.
  • allowPattern: string: a regex checked next to the allowlist inside the validation, for codebases where the allowed factories follow a naming convention.
"react/capitalized-calls": ["error", { "allowPattern": "Event$" }]

Why

The rule currently has no way to allowlist anything. The upstream ESLint plugin accepts per-rule options and merges them into the compiler options, so validateNoCapitalizedCalls is reachable there, but Oxlint's shared compiler run uses fixed options and nothing gets through.

That hurts codebases with naming conventions for capitalized non-component factories. Concretely: our company's monorepo has ~2,900 inline oxlint-disable-next-line react/capitalized-calls comments across ~1,600 files, almost all of them on generated analytics-event builders (...FooClickedEvent() spreads). Exact names don't scale to thousands of generated factories, which is what allowPattern is for.

How

The linter extracts the rule's resolved options in Linter::run and hands them to ContextHost, where the shared React Compiler run picks them up when it is built. The run still varies only with resolved config, never with which rules execute, so the single shared run stays valid for every rule in the family. allowPattern is a small oxc-side extension to EnvironmentConfig, checked in validate_no_capitalized_calls in the same place as the names allowlist.

One behavior note: same as the upstream compiler, the allowlist only applies to global loads. Method calls like obj.Child() are flagged from PropertyLoad/MethodCall, which has no allowlist, so they cannot be exempted. A test pins that.

Testing

  • cargo test -p oxc_linter capitalized_calls covers both options (exact name, anchored pattern, suffix pattern, one name does not allow others, method calls stay flagged under an allowlist), snapshot updated.
  • cargo test -p oxc_react_compiler passes.
  • cargo lintgen, schema and TS config types regenerated (just linter-schema-json, just linter-config-ts), cargo lint-timings unchanged.

Disclosure

This PR was implemented with Claude Code (AI assistance) and has been reviewed, tested, and is understood by the submitting contributor.