Skip to content

Commit

Permalink
chore: add more strct linting to generated projects
Browse files Browse the repository at this point in the history
  • Loading branch information
jtdLab committed Aug 25, 2023
1 parent 9593f4b commit e3ae480
Show file tree
Hide file tree
Showing 144 changed files with 1,164 additions and 1,014 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ linter:
- camel_case_extensions
- camel_case_types
- cancel_subscriptions
# - cascade_invocations TODO good in source bad in test code
- cast_nullable_to_non_nullable
- collection_methods_unrelated_type
- combinators_ordering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class {{name.pascalCase()}}Bloc extends Bloc<{{name.pascalCase()}}Event, {{name.
const {{name.pascalCase()}}Initial(),
) {
// Register handlers
on<{{name.pascalCase()}}Started>(
(event, emit) => _onStarted(event, emit),
);
on<{{name.pascalCase()}}Started>(_onStarted);
}

/// Handle incoming [{{name.pascalCase()}}Started] event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class {{entity_name.pascalCase()}}Dto with _${{entity_name.pascalCase()}}Dto {
// TODO: add more fields here
}) = _{{entity_name.pascalCase()}}Dto;

const {{entity_name.pascalCase()}}Dto._();

factory {{entity_name.pascalCase()}}Dto.fromDomain({{entity_name.pascalCase()}} domain) {
return {{entity_name.pascalCase()}}Dto(
id: domain.id,
);
}

factory {{entity_name.pascalCase()}}Dto.fromJson(Map<String, dynamic> json) =>
_${{entity_name.pascalCase()}}DtoFromJson(json);

const {{entity_name.pascalCase()}}Dto._();

{{entity_name.pascalCase()}} toDomain() {
return {{entity_name.pascalCase()}}(
id: id,
);
}

factory {{entity_name.pascalCase()}}Dto.fromJson(Map<String, dynamic> json) =>
_${{entity_name.pascalCase()}}DtoFromJson(json);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ void main() {
group('.()', () {
test('returns correct instance', () {
// Act
final {{entity_name.camelCase()}}Dto = {{entity_name.pascalCase()}}Dto(id: 'some_id');
const {{entity_name.camelCase()}}Dto = {{entity_name.pascalCase()}}Dto(id: 'some_id');

// Assert
expect({{entity_name.camelCase()}}Dto.id, 'some_id');
Expand All @@ -17,10 +17,10 @@ void main() {
group('.fromDomain()', () {
test('returns correct instance', () {
// Arrange
final {{entity_name.camelCase()}} = {{entity_name.pascalCase()}}(id: 'some_id');
const {{entity_name.camelCase()}} = {{entity_name.pascalCase()}}(id: 'some_id');

// Act + Assert
expect({{entity_name.pascalCase()}}Dto.fromDomain({{entity_name.camelCase()}}), {{entity_name.pascalCase()}}Dto(id: 'some_id'));
expect({{entity_name.pascalCase()}}Dto.fromDomain({{entity_name.camelCase()}}), const {{entity_name.pascalCase()}}Dto(id: 'some_id'));
});
});

Expand All @@ -30,7 +30,7 @@ void main() {
final {{entity_name.camelCase()}}Json = {'id': 'some_id'};

// Act + Assert
expect({{entity_name.pascalCase()}}Dto.fromJson({{entity_name.camelCase()}}Json), {{entity_name.pascalCase()}}Dto(id: 'some_id'));
expect({{entity_name.pascalCase()}}Dto.fromJson({{entity_name.camelCase()}}Json), const {{entity_name.pascalCase()}}Dto(id: 'some_id'));
});

test('throws when json is invalid', () {
Expand All @@ -42,17 +42,17 @@ void main() {
group('.toDomain()', () {
test('returns correct entity', () {
// Arrange
final {{entity_name.camelCase()}}Dto = {{entity_name.pascalCase()}}Dto(id: 'some_id');
const {{entity_name.camelCase()}}Dto = {{entity_name.pascalCase()}}Dto(id: 'some_id');

// Act + Assert
expect({{entity_name.camelCase()}}Dto.toDomain(), {{entity_name.pascalCase()}}(id: 'some_id'));
expect({{entity_name.camelCase()}}Dto.toDomain(), const {{entity_name.pascalCase()}}(id: 'some_id'));
});
});

group('.toJson()', () {
test('returns correct json', () {
// Arrange
final {{entity_name.camelCase()}}Dto = {{entity_name.pascalCase()}}Dto(id: 'some_id');
const {{entity_name.camelCase()}}Dto = {{entity_name.pascalCase()}}Dto(id: 'some_id');

// Act + Assert
expect({{entity_name.camelCase()}}Dto.toJson(), {'id': 'some_id'});
Expand Down
26 changes: 1 addition & 25 deletions bricks/di_package/__brick__/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

include: ../../../analysis_options.yaml
# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
3 changes: 2 additions & 1 deletion bricks/di_package/__brick__/lib/{{project_name}}_di.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Dependency Injection for {{project_name.titleCase()}}.
///
/// This contains the container and annotations required for dependency injection.
/// This contains the container and annotations required for dependency
/// injection.
///
/// To use, import `package:{{project_name}}_di/{{project_name}}_di.dart`.
library {{project_name}}_di;
Expand Down
1 change: 0 additions & 1 deletion bricks/di_package/__brick__/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ dependencies:
injectable: ^2.3.0

dev_dependencies:
lints: ^2.1.1
test: ^1.24.6
26 changes: 1 addition & 25 deletions bricks/domain_package/__brick__/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

include: ../../../../analysis_options.yaml
# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// TODO: description here
// TODO: description here
///
/// To use, import `package:{{project_name}}_domain{{#has_name}}_{{name}}{{/has_name}}/{{project_name}}_domain{{#has_name}}_{{name}}{{/has_name}}.dart`.
library {{project_name}}_domain{{#has_name}}_{{name}}{{/has_name}};
1 change: 0 additions & 1 deletion bricks/domain_package/__brick__/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies:
freezed_annotation: ^2.4.1

dev_dependencies:
lints: ^2.1.1
test: ^1.24.6
build_runner: ^2.4.6
freezed: ^2.4.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void main() {
group('.()', () {
test('returns correct instance', () {
// Arrange + Act
final {{name.camelCase()}} = {{name.pascalCase()}}(id: 'some_id');
const {{name.camelCase()}} = {{name.pascalCase()}}(id: 'some_id');

// Assert
expect({{name.camelCase()}}.id, 'some_id');
Expand Down
28 changes: 1 addition & 27 deletions bricks/infrastructure_package/__brick__/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

include: ../../../../analysis_options.yaml
# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

analyzer:
exclude:
- '**/**.g.dart'
errors:
invalid_annotation_target: ignore

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import 'package:injectable/injectable.dart';
///
/// For more info see: https://pub.dev/packages/injectable#including-micropackages-and-external-modules
@InjectableInit.microPackage()
initMicroPackage() {}
void initMicroPackage() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@GeneratedMicroModule;{{project_name.pascalCase()}}Infrastructure{{#has_name}}{{name.pascalCase()}}{{/has_name}}PackageModule;package:{{project_name}}_infrastructure{{#has_name}}_{{name}}{{/has_name}}/src/injection.module.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: unnecessary_lambdas
// ignore_for_file: lines_longer_than_80_chars
// ignore_for_file: type=lint
// coverage:ignore-file

// ignore_for_file: no_leading_underscores_for_library_prefixes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// TODO: description here
// TODO: description here
///
/// To use, import `package:{{project_name}}_infrastructure{{#has_name}}_{{name}}{{/has_name}}/{{project_name}}_infrastructure{{#has_name}}_{{name}}{{/has_name}}.dart`.
library {{project_name}}_infrastructure{{#has_name}}_{{name}}{{/has_name}};
Expand Down
1 change: 0 additions & 1 deletion bricks/infrastructure_package/__brick__/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dependencies:
{{project_name}}_domain{{#has_name}}_{{name}}{{/has_name}}:

dev_dependencies:
lints: ^2.1.1
test: ^1.24.6
mocktail: ^1.0.0
build_runner: ^2.4.6
Expand Down
26 changes: 1 addition & 25 deletions bricks/logging_package/__brick__/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

include: ../../../analysis_options.yaml
# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
2 changes: 1 addition & 1 deletion bricks/logging_package/__brick__/lib/src/injection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import 'package:injectable/injectable.dart';
///
/// For more info see: https://pub.dev/packages/injectable#including-micropackages-and-external-modules
@InjectableInit.microPackage()
initMicroPackage() {}
void initMicroPackage() {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//@GeneratedMicroModule;{{project_name.pascalCase()}}LoggingPackageModule;package:{{project_name}}_logging/src/injection.module.dart
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: unnecessary_lambdas
// ignore_for_file: lines_longer_than_80_chars
// ignore_for_file: type=lint
// coverage:ignore-file

// ignore_for_file: no_leading_underscores_for_library_prefixes
Expand Down
7 changes: 4 additions & 3 deletions bricks/logging_package/__brick__/lib/src/logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ enum Level {
wtf(1200),
nothing(2000);

final int value;
const Level(this.value);

final int value;

bool operator >=(Level level) => value >= level.value;
}

Expand All @@ -29,13 +30,13 @@ typedef LogCommand = void Function(

/// The logger of the application.
abstract class {{project_name.pascalCase()}}Logger {
{{project_name.pascalCase()}}Logger(this.level);

final Level level;

@visibleForTesting
LogCommand? logCommandOverrides;

{{project_name.pascalCase()}}Logger(this.level);

LogCommand get _logCommand => logCommandOverrides ?? log;

/// Log a message at level [Level.verbose].
Expand Down
1 change: 0 additions & 1 deletion bricks/logging_package/__brick__/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies:
injectable: ^2.3.0

dev_dependencies:
lints: ^2.1.1
test: ^1.24.6
mocktail: ^1.0.0
build_runner: ^2.4.6
Expand Down
1 change: 1 addition & 0 deletions bricks/logging_package/__brick__/test/mocks.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:mocktail/mocktail.dart';

// ignore: one_member_abstracts
abstract class _LogCommand {
void call(
String message, {
Expand Down
Loading

0 comments on commit e3ae480

Please sign in to comment.