feat(linter): Implement react/no-clone-element rule.#20129
feat(linter): Implement react/no-clone-element rule.#20129graphite-app[bot] merged 1 commit intomainfrom
react/no-clone-element rule.#20129Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new React lint rule to discourage usage of React.cloneElement/cloneElement, integrating it into the linter’s React plugin and snapshot-based test suite.
Changes:
- Implement
react/no-clone-elementrule with diagnostic messaging and documentation. - Register the rule in the React rules module list and generated rule enums/runners.
- Add snapshot output for rule test cases.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/react/no_clone_element.rs | New rule implementation + inline tests for react/no-clone-element. |
| crates/oxc_linter/src/snapshots/react_no_clone_element.snap | Snapshot output for the new rule’s diagnostics. |
| crates/oxc_linter/src/rules.rs | Exposes the new React rule module. |
| crates/oxc_linter/src/generated/rules_enum.rs | Registers the rule in the generated enum, IDs, and dispatch. |
| crates/oxc_linter/src/generated/rule_runner_impls.rs | Hooks rule runner to visit CallExpression nodes. |
Merging this PR will not alter performance
Comparing Footnotes
|
Merge activity
|
AI Disclosure: All code in this PR was written by me (docs, diagnostics, tests), excluding the `run` method which I used Claude Code for help with. Fixes #20105. Part of #1022, arguably. This is based on the rule from `@eslint-react/eslint-plugin`: https://www.eslint-react.xyz/docs/rules/no-clone-element You can read about `React.cloneElement` in [the React docs](https://react.dev/reference/react/cloneElement). This intentionally does not handle `require` imports currently. They are supported in the original rule, but I'm not sure they're worth the extra complexity here and almost none of our other react rules handle them either. It also does not handle import aliases like `import { cloneElement as foobar } from 'react';`.
6e74d7f to
1735215
Compare
# Oxlint ### 🚀 Features - 04a5ce0 oxlint: Support `vite.config.ts` `.lint` field (#20214) (leaysgur) - 1735215 linter: Implement `react/no-clone-element` rule. (#20129) (connorshea) - 68e6f6f linter: Implement `react/no-react-children` rule. (#20104) (connorshea) - fe3b32e linter/plugins: Add `oxlint-plugin-eslint` package (#20009) (overlookmotel) ### 🐛 Bug Fixes - 05f6a09 linter/no-inline-comments: Deserialize rule options with serde (#20207) (camc314) - c7eb09d linter/default-case: Deserialize rule options with serde (#20206) (camc314) - f85e16c linter/plugins: Fix types for visitor compilation (#20203) (overlookmotel) - 44e24e0 linter/exhaustive-deps: Ignore type-only typeof deps (#20201) (camc314) - 0b04998 linter/no-fallthrough: Deserialize rule options with serde (#20192) (camc314) - a1031cb linter/new-cap: Deserialize rule options with serde (#20161) (camc314) - ad27fd6 linter: Add help messages to import plugin diagnostics (#20158) (John Costa) - 1340307 linter/plugins: Ensure `after` hooks always run (#20167) (overlookmotel) - c4812ec linter/plugins: Reset visitor compilation state if error during compilation (#20166) (overlookmotel) - 887eecc linter/plugins: Add license notice to `oxlint-plugin-eslint` package (#20164) (overlookmotel) - e1713a4 linter/plugins: Include common chunks in `oxlint-plugin-eslint` package (#20163) (overlookmotel) - a9acb2b linter: Check `globals` entry for `no-undef`, only check es2026 globals for `no-extend-native` and `no-constant-binary-expression` (#20089) (Sysix) - 5559f0d linter/no-unused-vars: `reportUsedIgnorePattern` should not report used rest siblings (#20108) (Don Isaac) - de7c0e2 linter/plugins: Correct error message for `markVariableAsUsed` (#20152) (overlookmotel) ### ⚡ Performance - 3a86427 linter/plugins: Pre-populate cache of `EnterExit` objects at startup (#20194) (overlookmotel) - d243391 linter/plugins: Replace arrays with `Uint8Array`s (#20190) (overlookmotel) - 8742f8b linter/plugins: Pre-populate cache of `VisitProp` objects (#20189) (overlookmotel) - 3061acb linter/plugins: Pre-populate cache of `EnterExit` objects (#20187) (overlookmotel) - c73912b linter/plugins: Free visit functions earlier (#20186) (overlookmotel) - d9f8ff4 linter/plugins: Faster reset of visitor state (#20185) (overlookmotel) - 42aff15 oxlint/lsp: Avoid computing diagnostics for non invoked code actions requests (#20080) (Sysix) ### 📚 Documentation - a080650 linter/plugins: Fix documentation of visitor compilation (#20202) (overlookmotel) - 542a04a linter: Add a link to the cyclomatic complexity Wikipedia article in `eslint/complexity` (#20174) (connorshea) # Oxfmt ### 🚀 Features - 95943aa oxfmt: Support `vite.config.*` `.fmt` field (#20197) (leaysgur) - 172fc07 oxfmt: .js/.ts config file support (#20135) (leaysgur) ### 🐛 Bug Fixes - e483569 oxfmt: Avoid double-escaping in css-in-js (#20211) (leaysgur) Co-authored-by: leaysgur <6259812+leaysgur@users.noreply.github.com>
AI Disclosure: All code in this PR was written by me (docs, diagnostics, tests), excluding the
runmethod which I used Claude Code for help with.Fixes #20105. Part of #1022, arguably.
This is based on the rule from
@eslint-react/eslint-plugin: https://www.eslint-react.xyz/docs/rules/no-clone-elementYou can read about
React.cloneElementin the React docs.This intentionally does not handle
requireimports currently. They are supported in the original rule, but I'm not sure they're worth the extra complexity here and almost none of our other react rules handle them either. It also does not handle import aliases likeimport { cloneElement as foobar } from 'react';.