-
Notifications
You must be signed in to change notification settings - Fork 403
Generated code can contain unused variables #3384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hm, there should be an Still, good catch! It's not hard to just not generate that effectively empty method in that case. |
Thanks for the swift fix! I believe I'm not sure what specific warning was appearing in this issue, but on a quick search for "unused" it doesn't look like that list includes one about unused variables. So it may be a Dart analyzer warning that isn't one of the "linter" rules, and therefore isn't covered by |
Generated file contains unused variable when the table contains only a
class $GlobalSettingsTable extends GlobalSettings
with TableInfo<$GlobalSettingsTable, GlobalSetting> {
@override
final GeneratedDatabase attachedDatabase;
final String? _alias;
$GlobalSettingsTable(this.attachedDatabase, [this._alias]);
// Warning: The value of the field '_themeSettingMeta' isn't used.
static const VerificationMeta _themeSettingMeta = const VerificationMeta(
'themeSetting',
);
@override
late final GeneratedColumnWithTypeConverter<ThemeSetting, String>
themeSetting = GeneratedColumn<String>(
'theme_setting',
aliasedName,
false,
type: DriftSqlType.string,
requiredDuringInsert: true,
).withConverter<ThemeSetting>($GlobalSettingsTable.$converterthemeSetting);
@override
List<GeneratedColumn> get $columns => [themeSetting];
@override
String get aliasedName => _alias ?? actualTableName;
@override
String get actualTableName => $name;
static const String $name = 'global_settings';
@override
Set<GeneratedColumn> get $primaryKey => const {};
@override
GlobalSetting map(Map<String, dynamic> data, {String? tablePrefix}) {
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
return GlobalSetting(
themeSetting: $GlobalSettingsTable.$converterthemeSetting.fromSql(
attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}theme_setting'],
)!,
),
);
} If another column is added to the table, or the column builder is changed to other things like It seems like the fix #3384 (comment) needs to further drop Reproduced on 2.25.1. |
Thanks for the report, I've fixed this in 8b8aacb. |
Hi @simolus3. Thanks a lot for the prompt fix! Do you have an estimate of when the next release will come out? (It's not necessarily blocking us as we can pin a Git revision containing the fix for now) |
I'll try to do a release this weekend, there are some other minor patches I want to look at too in the meantime. |
This contains a fix for simolus3/drift#3384. Signed-off-by: Zixuan James Li <[email protected]>
Describe the bug
The generated
validateIntegrity
method can contain afinal 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:
We don't necessarily need to avoid generating code like this. Adding the lint rule to
ignore_for_file
should fix this issue.The text was updated successfully, but these errors were encountered: