Skip to content

Generated code can contain unused variables #3384

@PIG208

Description

@PIG208

Describe the bug

The generated validateIntegrity method can contain a final data = instance.toColumns(true);
statement that defines an unused local variable.

This can be reproduced by having a table that contains only columns with a type converter.

For example:

enum Fruit {
  apple,
  pear,
}
class Foo extends Table {
  Column<String> get fruit => textEnum<Fruit>()
    .withDefault(const Variable('apple'))();
}
  @override
  VerificationContext validateIntegrity(Insertable<FooData> instance,
      {bool isInserting = false}) {
    final context = VerificationContext();
    final data = instance.toColumns(true); // The value of the local variable 'data' isn't used
    context.handle(_fruitMeta, const VerificationResult.success());
    return context;
  }

We don't necessarily need to avoid generating code like this. Adding the lint rule to ignore_for_file should fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions