useConsistentTupleLabels (JavaScript)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useConsistentTupleLabels - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Same as
unicorn/consistent-tuple-labels
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useConsistentTupleLabels": "error" } } }}Description
Section titled “Description”Require either all or none of the elements of a tuple type to have labels.
A tuple type describes an array with a fixed number of elements, where each position has its own type.
Each element can have a label, such as x in [x: number, y: number], that describes what the position means.
When only some elements have labels, the elements without one look like they were forgotten,
and the tuple is harder to read.
This rule reports the elements without a label in a tuple type where at least one other element has a label.
Tuple types where no element has a label are allowed.
A rest element, such as ...rest: number[], can also have a label, and is checked the same way as the other elements.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”type Point = [x: number, number];code-block.ts:1:26 lint/nursery/useConsistentTupleLabels ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This tuple element has no label, but other elements of the same tuple do.
> 1 │ type Point = [x: number, number];
│ ^^^^^^
2 │
ℹ Labeling only some elements of a tuple makes it unclear what the other positions mean.
ℹ Add a label to this element, or remove the labels from the other elements.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
type Route = [name: string, ...string[]];code-block.ts:1:29 lint/nursery/useConsistentTupleLabels ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ This tuple element has no label, but other elements of the same tuple do.
> 1 │ type Route = [name: string, ...string[]];
│ ^^^^^^^^^^^
2 │
ℹ Labeling only some elements of a tuple makes it unclear what the other positions mean.
ℹ Add a label to this element, or remove the labels from the other elements.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
type Point = [x: number, y: number];type Pair = [number, number];type Route = [name: string, ...segments: string[]];Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.