avoid-positional-fields-in-records
Same as avoid_positional_fields_in_records in Pyramid Lint
- Group
- Style
- Path
lint/style/avoid-positional-fields-in-records- Default
- Off, opt in
- Origin
- Pyramid Lint
- Rule
- 113 of 512
Flags positional fields in record types.
Positional record fields are accessed as $1, $2, and so on, which convey
nothing about what each field means and break silently when fields are
reordered. Named fields (({int x, int y})) document intent at both the
declaration and every use site. The check recurses through type arguments
and nested record and function types, so a positional field buried inside a
generic is still reported.
Invalid
class RecordExamples {
/// Positional fields in record literal
void example1() {
final record = (1, 'hello');
print(record);
}
/// Positional fields in record type return
(int, String) getInfo() {
return (42, 'answer');
}
/// Positional fields in record type parameter
void processRecord((int, String) data) {
print(data);
}
/// Positional fields in record type variable
void example2() {
(String, bool, int) tuple = ('test', true, 5);
print(tuple);
}
/// Positional fields in record literal with multiple
void example3() {
final result = (1, 2, 3, 'four');
print(result);
}
}
// Regression: a declaration nested in a labeled block or a closure body must
// still be checked — a hand-rolled walk skipped those statement forms.
void containersRegression() {
lbl: {
final inLabeled = (1, 2);
print(inLabeled);
}
final closure = () {
final inClosure = (3, 4);
return inClosure;
};
print(closure);
}
typedef Pair = (int, String);
void typePositions(Object value) {
final cast = value as (int, String);
final test = value is (int, String);
final callback = ((int, String) pair) => pair;
print([cast, test, callback]);
}
final callback = () {
final pair = (1, 2);
return pair;
}; void example1() { final record = (1, 'hello'); /// Positional fields in record type return (int, String) getInfo() { /// Positional fields in record type parameter void processRecord((int, String) data) { void example2() { (String, bool, int) tuple = ('test', true, 5); void example3() { final result = (1, 2, 3, 'four'); lbl: { final inLabeled = (1, 2); final closure = () { final inClosure = (3, 4); typedef Pair = (int, String);void typePositions(Object value) { final cast = value as (int, String); final cast = value as (int, String); final test = value is (int, String); final test = value is (int, String); final callback = ((int, String) pair) => pair;final callback = () { final pair = (1, 2);Valid
class RecordExamples {
/// Named fields in record literal
void example1() {
final record = (id: 1, name: 'hello');
print(record);
}
/// Named fields in record type return
({int id, String name}) getInfo() {
return (id: 42, name: 'answer');
}
/// Named fields in record type parameter
void processRecord(({int id, String name}) data) {
print(data);
}
/// Named fields in record type variable
void example2() {
({String name, bool active, int count}) tuple = (name: 'test', active: true, count: 5);
print(tuple);
}
/// Named fields in record literal with multiple
void example3() {
final result = (a: 1, b: 2, c: 3, d: 'four');
print(result);
}
/// Record with mixed named fields
void example4() {
final data = (userId: 100, isActive: true);
print(data.userId);
print(data.isActive);
}
}Configure avoid-positional-fields-in-records
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-positional-fields-in-records": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-positional-fields-in-records: <reason>More style rules
- avoid-private-typedef-functions
avoid_private_typedef_functionsFlags a private function typedef that is used at most once.
- avoid-public-notifier-propertiesriverpod
Keeps notifier state behind Riverpod's observable state property.
- avoid-redundant-argument-values
avoid_redundant_argument_valuesFlags arguments that pass exactly the parameter's default value.
- avoid-redundant-else
Flags else branches after an if body that unconditionally returns or throws.
- avoid-redundant-pattern-field-names
avoid_redundant_pattern_field_namesrecommendedFlags redundant field names in object and record patterns.
- avoid-renaming-method-parameters
avoid_renaming_method_parametersRequires overriding methods to keep the positional parameter names of the member they inherit.
- avoid-return-types-on-setters
avoid_return_types_on_settersrecommendedFlags setters declared with an explicit return type.
- avoid-returning-this
avoid_returning_thisFlags methods that return
thisonly to enable a fluent interface.