Skip to content

Commit

Permalink
Migrate from pedantic to lints ^2.0.0 with lints/recommended.yaml (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse authored Sep 7, 2022
1 parent f9009ce commit 5f2eb82
Show file tree
Hide file tree
Showing 41 changed files with 876 additions and 640 deletions.
35 changes: 34 additions & 1 deletion chopper/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
include: package:pedantic/analysis_options.yaml
include: package:lints/recommended.yaml

analyzer:
exclude:
- "**.g.dart"
- "**.chopper.dart"
- "**.mocks.dart"
- "example/**"
plugins:
- dart_code_metrics

dart_code_metrics:
metrics:
cyclomatic-complexity: 20
number-of-arguments: 4
maximum-nesting-level: 5
number-of-parameters: 7
metrics-exclude:
- test/**
rules:
- newline-before-return
- no-boolean-literal-compare
- no-empty-block
- prefer-trailing-comma
- prefer-conditional-expressions
- no-equal-then-else
anti-patterns:
- long-method
- long-parameter-list

linter:
rules:
avoid_print: true
prefer_single_quotes: true
1 change: 1 addition & 0 deletions chopper/example/definition.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';

import 'package:chopper/chopper.dart';

part 'definition.chopper.dart';
Expand Down
3 changes: 2 additions & 1 deletion chopper/example/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:chopper/chopper.dart';

import 'definition.dart';

Future<void> main() async {
final chopper = ChopperClient(
baseUrl: 'http://localhost:8000',
services: [
// the generated service
MyService.create(ChopperClient())
MyService.create(ChopperClient()),
],
converter: JsonConverter(),
);
Expand Down
2 changes: 1 addition & 1 deletion chopper/lib/chopper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ library chopper;
export 'src/annotations.dart';
export 'src/authenticator.dart';
export 'src/base.dart';
export 'src/constants.dart';
export 'src/interceptor.dart';
export 'src/request.dart';
export 'src/response.dart';
export 'src/utils.dart' hide mapToQuery;
export 'src/constants.dart';
96 changes: 32 additions & 64 deletions chopper/lib/src/annotations.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:async';

import 'package:meta/meta.dart';

import 'constants.dart';
import 'request.dart';
import 'response.dart';
import 'constants.dart';

/// Defines a Chopper API.
///
Expand Down Expand Up @@ -171,15 +173,10 @@ class Method {
@immutable
class Get extends Method {
const Get({
bool optionalBody = true,
String path = '',
Map<String, String> headers = const {},
}) : super(
HttpMethod.Get,
optionalBody: optionalBody,
path: path,
headers: headers,
);
super.optionalBody = true,
super.path,
super.headers,
}) : super(HttpMethod.Get);
}

/// Defines a method as an HTTP POST request.
Expand All @@ -188,30 +185,20 @@ class Get extends Method {
@immutable
class Post extends Method {
const Post({
bool optionalBody = false,
String path = '',
Map<String, String> headers = const {},
}) : super(
HttpMethod.Post,
optionalBody: optionalBody,
path: path,
headers: headers,
);
super.optionalBody,
super.path,
super.headers,
}) : super(HttpMethod.Post);
}

/// Defines a method as an HTTP DELETE request.
@immutable
class Delete extends Method {
const Delete({
bool optionalBody = true,
String path = '',
Map<String, String> headers = const {},
}) : super(
HttpMethod.Delete,
optionalBody: optionalBody,
path: path,
headers: headers,
);
super.optionalBody = true,
super.path,
super.headers,
}) : super(HttpMethod.Delete);
}

/// Defines a method as an HTTP PUT request.
Expand All @@ -220,60 +207,40 @@ class Delete extends Method {
@immutable
class Put extends Method {
const Put({
bool optionalBody = false,
String path = '',
Map<String, String> headers = const {},
}) : super(
HttpMethod.Put,
optionalBody: optionalBody,
path: path,
headers: headers,
);
super.optionalBody,
super.path,
super.headers,
}) : super(HttpMethod.Put);
}

/// Defines a method as an HTTP PATCH request.
/// Use the [Body] annotation to pass data to send.
@immutable
class Patch extends Method {
const Patch({
bool optionalBody = false,
String path = '',
Map<String, String> headers = const {},
}) : super(
HttpMethod.Patch,
optionalBody: optionalBody,
path: path,
headers: headers,
);
super.optionalBody,
super.path,
super.headers,
}) : super(HttpMethod.Patch);
}

/// Defines a method as an HTTP HEAD request.
@immutable
class Head extends Method {
const Head({
bool optionalBody = true,
String path = '',
Map<String, String> headers = const {},
}) : super(
HttpMethod.Head,
optionalBody: optionalBody,
path: path,
headers: headers,
);
super.optionalBody = true,
super.path,
super.headers,
}) : super(HttpMethod.Head);
}

@immutable
class Options extends Method {
const Options({
bool optionalBody = true,
String path = '',
Map<String, String> headers = const {},
}) : super(
HttpMethod.Options,
optionalBody: optionalBody,
path: path,
headers: headers,
);
super.optionalBody = true,
super.path,
super.headers,
}) : super(HttpMethod.Options);
}

/// A function that should convert the body of a [Request] to the HTTP representation.
Expand Down Expand Up @@ -377,6 +344,7 @@ class Multipart {
@immutable
class Part {
final String? name;

const Part([this.name]);
}

Expand Down
7 changes: 5 additions & 2 deletions chopper/lib/src/authenticator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import 'package:chopper/chopper.dart';
/// This method should return a [Request] that includes credentials to satisfy an authentication challenge received in
/// [response]. It should return `null` if the challenge cannot be satisfied.
abstract class Authenticator {
FutureOr<Request?> authenticate(Request request, Response response,
[Request? originalRequest]);
FutureOr<Request?> authenticate(
Request request,
Response response, [
Request? originalRequest,
]);
}
Loading

0 comments on commit 5f2eb82

Please sign in to comment.