このコミットが含まれているのは:
@@ -266,6 +266,44 @@ const value =
|
||||
value selection. Do not replace a clear ternary with `if` statements, and do
|
||||
not introduce immediately invoked functions just to avoid or reformat a
|
||||
ternary expression.
|
||||
- In TypeScript and TSX, multi-stage ternary expressions must make branch
|
||||
boundaries explicit. Wrap each condition group in parentheses instead of
|
||||
relying on indentation alone to show which `?` matches which `:`.
|
||||
- In TypeScript and TSX, wrap nested ternary expressions in parentheses. Do
|
||||
not write flat vertical chains of `?` and `:` without explicit grouping.
|
||||
- In TypeScript and TSX, when a ternary condition contains `&&` or `||`, wrap
|
||||
the whole condition in parentheses before `?`.
|
||||
- In TypeScript and TSX, if a ternary reaches three or more stages and still
|
||||
reads poorly after explicit grouping, extract a helper function or use `if`
|
||||
statements instead of keeping a flat multi-stage ternary.
|
||||
|
||||
Bad:
|
||||
|
||||
```ts
|
||||
row.skipReason === 'existing' || row.importStatus === 'skipped'
|
||||
? 'skipped'
|
||||
: Object.keys (row.validationErrors ?? { }).length > 0
|
||||
|| row.importStatus === 'failed'
|
||||
|| row.importStatus === 'created'
|
||||
? null
|
||||
: hasWarnings (row) || row.status === 'warning'
|
||||
? 'warning'
|
||||
: 'ready'
|
||||
```
|
||||
|
||||
Good:
|
||||
|
||||
```ts
|
||||
(row.skipReason === 'existing' || row.importStatus === 'skipped')
|
||||
? 'skipped'
|
||||
: ((Object.keys (row.validationErrors ?? { }).length > 0
|
||||
|| row.importStatus === 'failed'
|
||||
|| row.importStatus === 'created')
|
||||
? null
|
||||
: ((hasWarnings (row) || row.status === 'warning')
|
||||
? 'warning'
|
||||
: 'ready'))
|
||||
```
|
||||
- In TypeScript and TSX, do not write `let` followed by later `if` assignments
|
||||
when the value can be expressed as a single `const` initializer. Prefer
|
||||
`const` because it prevents accidental later reassignment.
|
||||
|
||||
新しい課題から参照
ユーザをブロックする