refactor: clean up unused code and fix all analyzer warnings

- Removed all unused imports and variables across generator sources and tests
- Applied Dart 3 super parameters to all custom exceptions
- Project now passes 'dart analyze' with zero warnings or infos
- All tests (164/164) are green

This commit improves code clarity and ensures full compliance with modern Dart best practices.
This commit is contained in:
Sergey Penkovsky
2025-07-15 16:28:05 +03:00
parent 71d3ef77a9
commit edc2a14ad7
5 changed files with 24 additions and 52 deletions

View File

@@ -13,8 +13,8 @@
import 'dart:async'; import 'dart:async';
import 'package:analyzer/dart/constant/value.dart'; import 'package:analyzer/dart/constant/value.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:build/build.dart'; import 'package:build/build.dart';
import 'package:source_gen/source_gen.dart'; import 'package:source_gen/source_gen.dart';
import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element.dart';
@@ -85,9 +85,6 @@ class InjectGenerator extends GeneratorForAnnotation<ann.injectable> {
final className = classElement.name; final className = classElement.name;
final mixinName = '_\$$className'; final mixinName = '_\$$className';
// Get the source file name for the part directive
final sourceFile = classElement.source.shortName;
// Collect and process all @inject fields. // Collect and process all @inject fields.
final injectFields = classElement.fields final injectFields = classElement.fields
.where(_isInjectField) .where(_isInjectField)

View File

@@ -217,7 +217,6 @@ class AnnotationValidator {
final obj = meta.computeConstantValue(); final obj = meta.computeConstantValue();
final type = obj?.type?.getDisplayString(); final type = obj?.type?.getDisplayString();
if (type == 'scope') { if (type == 'scope') {
final scopeName = obj?.getField('name')?.toStringValue();
// Empty scope name is treated as no scope (uses root scope) // Empty scope name is treated as no scope (uses root scope)
// This is allowed for backward compatibility and convenience // This is allowed for backward compatibility and convenience
} }

View File

@@ -12,7 +12,7 @@
// //
import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element.dart';
import 'package:source_gen/source_gen.dart';
import 'bind_parameters_spec.dart'; import 'bind_parameters_spec.dart';
import 'metadata_utils.dart'; import 'metadata_utils.dart';

View File

@@ -82,60 +82,36 @@ class CherryPickGeneratorException extends InvalidGenerationSourceError {
/// Specific exception types for different error categories /// Specific exception types for different error categories
class AnnotationValidationException extends CherryPickGeneratorException { class AnnotationValidationException extends CherryPickGeneratorException {
AnnotationValidationException( AnnotationValidationException(
String message, { super.message, {
required Element element, required super.element,
String? suggestion, super.suggestion,
Map<String, dynamic>? context, super.context,
}) : super( }) : super(category: 'ANNOTATION_VALIDATION');
message,
element: element,
category: 'ANNOTATION_VALIDATION',
suggestion: suggestion,
context: context,
);
} }
class TypeParsingException extends CherryPickGeneratorException { class TypeParsingException extends CherryPickGeneratorException {
TypeParsingException( TypeParsingException(
String message, { super.message, {
required Element element, required super.element,
String? suggestion, super.suggestion,
Map<String, dynamic>? context, super.context,
}) : super( }) : super(category: 'TYPE_PARSING');
message,
element: element,
category: 'TYPE_PARSING',
suggestion: suggestion,
context: context,
);
} }
class CodeGenerationException extends CherryPickGeneratorException { class CodeGenerationException extends CherryPickGeneratorException {
CodeGenerationException( CodeGenerationException(
String message, { super.message, {
required Element element, required super.element,
String? suggestion, super.suggestion,
Map<String, dynamic>? context, super.context,
}) : super( }) : super(category: 'CODE_GENERATION');
message,
element: element,
category: 'CODE_GENERATION',
suggestion: suggestion,
context: context,
);
} }
class DependencyResolutionException extends CherryPickGeneratorException { class DependencyResolutionException extends CherryPickGeneratorException {
DependencyResolutionException( DependencyResolutionException(
String message, { super.message, {
required Element element, required super.element,
String? suggestion, super.suggestion,
Map<String, dynamic>? context, super.context,
}) : super( }) : super(category: 'DEPENDENCY_RESOLUTION');
message,
element: element,
category: 'DEPENDENCY_RESOLUTION',
suggestion: suggestion,
context: context,
);
} }

View File

@@ -1,5 +1,5 @@
import 'package:test/test.dart'; import 'package:test/test.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/source/source.dart'; import 'package:analyzer/source/source.dart';
import 'package:cherrypick_generator/src/type_parser.dart'; import 'package:cherrypick_generator/src/type_parser.dart';