Repository navigation
Conversation
|
A maintainer will take a look as soon as they can. In the meantime, please make sure that:
|
🦋 Changeset detectedLatest commit: 2b36b38 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Merging this PR will degrade performance by 6.17%1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
85a19e2 to
73a79b8
Compare
- match ternary and if subjects by reference equivalence, so `a?.b != null ? a.b : c` and `a["b"]` against `a.b` are reported and the fix uses the test-side subject
- stop reporting ternaries and if statements whose subject contains a call: `foo() !== null ? foo() : x` and `getRec().a == null` move from the invalid to the valid fixtures
- report mixed loose and strict compound checks, loose compounds in ternaries, and parenthesized tests and null literals
- accept `(a = b);`, `a ??= b`, `a ||= b`, parenthesized targets, and type wrappers around the tested value in if bodies and tests, so `if (!assign) { assign ||= makeObj(); }` is now reported by the if as well as by the `||=`
- trace the conditional test context through parentheses, `&&`, `||`, `??`, ternary branches, the last sequence expression, and `!`, and apply ignoreConditionalTests to `||=`
- report `||` that reaches a test only through a call argument, a function body, or a unary operator other than `!`
- let ignoreBooleanCoercion pass through ternary branches and sequences, and stop at `!`
- stop the mixed logical check from climbing into a parent `||=` or descending into nested `||=` operands, so `outerAssign ||= innerAssign ||= b && c` and `parenOuter ||= (parenInner ||= b && c)` now report the outer `||=`
- withhold the ternary fix when the tested value or the present branch contains a type assertion, `satisfies`, `<T>`, `!`, or an instantiation, since the rewrite keeps only the tested value
- keep only the comments, without line breaks, that sit before the present branch of a ternary, and withhold the fix for a `//` or multi-line comment there, so `return a != null ?\n a : d` does not become `return\n a ?? d`
- withhold the fix for a compound check when optional chaining differs between its two comparisons, so `deep.n?.a !== null && deep.n.a !== undefined` keeps its TypeError
- treat a local variable named `undefined` as a plain variable, and let `ignoreBooleanCoercion` count only the first `Boolean()` argument
- withhold the fix when the rewrite would start a statement with `(` after a line that does not end in `;` or `{`
- withhold the ternary fix when it would drop a comment, and keep comments before either branch
- wrap arrow function operands in parentheses when rewriting to `??`
- drop the space after `??` when the fallback already starts on a new line
- add `AnyJsAssignment::omit_parentheses` with a unit test
- update the rule docs and the ignoreConditionalTests and ignoreBooleanCoercion option docs
73a79b8 to
4dc1c42
Compare
- report truthiness ternaries `x ? x : y` and `!x ? y : x` with their own diagnostic, and give `if (!x)` a falsy message instead of the nullish one
- apply ignoreConditionalTests, ignoreTernaryTests, and ignoreBooleanCoercion to truthiness ternaries, while a ternary passed directly as the `Boolean()` argument is still reported
- report `||=` on static and computed member targets and on `as T` and `<T>` targets with the asserted type, keep the declared type through parentheses and `satisfies`, and skip `x!` targets, matching `||`
- register member and assertion targets of every compound assignment in the module graph, and read them through `type_of_assignment`
- report `||`, `||=`, truthiness ternaries, and `if (!x)` on `any` and `unknown` without a fix, including a variable declared `unknown` that is assigned in a nested block, and never report a strict comparison on them
- report `if (x == null)` for values of any type by dropping the nullable-type requirement on the `if` subject
- offer the fix on arrays, `Date` and other built-in objects, functions, classes, and type parameters constrained to `object`, and withhold it on object shapes, interfaces, class instances, `Number`, and `String`, because the generated `String` type lacks members added after ES2015 such as `padStart`, so a shape whose members all exist on `String` can still hold `''`
- make ignorePrimitives skip a value when any variant is an ignored primitive, including template literal types and branded intersections, and apply it only to truthiness checks
- replace `has_any_ignore_primitives` with `ignores_any_primitive` so `false` and `{ "string": false }` ignore nothing
- remove the issue link from the rule metadata
- update the rule docs, the option docs, and the generated schema and bindings
- add a changeset
4dc1c42 to
2b36b38
Compare
Summary
Closes #8043
Depends on #13260, whose commit is the first one here. Only the last commit belongs to this PR.
New reports:
x ? x : yand!x ? y : x, andif (!x) x = y, each with its own message.ignoreConditionalTests,ignoreTernaryTestsandignoreBooleanCoercionapply to them.Boolean()is still reported.||=on member targets (obj.a ||= x,arr[i] ||= x), and onas Tand<T>targets using the asserted type.x! ||= yis not reported, the same asx! || y.||,||=, truthiness ternaries andif (!x)on values typedanyorunknown, without a fix. Strict comparisons on these values are not reported.if (x == null) x = y, whatever the type ofx.When the fix is offered:
||becomes??only when Biome can tell that no falsy primitive (0,'',false) is assignable to the non-nullish part of the type.Dateand other built-in objects, functions, classes, and type parameters constrained toobjectget the fix.{ a: string }or{}, interfaces, class instances,Number,String, and unconstrained type parameters don't. Biome's generatedStringtype lacks members added after ES2015, such aspadStart, so it can't rule out''for a shape whose members all exist onString.Options:
ignorePrimitivesignores a value when any variant of its type is an ignored primitive. That includes template literal types and branded intersections such asstring & { __brand: 'id' }.string | number | nullis ignored when onlystringis enabled.nullorundefinedare not affected."ignorePrimitives": falseand{ "string": false }ignore nothing.Type inference:
TypedService::type_of_assignmentreads them, andTypeData::from_any_js_assignment_targettypes them.InferredType::includes_any_or_unknown_keywordlooks through unions, because a write in a nested block widens anunknownbinding tounknown | T.issue_numberis removed from the rule metadata. The changeset is included.Test Plan
ternaryTruthinessInvalid.tsandternaryTruthinessValid.tsunresolvedValid.tscrossModuleGeneric/invalid.tsignoreBooleanCoercionDefault.tsignorePrimitivesString.ts,ignorePrimitivesBigint.ts,ignorePrimitivesBoolean.tsandignorePrimitivesDisabledObject.tsifStatementAsi.tsis renamed toasi.tsand covers truthiness ternaries too.logicalOrInvalid.tscovers which types get the fix and which don't.inferred_type.rshas unit tests foris_safe_for_nullish_coalescing,has_ignored_primitive_variantandincludes_any_or_unknown_keyword.requests.test.rshas module-graph tests for registering assignment targets.cargo test -p biome_js_analyze -p biome_js_type_info -p biome_module_graphpasses, andjust f,just landjust lint-rulesare clean.Docs
The rule docs cover truthiness checks,
anyandunknown, and when the fix is offered. TheignorePrimitivesandignoreTernaryTestsoption docs are updated, and the schema and bindings are regenerated.