Commit 08d68a5
feat(linter/react): implement
Related to #1022
### AI usage disclosure
I used Claude Code to help document the code, navigate the codebase to
find the exact AST kinds I needed, work through the `elementOverrides`
resolution logic, diagnose a few failing test cases, and generate this
PR description. All code has been reviewed and tested by me.
### What this does
Adds the `react/jsx-no-literals` rule ([eslint-plugin-react
equivalent](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-literals.md)),
which flags unwrapped string literals used as JSX children or
string-valued props. Tracked under #1022.
- **Category:** `restriction` (opt-in; only meaningful for codebases
enforcing i18n)
- **Fix:** `none` (no safe mechanical transform exists)
### Implemented options
| Option | Notes |
| --- | --- |
| `noStrings` | Flags string/template literals inside `{...}` containers
and props, including string concatenation (`{'foo' + bar}`). |
| `allowedStrings` | Whitelist, compared on trimmed values. |
| `ignoreProps` | Skips attribute checks. |
| `noAttributeStrings` | Flags string-literal attribute values. |
| `restrictedAttributes` | Flags string literals only on the named
attributes. |
| `elementOverrides` | Per-element option overrides, including
`allowElement` and `applyToNestedElements`. Override keys resolve
through import aliases (`import { T as U }`), `require` destructuring,
member-expression tags (`<T.U>`), and the bare-property fallback
(`React.Fragment` matches a `Fragment` override). |
### Notes
- JSX fragments (`<>…</>`) are handled in addition to elements.
- Diagnostics are tailored per situation (literal text child, string
literal in JSX, restricted attribute) rather than a single generic
message.
- The rule config is boxed so `RuleEnum` stays pointer-sized
(`size_asserts` passes).
### Known limitations
- HTML-entity handling for `allowedStrings` (` `, `—`)
compares against `JSXText.value`; some entity edge cases may need
`JSXText.raw`.
---------
Co-authored-by: Kapobajza <[email protected]>
Co-authored-by: Cameron Clark <[email protected]>jsx-no-literals rule (#23145)1 parent 9a2788b commit 08d68a5
8 files changed
Lines changed: 2696 additions & 1 deletion
File tree
- apps/oxlint/src-js/package
- crates/oxc_linter/src
- generated
- rules/react
- snapshots
- npm/oxlint
- tasks/website_linter/src/snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1172 | 1172 | | |
1173 | 1173 | | |
1174 | 1174 | | |
| 1175 | + | |
1175 | 1176 | | |
1176 | 1177 | | |
1177 | 1178 | | |
| |||
4077 | 4078 | | |
4078 | 4079 | | |
4079 | 4080 | | |
| 4081 | + | |
| 4082 | + | |
| 4083 | + | |
| 4084 | + | |
| 4085 | + | |
| 4086 | + | |
| 4087 | + | |
| 4088 | + | |
| 4089 | + | |
| 4090 | + | |
| 4091 | + | |
| 4092 | + | |
| 4093 | + | |
| 4094 | + | |
| 4095 | + | |
| 4096 | + | |
| 4097 | + | |
| 4098 | + | |
| 4099 | + | |
| 4100 | + | |
| 4101 | + | |
| 4102 | + | |
| 4103 | + | |
| 4104 | + | |
| 4105 | + | |
| 4106 | + | |
| 4107 | + | |
| 4108 | + | |
| 4109 | + | |
| 4110 | + | |
| 4111 | + | |
| 4112 | + | |
| 4113 | + | |
| 4114 | + | |
| 4115 | + | |
| 4116 | + | |
| 4117 | + | |
| 4118 | + | |
| 4119 | + | |
| 4120 | + | |
| 4121 | + | |
| 4122 | + | |
| 4123 | + | |
| 4124 | + | |
| 4125 | + | |
| 4126 | + | |
| 4127 | + | |
| 4128 | + | |
| 4129 | + | |
| 4130 | + | |
| 4131 | + | |
| 4132 | + | |
| 4133 | + | |
| 4134 | + | |
| 4135 | + | |
| 4136 | + | |
| 4137 | + | |
| 4138 | + | |
| 4139 | + | |
| 4140 | + | |
| 4141 | + | |
| 4142 | + | |
| 4143 | + | |
| 4144 | + | |
4080 | 4145 | | |
4081 | 4146 | | |
4082 | 4147 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
428 | 428 | | |
429 | 429 | | |
430 | 430 | | |
| 431 | + | |
431 | 432 | | |
432 | 433 | | |
433 | 434 | | |
| |||
0 commit comments