google / reflectable.dart

Reflectable is a Dart library that allows programmers to eliminate certain usages of dynamic reflection by specialization of reflective code to an equivalent implementation using only static techniques. The use of dynamic reflection is constrained in order to ensure that the specialized code can be generated and will have a reasonable size.
https://pub.dev/packages/reflectable
BSD 3-Clause "New" or "Revised" License
381 stars 57 forks source link

Add ignore 'implementation_imports' #203

Closed bounty1342 closed 4 years ago

bounty1342 commented 4 years ago

Hi, In the generated main.reflectable.dart, I presume the following comment can be added to reduce the numbers of problems : // ignore_for_file: implementation_imports

What do you think ? Is there another way of doing it ?

Regards

eernstg commented 4 years ago

Which kind of problems do you observe, and how do they arise? Are you using pedantic on a package where one or more libraries are generated by reflectable?

Could you use an exclude directive or something similar cf. this page to control the usage of the analyzer on the generated file?

bounty1342 commented 4 years ago

Hi,

I use the package dart_json_mapper witch generate files using reflectable.

As there is already those ignore comments, why not add implementation_imports ?

// ignore_for_file: unnecessary_const
// ignore_for_file: prefer_collection_literals
// ignore_for_file: prefer_adjacent_string_concatenation

// ignore:unused_import
import 'package:reflectable/mirrors.dart' as m;
// ignore:unused_import
import 'package:reflectable/src/reflectable_builder_based.dart' as r;
// ignore:unused_import
import 'package:reflectable/reflectable.dart' as r show Reflectable;

Regards

eernstg commented 4 years ago

I created https://github.com/dart-lang/reflectable/pull/204 to do this.

It could be argued that we shouldn't keep adding linter directives like this (maybe we should offer a more general mechanism for including arbitrary code into one or more locations in the generated file). But for this particular lint it is actually justified by the nature of the reflectable code generation: Reflectable generates code that does need to import arbitrary libraries that are reachable via a chain of imports, because it may need to denote declarations in such libraries in order to provide reflection support as specified by the developer.

eernstg commented 4 years ago

Thanks! ;-) Reflectable 2.2.2 was just published.