@shivaedev/quality 0.48.0 → 0.48.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +46 -1
- package/dist/adapters/fixJsxConditionals.d.ts.map +1 -1
- package/dist/adapters/fixJsxConditionals.js +2 -5
- package/dist/adapters/fixJsxConditionals.js.map +1 -1
- package/dist/adapters/knip/configuration.d.ts.map +1 -1
- package/dist/adapters/knip/configuration.js +8 -1
- package/dist/adapters/knip/configuration.js.map +1 -1
- package/dist/rules/react/jsxChildDecision.d.ts +5 -0
- package/dist/rules/react/jsxChildDecision.d.ts.map +1 -0
- package/dist/rules/react/jsxChildDecision.js +74 -0
- package/dist/rules/react/jsxChildDecision.js.map +1 -0
- package/dist/rules/react/jsxConditionals.d.ts.map +1 -1
- package/dist/rules/react/jsxConditionals.js +9 -33
- package/dist/rules/react/jsxConditionals.js.map +1 -1
- package/package.json +3 -3
- package/src/adapters/fixJsxConditionals.ts +2 -8
- package/src/adapters/knip/configuration.ts +8 -1
- package/src/rules/react/jsxChildDecision.ts +84 -0
- package/src/rules/react/jsxConditionals.ts +9 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.48.2 - 2026-10-31
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Limit `react/jsx-conditionals` and its mechanical fix to decisions in returned component JSX. Accept JSX built in a `const` before the return, library callbacks and ternaries between plain string or number literals. Document accepted decisions, attributes, extracted components and list separators.
|
|
8
|
+
|
|
9
|
+
## 0.48.1 - 2026-10-30
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `code/unused` treats numbered migrations in `src/server/migrations` and `src/modules/<module>/server/migrations` as entry points, because migration runners load them from their directory, so apps no longer baseline every migration as an unused file.
|
|
14
|
+
|
|
3
15
|
## 0.48.0 - 2026-10-30
|
|
4
16
|
|
|
5
17
|
### Added
|
package/README.md
CHANGED
|
@@ -256,7 +256,7 @@ For adoption, run `quality baseline write --rule code/unused` and review the rec
|
|
|
256
256
|
- **Suppressions:** the `suppressions/*` rules reject inline lint and compiler directives, casts through `unknown`, `any` or `never`, Biome settings that weaken a check, recommended Biome rules the preset leaves below `error`, and `ignoreDeprecations`. None of them takes exceptions. A type test (`*.typecheck.test.ts`) may use `@ts-expect-error`; a test that must pass a rejected value at run time calls the API through `Reflect.apply`.
|
|
257
257
|
- **Imports:** cycles, unresolvable imports, workspace imports missing from the manifest or an entry point, relative imports that leave their folder, production imports of test code, runtime folders and fences, as described above.
|
|
258
258
|
- **Names and files:** the Biome preset's naming rules and plugins, and the `files/*` rules, which name a file after its main export with its folders as the prefix. `files/named-after-export` keeps the export’s full name while the file name omits words already supplied by any folder above it. In `spaces/client/`, a component exporting `CreateSpace` lives in `Create.tsx`: `spaces/` supplies “Space” even across the intervening `client/` folder. Keep the export named `CreateSpace`; `CreateSpace.tsx` would repeat a folder name. No naming rule renames anything; the author picks the name. A name an outside system owns, such as a query parameter or an environment variable, is written as a quoted key, which the naming rules skip. A `Schema.Struct` field stays camelCase even when quoted and maps to the outside name with `Schema.encodeKeys`. Biome's naming messages print only a pattern: spell acronyms as words (`HttpClient`, `userId`, `parseUrl`) rather than turning off `strictCase` as its hint suggests, give a type no `I` prefix, and name a type parameter `T`, `T` plus a PascalCase name (`TItem`), or Effect's `A`, `E` and `R`. No rule checks these, so review does: a boolean reads as a question (`isOpen`, `canRetry`) unless the DOM or React names it (`open`, `disabled`); a schema shares its name with its type (`type Item = typeof Item.Type`); an unused parameter is removed rather than renamed with the `_` prefix TypeScript accepts. The naming rules take repository facts: `toolOwned` lists `.gitignore` patterns whose names a tool fixes, and a configured list extends the rule's defaults, so list only repository-specific additions; `content` lists snake_case content folders and files; `tests/follow` and `tests/colocated` take `suites` for test folders with their own layout, such as a Playwright suite.
|
|
259
|
-
- **React:** `react/jsx-conditionals` reports `&&` and ternaries in JSX children, including nested decisions.
|
|
259
|
+
- **React:** `react/jsx-conditionals` reports `&&` and ternaries in the JSX children a component returns, including nested decisions and returned `.map` items. Decisions in a `const` above the return, JSX built inside library callbacks and conditional attributes are accepted. A ternary with two plain string or number literal branches, such as `{on ? "On" : "Off"}`, is accepted; branches that select JSX, components or computed values still need a decision before the JSX. This rule owns the check, so the shared Biome preset leaves `noLeakedRender` off.
|
|
260
260
|
- **Tests:** `tests/follow` and `tests/colocated` keep a test beside the code it covers, named `<file>[.<modifier>].test.ts` or `<behaviour>[.<modifier>].spec.ts` with at most one modifier of `dom`, `slow`, `typecheck` and `unit`; a unit test runs without the DOM, so `.unit.dom` is rejected. `tests/colocated` always treats `__tests__/` as a test folder. It treats `test/`, `tests/` and `spec/` as test folders only when their directly contained checked files are all tests or test support; a product folder with source beside its specs is an ordinary source folder. Declared `suites` keep their own layout. Shared test support belongs in `test-support/`, the sanctioned test-only folder. A test covering a whole module may sit at its root or directly beside its folder. The story rules above keep setup in the kit.
|
|
261
261
|
- **Manifests:** `manifests/valid` decodes every repository `package.json` through one shared Schema before dependent rules run and reports each invalid manifest once with its file path. Read failures other than `NotFound` fail the scan. `manifests/sorted` keeps every `package.json` in sort-package-json order, and `manifests/source-first` puts the `source` condition first in `exports` and `imports`. `manifests/exports-shape` checks the package root and workspace members with exports. They use one file-preserving TypeScript wildcard: for example, `./*.ts` maps to `./src/*.ts`, `./dist/*.d.ts` and `./dist/*.js` under `source`, `types` and `default`. A subtree pattern such as `./server/*.ts` keeps that same subtree in its targets. An optional root entry and exact-path non-code assets such as JSON presets and `./package.json` are allowed. Every module remains importable; `null` export entries fail with a request to remove the block. A package without modules, such as a dependency shell, exports only exact assets and needs no wildcard. Import each module at its path under `src/`; named aliases, flattened paths, per-file module lists and additional wildcards fail. `manifests/application` keeps an application on its entry points, as described above.
|
|
262
262
|
- **Biome:** the `biome` rule reports Biome's error findings as `biome/<category>`. A Biome run that fails without an error finding, such as one whose config leaves no file to check, fails lint and fix with Biome's message. The preset leaves out the `.worktrees` folder at the root, so a checkout does not lint its linked worktrees, while a worktree inside it lints all of its own files. The preset's plugins ban ambient time, randomness, `console` and `process.env` in favour of Effect's services.
|
|
@@ -285,6 +285,31 @@ function Panel({ ready }) {
|
|
|
285
285
|
}
|
|
286
286
|
```
|
|
287
287
|
|
|
288
|
+
JSX built in a `const` above the return is also accepted:
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
function Panel({ ready }) {
|
|
292
|
+
const content = <section>{ready && <Content />}</section>;
|
|
293
|
+
return <main>{content}</main>;
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Conditional attributes are accepted:
|
|
298
|
+
|
|
299
|
+
```tsx
|
|
300
|
+
function Panel({ ready }) {
|
|
301
|
+
return <section className={ready ? "active" : "idle"} />;
|
|
302
|
+
}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Library callbacks make their own rendering decisions. A chart formatter is accepted:
|
|
306
|
+
|
|
307
|
+
```tsx
|
|
308
|
+
function Chart() {
|
|
309
|
+
return <Library formatter={(value) => <span>{value ? <Content /> : null}</span>} />;
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
288
313
|
Replace `<ul>{items.map(item => item.visible ? <li key={item.id}>{item.name}</li> : null)}</ul>` with an item component that receives the data and returns `null`:
|
|
289
314
|
|
|
290
315
|
```tsx
|
|
@@ -304,6 +329,26 @@ function List({ items }) {
|
|
|
304
329
|
}
|
|
305
330
|
```
|
|
306
331
|
|
|
332
|
+
To join rendered items with a separator, decide the separator in a `const` before the item return:
|
|
333
|
+
|
|
334
|
+
```tsx
|
|
335
|
+
function List({ items }) {
|
|
336
|
+
return (
|
|
337
|
+
<>
|
|
338
|
+
{items.map((item, index) => {
|
|
339
|
+
const separator = index > 0 && ", ";
|
|
340
|
+
return (
|
|
341
|
+
<span key={item.id}>
|
|
342
|
+
{separator}
|
|
343
|
+
{item.name}
|
|
344
|
+
</span>
|
|
345
|
+
);
|
|
346
|
+
})}
|
|
347
|
+
</>
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
307
352
|
### API
|
|
308
353
|
|
|
309
354
|
Import names from their defining module; there is no root entry. The package's `./*.ts` export pattern also exposes the gate's implementation modules; the following table lists the config, tool and extension entry points:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixJsxConditionals.d.ts","sourceRoot":"","sources":["../../src/adapters/fixJsxConditionals.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"fixJsxConditionals.d.ts","sourceRoot":"","sources":["../../src/adapters/fixJsxConditionals.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAgE3C,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CA4C3D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { parse } from "#rules/parse.ts";
|
|
3
|
+
import { jsxChildDecision } from "#rules/react/jsxChildDecision.ts";
|
|
3
4
|
function unwrap(node) {
|
|
4
5
|
return ts.isParenthesizedExpression(node) ? unwrap(node.expression) : node;
|
|
5
6
|
}
|
|
@@ -26,11 +27,7 @@ function conditionalChild(node) {
|
|
|
26
27
|
return undefined;
|
|
27
28
|
}
|
|
28
29
|
const expression = unwrap(child.expression);
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
function isConditional(expression) {
|
|
32
|
-
return (ts.isConditionalExpression(expression)
|
|
33
|
-
|| (ts.isBinaryExpression(expression) && expression.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken));
|
|
30
|
+
return jsxChildDecision(expression) === undefined ? undefined : child.expression;
|
|
34
31
|
}
|
|
35
32
|
function returnedExpression(node) {
|
|
36
33
|
if (ts.isReturnStatement(node)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixJsxConditionals.js","sourceRoot":"","sources":["../../src/adapters/fixJsxConditionals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"fixJsxConditionals.js","sourceRoot":"","sources":["../../src/adapters/fixJsxConditionals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAQpE,SAAS,MAAM,CAAC,IAAmB;IAClC,OAAO,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5E,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAmB;IAC5C,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC1D,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,EAAE,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC;QACrD,IAAI,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrG,OAAO,SAAS,CAAC;QAClB,CAAC;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AAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC/F,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;YAChE,KAAK,CAAC,IAAI,CAAC;gBACV,GAAG,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG;gBAC3D,KAAK;gBACL,IAAI,EAAE,WAAW,IAAI,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI;aACjE,CAAC,CAAC;YACH,OAAO;QACR,CAAC;QACD,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,CAAC;IACd,IAAI,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9E,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/adapters/knip/configuration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../../src/adapters/knip/configuration.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAe3C,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDzD"}
|
|
@@ -2,6 +2,7 @@ import { posix } from "node:path";
|
|
|
2
2
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
3
|
import { exportedModule, exportTargets } from "#imports/packageExports.ts";
|
|
4
4
|
import { packageOf, workspacePackages } from "#imports/workspace.ts";
|
|
5
|
+
import { isMigrationFile } from "#naming/migrationFile.ts";
|
|
5
6
|
import { KNIP_ISSUES } from "./findings.js";
|
|
6
7
|
const ENTRIES = ["**/*.{test,spec,stories,story}.{ts,tsx,mts,cts,js,jsx,mjs,cjs}", "src/test-support/**", "*.config.{ts,mts,cts,js,mjs,cjs}"];
|
|
7
8
|
function importPaths(imports) {
|
|
@@ -26,9 +27,15 @@ export async function knipConfiguration(inputs) {
|
|
|
26
27
|
const bins = exportTargets(manifest.bin).map((target) => target.replace(/^\.\//u, ""));
|
|
27
28
|
const binaries = sources.filter((path) => bins.includes(path) || bins.includes(path.replace(/^src\//u, "dist/").replace(/\.(?<mode>[cm]?)tsx?$/u, ".$<mode>js")));
|
|
28
29
|
const publicFiles = sources.filter((path) => exportedModule(manifest.exports, path));
|
|
30
|
+
// Migration runners load these files from their directory, so no import reaches them.
|
|
31
|
+
const migrations = sources.filter((path) => isMigrationFile(posix.join(directory, path)));
|
|
29
32
|
return [
|
|
30
33
|
directory,
|
|
31
|
-
{
|
|
34
|
+
{
|
|
35
|
+
entry: [...ENTRIES, ...publicFiles, ...migrations, ...bins, ...binaries, ...scriptEntries],
|
|
36
|
+
paths: importPaths(manifest.imports ?? {}),
|
|
37
|
+
project: sources,
|
|
38
|
+
},
|
|
32
39
|
];
|
|
33
40
|
});
|
|
34
41
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../../../src/adapters/knip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,OAAO;YACN,SAAS;YACT;gBACC,KAAK,EAAE,CAAC,GAAG,OAAO,EAAE,GAAG,WAAW,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAAE,GAAG,aAAa,CAAC;gBAC1F,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC;gBAC1C,OAAO,EAAE,OAAO;aAChB;SACQ,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,OAAO;QACN,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;QACV,cAAc,EAAE,EAAE;QAClB,kBAAkB,EAAE,EAAE;QACtB,uBAAuB,EAAE,KAAK;QAC9B,WAAW,EAAE,EAAE;QACf,YAAY,EAAE,EAAE;QAChB,aAAa,EAAE,EAAE;QACjB,gBAAgB,EAAE,EAAE;QACpB,gBAAgB,EAAE,EAAE;QACpB,OAAO,EAAE,WAAW;QACpB,mBAAmB,EAAE,KAAK;QAC1B,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;QACrE,IAAI,EAAE,EAAE;QACR,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC;KAC1C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsxChildDecision.d.ts","sourceRoot":"","sources":["../../../src/rules/react/jsxChildDecision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AA8E5B,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CAKxF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
function mapCall(node) {
|
|
3
|
+
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map";
|
|
4
|
+
}
|
|
5
|
+
function componentWrapper(node) {
|
|
6
|
+
const callee = node.expression;
|
|
7
|
+
const name = ts.isPropertyAccessExpression(callee) ? callee.name : callee;
|
|
8
|
+
return ts.isIdentifier(name) && ["memo", "forwardRef"].includes(name.text);
|
|
9
|
+
}
|
|
10
|
+
function component(node) {
|
|
11
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
12
|
+
return node.name === undefined || /^[A-Z]/u.test(node.name.text);
|
|
13
|
+
}
|
|
14
|
+
if (ts.isMethodDeclaration(node)) {
|
|
15
|
+
return ts.isClassLike(node.parent) && ts.isIdentifier(node.name) && node.name.text === "render";
|
|
16
|
+
}
|
|
17
|
+
let parent = node.parent;
|
|
18
|
+
while (ts.isParenthesizedExpression(parent) || ts.isCallExpression(parent)) {
|
|
19
|
+
if (ts.isCallExpression(parent) && !componentWrapper(parent)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
parent = parent.parent;
|
|
23
|
+
}
|
|
24
|
+
return ts.isExportAssignment(parent) || (ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name) && /^[A-Z]/u.test(parent.name.text));
|
|
25
|
+
}
|
|
26
|
+
function literal(node) {
|
|
27
|
+
if (ts.isParenthesizedExpression(node)) {
|
|
28
|
+
return literal(node.expression);
|
|
29
|
+
}
|
|
30
|
+
return (ts.isStringLiteral(node)
|
|
31
|
+
|| ts.isNumericLiteral(node)
|
|
32
|
+
|| (ts.isPrefixUnaryExpression(node)
|
|
33
|
+
&& (node.operator === ts.SyntaxKind.MinusToken || node.operator === ts.SyntaxKind.PlusToken)
|
|
34
|
+
&& ts.isNumericLiteral(node.operand)));
|
|
35
|
+
}
|
|
36
|
+
function boundary(node) {
|
|
37
|
+
return ts.isJsxAttribute(node) || ts.isJsxSpreadAttribute(node) || ts.isVariableDeclaration(node);
|
|
38
|
+
}
|
|
39
|
+
function jsxChild(node) {
|
|
40
|
+
return ts.isJsxExpression(node) && (ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent));
|
|
41
|
+
}
|
|
42
|
+
function returnedComponent(node, returned) {
|
|
43
|
+
return (returned || (ts.isArrowFunction(node) && !ts.isBlock(node.body))) && component(node);
|
|
44
|
+
}
|
|
45
|
+
function childContext(node) {
|
|
46
|
+
let mapped = false;
|
|
47
|
+
let child = false;
|
|
48
|
+
let returned = false;
|
|
49
|
+
for (let parent = node.parent; parent !== undefined; parent = parent.parent) {
|
|
50
|
+
if (boundary(parent)) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
child ||= jsxChild(parent);
|
|
54
|
+
if (ts.isFunctionLike(parent) && !mapCall(parent.parent)) {
|
|
55
|
+
return child && returnedComponent(parent, returned) ? { mapped } : undefined;
|
|
56
|
+
}
|
|
57
|
+
if (mapCall(parent)) {
|
|
58
|
+
mapped = true;
|
|
59
|
+
returned = false;
|
|
60
|
+
}
|
|
61
|
+
returned ||= ts.isReturnStatement(parent);
|
|
62
|
+
if (!returned && ts.isStatement(parent) && !ts.isBlock(parent)) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
export function jsxChildDecision(node) {
|
|
69
|
+
if (ts.isConditionalExpression(node)) {
|
|
70
|
+
return literal(node.whenTrue) && literal(node.whenFalse) ? undefined : childContext(node);
|
|
71
|
+
}
|
|
72
|
+
return ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken ? childContext(node) : undefined;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=jsxChildDecision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsxChildDecision.js","sourceRoot":"","sources":["../../../src/rules/react/jsxChildDecision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,SAAS,OAAO,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,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAChE,OAAO,SAAS,CAAC;QAClB,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAa;IAC7C,IAAI,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC;QACtC,OAAO,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,EAAE,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,IAAI,KAAK,EAAE,CAAC,UAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1I,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsxConditionals.d.ts","sourceRoot":"","sources":["../../../src/rules/react/jsxConditionals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jsxConditionals.d.ts","sourceRoot":"","sources":["../../../src/rules/react/jsxConditionals.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,eAAe,qEAwB1B,CAAC"}
|
|
@@ -1,44 +1,20 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { defineRule } from "#rule.ts";
|
|
3
3
|
import { parse } from "#rules/parse.ts";
|
|
4
|
+
import { jsxChildDecision } from "./jsxChildDecision.js";
|
|
4
5
|
const REPAIR = "Decide before the JSX with an if and early return, or a variable computed above the return; or extract a component that receives the data and returns null when it has nothing to show.";
|
|
5
|
-
function mapCall(node) {
|
|
6
|
-
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map";
|
|
7
|
-
}
|
|
8
|
-
function childContext(node) {
|
|
9
|
-
let mapped = false;
|
|
10
|
-
let child = false;
|
|
11
|
-
for (let parent = node.parent; parent !== undefined; parent = parent.parent) {
|
|
12
|
-
if (!child && ts.isJsxSpreadAttribute(parent)) {
|
|
13
|
-
return undefined;
|
|
14
|
-
}
|
|
15
|
-
if (ts.isJsxExpression(parent)) {
|
|
16
|
-
if (!(child || ts.isJsxElement(parent.parent) || ts.isJsxFragment(parent.parent))) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
child = true;
|
|
20
|
-
}
|
|
21
|
-
if (ts.isVariableDeclaration(parent) || (ts.isStatement(parent) && !ts.isReturnStatement(parent) && !ts.isBlock(parent))) {
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
mapped ||= mapCall(parent);
|
|
25
|
-
}
|
|
26
|
-
return child ? { mapped } : undefined;
|
|
27
|
-
}
|
|
28
6
|
export const jsxConditionals = defineRule({
|
|
29
7
|
check: ({ sources }) => sources.flatMap((file) => {
|
|
30
8
|
const source = parse(file);
|
|
31
9
|
const findings = [];
|
|
32
10
|
function visit(node) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
});
|
|
41
|
-
}
|
|
11
|
+
const context = jsxChildDecision(node);
|
|
12
|
+
if (context !== undefined && source !== undefined) {
|
|
13
|
+
findings.push({
|
|
14
|
+
file: file.path,
|
|
15
|
+
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
16
|
+
message: `Conditional rendering inside a JSX child. ${REPAIR}${context.mapped ? " Inside .map, extract the item into its own component that makes its own decision." : ""}`,
|
|
17
|
+
});
|
|
42
18
|
}
|
|
43
19
|
ts.forEachChild(node, visit);
|
|
44
20
|
}
|
|
@@ -47,7 +23,7 @@ export const jsxConditionals = defineRule({
|
|
|
47
23
|
}
|
|
48
24
|
return findings;
|
|
49
25
|
}),
|
|
50
|
-
description: `Components decide what to render outside their JSX. ${REPAIR} Inside .map, extract an item component that makes its own decision. Attribute values are accepted.`,
|
|
26
|
+
description: `Components decide what to render outside their returned JSX. ${REPAIR} Inside .map, extract an item component that makes its own decision. Attribute values, library callbacks and ternaries between plain string or number literals are accepted.`,
|
|
51
27
|
id: "react/jsx-conditionals",
|
|
52
28
|
registrable: false,
|
|
53
29
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsxConditionals.js","sourceRoot":"","sources":["../../../src/rules/react/jsxConditionals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAgB,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"jsxConditionals.js","sourceRoot":"","sources":["../../../src/rules/react/jsxConditionals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAgB,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,MAAM,GACX,yLAAyL,CAAC;AAE3L,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;IACzC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CACtB,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxB,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,QAAQ,GAAc,EAAE,CAAC;QAC/B,SAAS,KAAK,CAAC,IAAa;YAC3B,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;YACvC,IAAI,OAAO,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACnD,QAAQ,CAAC,IAAI,CAAC;oBACb,IAAI,EAAE,IAAI,CAAC,IAAI;oBACf,IAAI,EAAE,MAAM,CAAC,6BAA6B,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;oBAC1E,OAAO,EAAE,6CAA6C,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,oFAAoF,CAAC,CAAC,CAAC,EAAE,EAAE;iBAC3K,CAAC,CAAC;YACJ,CAAC;YACD,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAC1B,KAAK,CAAC,MAAM,CAAC,CAAC;QACf,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC,CAAC;IACH,WAAW,EAAE,gEAAgE,MAAM,8KAA8K;IACjQ,EAAE,EAAE,wBAAwB;IAC5B,WAAW,EAAE,KAAK;CAClB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/quality",
|
|
3
|
-
"version": "0.48.
|
|
3
|
+
"version": "0.48.2",
|
|
4
4
|
"description": "Repository quality gate with typed rules, a baseline of existing debt and a registry of reasoned exceptions",
|
|
5
5
|
"homepage": "https://github.com/ShivaeDev/platform/tree/main/packages/quality#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@biomejs/biome": "2.6.2",
|
|
54
54
|
"@shivaedev/types": "0.3.0",
|
|
55
55
|
"@vitest/coverage-v8": "5.0.5",
|
|
56
|
-
"ignore": "7.0.
|
|
56
|
+
"ignore": "7.0.14",
|
|
57
57
|
"knip": "6.42.1",
|
|
58
58
|
"sort-package-json": "4.1.0",
|
|
59
59
|
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"@effect/platform-node": "4.0.6",
|
|
63
63
|
"@effect/platform-node-shared": "4.0.6",
|
|
64
64
|
"@effect/vitest": "4.0.6",
|
|
65
|
-
"@shivaedev/test-story": "0.
|
|
65
|
+
"@shivaedev/test-story": "0.28.0",
|
|
66
66
|
"@types/node": "24.19.2",
|
|
67
67
|
"@typescript/native": "npm:typescript@7.0.2",
|
|
68
68
|
"effect": "4.0.6",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import type { SourceFile } from "#rule.ts";
|
|
3
3
|
import { parse } from "#rules/parse.ts";
|
|
4
|
+
import { jsxChildDecision } from "#rules/react/jsxChildDecision.ts";
|
|
4
5
|
|
|
5
6
|
interface Edit {
|
|
6
7
|
readonly end: number;
|
|
@@ -35,14 +36,7 @@ function conditionalChild(node: ts.Expression): ts.Expression | undefined {
|
|
|
35
36
|
return undefined;
|
|
36
37
|
}
|
|
37
38
|
const expression = unwrap(child.expression);
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function isConditional(expression: ts.Expression): boolean {
|
|
42
|
-
return (
|
|
43
|
-
ts.isConditionalExpression(expression)
|
|
44
|
-
|| (ts.isBinaryExpression(expression) && expression.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken)
|
|
45
|
-
);
|
|
39
|
+
return jsxChildDecision(expression) === undefined ? undefined : child.expression;
|
|
46
40
|
}
|
|
47
41
|
|
|
48
42
|
function returnedExpression(node: ts.Node): ts.Expression | undefined {
|
|
@@ -2,6 +2,7 @@ import { posix } from "node:path";
|
|
|
2
2
|
import { readPackageManifest } from "#adapters/manifestInventory.ts";
|
|
3
3
|
import { exportedModule, exportTargets } from "#imports/packageExports.ts";
|
|
4
4
|
import { packageOf, workspacePackages } from "#imports/workspace.ts";
|
|
5
|
+
import { isMigrationFile } from "#naming/migrationFile.ts";
|
|
5
6
|
import type { RuleInputs } from "#rule.ts";
|
|
6
7
|
import { KNIP_ISSUES } from "./findings.ts";
|
|
7
8
|
|
|
@@ -40,9 +41,15 @@ export async function knipConfiguration(inputs: RuleInputs) {
|
|
|
40
41
|
(path) => bins.includes(path) || bins.includes(path.replace(/^src\//u, "dist/").replace(/\.(?<mode>[cm]?)tsx?$/u, ".$<mode>js")),
|
|
41
42
|
);
|
|
42
43
|
const publicFiles = sources.filter((path) => exportedModule(manifest.exports, path));
|
|
44
|
+
// Migration runners load these files from their directory, so no import reaches them.
|
|
45
|
+
const migrations = sources.filter((path) => isMigrationFile(posix.join(directory, path)));
|
|
43
46
|
return [
|
|
44
47
|
directory,
|
|
45
|
-
{
|
|
48
|
+
{
|
|
49
|
+
entry: [...ENTRIES, ...publicFiles, ...migrations, ...bins, ...binaries, ...scriptEntries],
|
|
50
|
+
paths: importPaths(manifest.imports ?? {}),
|
|
51
|
+
project: sources,
|
|
52
|
+
},
|
|
46
53
|
] as const;
|
|
47
54
|
});
|
|
48
55
|
return {
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
function mapCall(node: ts.Node): boolean {
|
|
4
|
+
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map";
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function componentWrapper(node: ts.CallExpression): boolean {
|
|
8
|
+
const callee = node.expression;
|
|
9
|
+
const name = ts.isPropertyAccessExpression(callee) ? callee.name : callee;
|
|
10
|
+
return ts.isIdentifier(name) && ["memo", "forwardRef"].includes(name.text);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function component(node: ts.Node): boolean {
|
|
14
|
+
if (ts.isFunctionDeclaration(node)) {
|
|
15
|
+
return node.name === undefined || /^[A-Z]/u.test(node.name.text);
|
|
16
|
+
}
|
|
17
|
+
if (ts.isMethodDeclaration(node)) {
|
|
18
|
+
return ts.isClassLike(node.parent) && ts.isIdentifier(node.name) && node.name.text === "render";
|
|
19
|
+
}
|
|
20
|
+
let parent = node.parent;
|
|
21
|
+
while (ts.isParenthesizedExpression(parent) || ts.isCallExpression(parent)) {
|
|
22
|
+
if (ts.isCallExpression(parent) && !componentWrapper(parent)) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
parent = parent.parent;
|
|
26
|
+
}
|
|
27
|
+
return ts.isExportAssignment(parent) || (ts.isVariableDeclaration(parent) && ts.isIdentifier(parent.name) && /^[A-Z]/u.test(parent.name.text));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function literal(node: ts.Expression): boolean {
|
|
31
|
+
if (ts.isParenthesizedExpression(node)) {
|
|
32
|
+
return literal(node.expression);
|
|
33
|
+
}
|
|
34
|
+
return (
|
|
35
|
+
ts.isStringLiteral(node)
|
|
36
|
+
|| ts.isNumericLiteral(node)
|
|
37
|
+
|| (ts.isPrefixUnaryExpression(node)
|
|
38
|
+
&& (node.operator === ts.SyntaxKind.MinusToken || node.operator === ts.SyntaxKind.PlusToken)
|
|
39
|
+
&& ts.isNumericLiteral(node.operand))
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function boundary(node: ts.Node): boolean {
|
|
44
|
+
return ts.isJsxAttribute(node) || ts.isJsxSpreadAttribute(node) || ts.isVariableDeclaration(node);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function jsxChild(node: ts.Node): boolean {
|
|
48
|
+
return ts.isJsxExpression(node) && (ts.isJsxElement(node.parent) || ts.isJsxFragment(node.parent));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function returnedComponent(node: ts.Node, returned: boolean): boolean {
|
|
52
|
+
return (returned || (ts.isArrowFunction(node) && !ts.isBlock(node.body))) && component(node);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function childContext(node: ts.Node): { readonly mapped: boolean } | undefined {
|
|
56
|
+
let mapped = false;
|
|
57
|
+
let child = false;
|
|
58
|
+
let returned = false;
|
|
59
|
+
for (let parent = node.parent; parent !== undefined; parent = parent.parent) {
|
|
60
|
+
if (boundary(parent)) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
child ||= jsxChild(parent);
|
|
64
|
+
if (ts.isFunctionLike(parent) && !mapCall(parent.parent)) {
|
|
65
|
+
return child && returnedComponent(parent, returned) ? { mapped } : undefined;
|
|
66
|
+
}
|
|
67
|
+
if (mapCall(parent)) {
|
|
68
|
+
mapped = true;
|
|
69
|
+
returned = false;
|
|
70
|
+
}
|
|
71
|
+
returned ||= ts.isReturnStatement(parent);
|
|
72
|
+
if (!returned && ts.isStatement(parent) && !ts.isBlock(parent)) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function jsxChildDecision(node: ts.Node): { readonly mapped: boolean } | undefined {
|
|
80
|
+
if (ts.isConditionalExpression(node)) {
|
|
81
|
+
return literal(node.whenTrue) && literal(node.whenFalse) ? undefined : childContext(node);
|
|
82
|
+
}
|
|
83
|
+
return ts.isBinaryExpression(node) && node.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken ? childContext(node) : undefined;
|
|
84
|
+
}
|
|
@@ -1,50 +1,24 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
2
|
import { defineRule, type Finding } from "#rule.ts";
|
|
3
3
|
import { parse } from "#rules/parse.ts";
|
|
4
|
+
import { jsxChildDecision } from "./jsxChildDecision.ts";
|
|
4
5
|
|
|
5
6
|
const REPAIR =
|
|
6
7
|
"Decide before the JSX with an if and early return, or a variable computed above the return; or extract a component that receives the data and returns null when it has nothing to show.";
|
|
7
8
|
|
|
8
|
-
function mapCall(node: ts.Node): boolean {
|
|
9
|
-
return ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.name.text === "map";
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function childContext(node: ts.Node): { readonly mapped: boolean } | undefined {
|
|
13
|
-
let mapped = false;
|
|
14
|
-
let child = false;
|
|
15
|
-
for (let parent = node.parent; parent !== undefined; parent = parent.parent) {
|
|
16
|
-
if (!child && ts.isJsxSpreadAttribute(parent)) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
if (ts.isJsxExpression(parent)) {
|
|
20
|
-
if (!(child || ts.isJsxElement(parent.parent) || ts.isJsxFragment(parent.parent))) {
|
|
21
|
-
return undefined;
|
|
22
|
-
}
|
|
23
|
-
child = true;
|
|
24
|
-
}
|
|
25
|
-
if (ts.isVariableDeclaration(parent) || (ts.isStatement(parent) && !ts.isReturnStatement(parent) && !ts.isBlock(parent))) {
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
mapped ||= mapCall(parent);
|
|
29
|
-
}
|
|
30
|
-
return child ? { mapped } : undefined;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
9
|
export const jsxConditionals = defineRule({
|
|
34
10
|
check: ({ sources }) =>
|
|
35
11
|
sources.flatMap((file) => {
|
|
36
12
|
const source = parse(file);
|
|
37
13
|
const findings: Finding[] = [];
|
|
38
14
|
function visit(node: ts.Node): void {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
}
|
|
15
|
+
const context = jsxChildDecision(node);
|
|
16
|
+
if (context !== undefined && source !== undefined) {
|
|
17
|
+
findings.push({
|
|
18
|
+
file: file.path,
|
|
19
|
+
line: source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1,
|
|
20
|
+
message: `Conditional rendering inside a JSX child. ${REPAIR}${context.mapped ? " Inside .map, extract the item into its own component that makes its own decision." : ""}`,
|
|
21
|
+
});
|
|
48
22
|
}
|
|
49
23
|
ts.forEachChild(node, visit);
|
|
50
24
|
}
|
|
@@ -53,7 +27,7 @@ export const jsxConditionals = defineRule({
|
|
|
53
27
|
}
|
|
54
28
|
return findings;
|
|
55
29
|
}),
|
|
56
|
-
description: `Components decide what to render outside their JSX. ${REPAIR} Inside .map, extract an item component that makes its own decision. Attribute values are accepted.`,
|
|
30
|
+
description: `Components decide what to render outside their returned JSX. ${REPAIR} Inside .map, extract an item component that makes its own decision. Attribute values, library callbacks and ternaries between plain string or number literals are accepted.`,
|
|
57
31
|
id: "react/jsx-conditionals",
|
|
58
32
|
registrable: false,
|
|
59
33
|
});
|