Skip to content

feat: port rule react/checked-requires-onchange-or-readonly#1030

Merged
fansenze merged 2 commits into
mainfrom
feat/port-rule-checked_requires_onchange_or_readonly-20260527
May 27, 2026
Merged

feat: port rule react/checked-requires-onchange-or-readonly#1030
fansenze merged 2 commits into
mainfrom
feat/port-rule-checked_requires_onchange_or_readonly-20260527

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

Summary

Port the react/checked-requires-onchange-or-readonly rule from eslint-plugin-react to rslint.

It enforces that an <input> (or React.createElement('input', ...)) using checked also has onChange or readOnly, and forbids combining checked with defaultChecked.

Achieving full upstream parity required aligning the shared reactutil.IsCreateElementCall detector with eslint-plugin-react's isCreateElement:

  • accept optional-chain pragma access (React?.createElement(...));
  • reject parenthesized optional chains ((React?.createElement)(...)) and TS-wrapped pragmas ((React as any).createElement(...)), which upstream does not recognize.

These were differential-verified against eslint-plugin-react. The same divergence affected no_unstable_nested_components (which uses the same detector), so its two TS-wrapper test cases were corrected to match upstream.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Full parity required aligning the shared reactutil.IsCreateElementCall detector with upstream: accept optional-chain pragma (React?.createElement), reject parenthesized optional chains and TS-wrapped pragmas ((React as any).createElement). no_unstable_nested_components shared the same divergence and is corrected to match.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the new react/checked-requires-onchange-or-readonly rule, which ensures that checked attributes on <input> elements are accompanied by either onChange or readOnly attributes. It also refactors the pragma factory call detection logic in create_element.go to align with ESLint's handling of parenthesized optional chains and TS expression wrappers. The review feedback highlights several critical areas where missing nil checks on AST nodes (resulting from parser recovery on malformed syntax) could lead to nil pointer dereference panics. Code suggestions were provided to safely handle these edge cases.

Comment thread internal/plugins/react/reactutil/create_element.go Outdated
Comment thread internal/plugins/react/reactutil/create_element.go
Defensive: if a parenthesized callee flattens to nil (only possible for the empty-parens `()` syntax-error shape, which rslint does not lint), return early instead of nil-dereferencing through IsOptionalChain / callee.Kind.
@fansenze fansenze merged commit b289093 into main May 27, 2026
24 of 26 checks passed
@fansenze fansenze deleted the feat/port-rule-checked_requires_onchange_or_readonly-20260527 branch May 27, 2026 08:38
eryue0220 added a commit to eryue0220/rslint that referenced this pull request May 27, 2026
… into feat/no-duplicate-hooks

* 'feat/no-duplicate-hooks' of github.com:eryue0220/rslint:
  test(eslint-plugin-runner): skip worker-pool e2e suites on windows (napi terminate aborts) (web-infra-dev#1031)
  feat: port rule react/checked-requires-onchange-or-readonly (web-infra-dev#1030)
  chore(deps): update actions/checkout action to v6 (web-infra-dev#1007)
  chore(deps): update actions/setup-go action to v6 (web-infra-dev#1009)
  chore(deps): update actions/setup-node action to v6 (web-infra-dev#1010)
  feat: port rule @stylistic/jsx-indent-props (web-infra-dev#1028)
  feat(eslint-plugin-runner): new package for ESLint plugin compatibility runtime (web-infra-dev#991)
  feat: port rule @stylistic/jsx-function-call-newline (web-infra-dev#1027)
  feat(eslint-plugin-jest): add `prefer-called-with` rule (web-infra-dev#1025)
  feat: port rule @stylistic/jsx-first-prop-new-line (web-infra-dev#1024)
  feat: port rule @stylistic/jsx-curly-spacing (web-infra-dev#1023)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant