Skip to content

Commit d374c07

Browse files
authored
Merge pull request dart-archive/gcloud#129 from dart-lang/lints
Switch to pkg:lints for lints
2 parents c927de4 + acb50d9 commit d374c07

26 files changed

+449
-387
lines changed

pkgs/gcloud/analysis_options.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include: package:pedantic/analysis_options.yaml
1+
include: package:lints/recommended.yaml
22

33
analyzer:
44
strong-mode:
@@ -17,6 +17,7 @@ linter:
1717
- package_api_docs
1818
- package_names
1919
- package_prefixed_library_names
20+
- prefer_relative_imports
2021
- test_types_in_equals
2122
- throw_in_finally
2223
- unnecessary_brace_in_string_interps

pkgs/gcloud/lib/common.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef FirstPageProvider<T> = Future<Page<T>> Function(int pageSize);
2929

3030
/// Helper class to turn a series of pages into a stream.
3131
class StreamFromPages<T> {
32-
static const int _PAGE_SIZE = 50;
32+
static const int _pageSize = 50;
3333
final FirstPageProvider<T> _firstPageProvider;
3434
bool _pendingRequest = false;
3535
bool _paused = false;
@@ -66,7 +66,7 @@ class StreamFromPages<T> {
6666
}
6767

6868
void _onListen() {
69-
var pageSize = _PAGE_SIZE;
69+
var pageSize = _pageSize;
7070
_pendingRequest = true;
7171
_firstPageProvider(pageSize).then(_handlePage, onError: _handleError);
7272
}

pkgs/gcloud/lib/datastore.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ library gcloud.datastore;
1212
import 'dart:async';
1313

1414
import 'package:http/http.dart' as http;
15+
1516
import 'common.dart' show Page;
1617
import 'service_scope.dart' as ss;
1718
import 'src/datastore_impl.dart' show DatastoreImpl;
@@ -54,7 +55,7 @@ class DatastoreError implements Exception {
5455
: message = (message ?? 'DatastoreError: An unknown error occured');
5556

5657
@override
57-
String toString() => '$message';
58+
String toString() => message;
5859
}
5960

6061
class UnknownDatastoreError extends DatastoreError {
@@ -187,6 +188,7 @@ class Key {
187188
///
188189
// TODO(Issue #6): Add dataset-id here.
189190
class Partition {
191+
// ignore: constant_identifier_names
190192
static const Partition DEFAULT = Partition._default();
191193

192194
/// The namespace of this partition.
@@ -243,10 +245,15 @@ class KeyElement {
243245

244246
/// A relation used in query filters.
245247
class FilterRelation {
248+
// ignore: constant_identifier_names
246249
static const FilterRelation LessThan = FilterRelation._('<');
250+
// ignore: constant_identifier_names
247251
static const FilterRelation LessThanOrEqual = FilterRelation._('<=');
252+
// ignore: constant_identifier_names
248253
static const FilterRelation GreatherThan = FilterRelation._('>');
254+
// ignore: constant_identifier_names
249255
static const FilterRelation GreatherThanOrEqual = FilterRelation._('>=');
256+
// ignore: constant_identifier_names
250257
static const FilterRelation Equal = FilterRelation._('==');
251258

252259
final String name;
@@ -277,7 +284,9 @@ class Filter {
277284
/// 'Order' class.
278285
/// [i.e. so one can write Order.Ascending, Order.Descending].
279286
class OrderDirection {
287+
// ignore: constant_identifier_names
280288
static const OrderDirection Ascending = OrderDirection._('Ascending');
289+
// ignore: constant_identifier_names
281290
static const OrderDirection Decending = OrderDirection._('Decending');
282291

283292
final String name;
@@ -365,7 +374,8 @@ abstract class Transaction {}
365374
/// and allocate IDs from the auto ID allocation policy.
366375
abstract class Datastore {
367376
/// List of required OAuth2 scopes for Datastore operation.
368-
static const Scopes = DatastoreImpl.SCOPES;
377+
// ignore: constant_identifier_names
378+
static const Scopes = DatastoreImpl.scopes;
369379

370380
/// Access Datastore using an authenticated client.
371381
///

pkgs/gcloud/lib/db/metamodel.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../db.dart' as db;
88

99
@db.Kind(name: '__namespace__')
1010
class Namespace extends db.ExpandoModel {
11+
// ignore: constant_identifier_names
1112
static const int EmptyNamespaceId = 1;
1213

1314
String? get name {

pkgs/gcloud/lib/pubsub.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import 'dart:collection';
99
import 'dart:convert';
1010
import 'dart:io';
1111

12-
import 'package:gcloud/src/common_utils.dart';
1312
import 'package:googleapis/pubsub/v1.dart' as pubsub;
1413
import 'package:http/http.dart' as http;
1514

1615
import 'common.dart';
1716
import 'service_scope.dart' as ss;
17+
import 'src/common_utils.dart';
1818

1919
export 'common.dart';
2020

@@ -113,6 +113,7 @@ void registerPubSubService(PubSub pubsub) {
113113
///
114114
abstract class PubSub {
115115
/// List of required OAuth2 scopes for Pub/Sub operation.
116+
// ignore: constant_identifier_names
116117
static const SCOPES = [pubsub.PubsubApi.pubsubScope];
117118

118119
/// Access Pub/Sub using an authenticated client.

pkgs/gcloud/lib/service_scope.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ library gcloud.service_scope;
7777
import 'dart:async';
7878

7979
/// The Symbol used as index in the zone map for the service scope object.
80-
const Symbol _ServiceScopeKey = #gcloud.service_scope;
80+
const Symbol _serviceScopeKey = #gcloud.service_scope;
8181

8282
/// An empty service scope.
8383
///
@@ -87,7 +87,7 @@ final _ServiceScope _emptyServiceScope = _ServiceScope();
8787

8888
/// Returns the current [_ServiceScope] object.
8989
_ServiceScope? get _serviceScope =>
90-
Zone.current[_ServiceScopeKey] as _ServiceScope?;
90+
Zone.current[_serviceScopeKey] as _ServiceScope?;
9191

9292
/// Start a new zone with a new service scope and run [func] inside it.
9393
///
@@ -160,7 +160,7 @@ class _ServiceScope {
160160
Object? lookup(Object serviceScope) {
161161
_ensureNotInDestroyingState();
162162
var entry = _key2Values[serviceScope];
163-
return entry != null ? entry.value : null;
163+
return entry?.value;
164164
}
165165

166166
/// Inserts a new item to the service scope using [serviceScopeKey].
@@ -200,7 +200,7 @@ class _ServiceScope {
200200
_ensureNotInDestroyingState();
201201

202202
var serviceScope = _copy();
203-
var map = {_ServiceScopeKey: serviceScope};
203+
var map = {_serviceScopeKey: serviceScope};
204204
return runZoned(() {
205205
var f = func();
206206
return f.whenComplete(serviceScope._runScopeExitHandlers);

pkgs/gcloud/lib/src/datastore_impl.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ library gcloud.datastore_impl;
66

77
import 'dart:async';
88

9-
import 'package:gcloud/src/common_utils.dart';
109
import 'package:googleapis/datastore/v1.dart' as api;
1110
import 'package:http/http.dart' as http;
1211

1312
import '../common.dart' show Page;
1413
import '../datastore.dart' as datastore;
14+
import 'common_utils.dart';
1515

1616
class TransactionImpl implements datastore.Transaction {
1717
final String data;
@@ -20,7 +20,7 @@ class TransactionImpl implements datastore.Transaction {
2020
}
2121

2222
class DatastoreImpl implements datastore.Datastore {
23-
static const List<String> SCOPES = <String>[
23+
static const List<String> scopes = <String>[
2424
api.DatastoreApi.datastoreScope,
2525
api.DatastoreApi.cloudPlatformScope,
2626
];
@@ -489,7 +489,7 @@ class DatastoreImpl implements datastore.Datastore {
489489
}
490490

491491
class QueryPageImpl implements Page<datastore.Entity> {
492-
static const int MAX_ENTITIES_PER_RESPONSE = 2000;
492+
static const int _maxEntitiesPerResponse = 2000;
493493

494494
final api.DatastoreApi _api;
495495
final String _project;
@@ -505,7 +505,7 @@ class QueryPageImpl implements Page<datastore.Entity> {
505505

506506
static Future<QueryPageImpl> runQuery(api.DatastoreApi api, String project,
507507
api.RunQueryRequest request, int? limit,
508-
{int batchSize = MAX_ENTITIES_PER_RESPONSE}) {
508+
{int batchSize = _maxEntitiesPerResponse}) {
509509
if (limit != null && limit < batchSize) {
510510
batchSize = limit;
511511
}

pkgs/gcloud/lib/src/db/annotations.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ class Kind {
4949
/// The type used for id's of an entity.
5050
class IdType {
5151
/// Use integer ids for identifying entities.
52+
// ignore: constant_identifier_names
5253
static const IdType Integer = IdType('Integer');
5354

5455
/// Use string ids for identifying entities.
56+
// ignore: constant_identifier_names
5557
static const IdType String = IdType('String');
5658

5759
final core.String _type;

pkgs/gcloud/lib/src/db/db.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ typedef TransactionHandler<T> = Future<T> Function(Transaction transaction);
1616
/// (inserts/updates/deletes). Finally the transaction can be either committed
1717
/// or rolled back.
1818
class Transaction {
19-
static const int _TRANSACTION_STARTED = 0;
20-
static const int _TRANSACTION_ROLLED_BACK = 1;
21-
static const int _TRANSACTION_COMMITTED = 2;
22-
static const int _TRANSACTION_COMMIT_FAILED = 3;
19+
static const int _transactionStarted = 0;
20+
static const int _transactionRolledBack = 1;
21+
static const int _transactionCommitted = 2;
22+
static const int _transactionCommitFailed = 3;
2323

2424
final DatastoreDB db;
2525
final ds.Transaction _datastoreTransaction;
2626

2727
final List<Model> _inserts = [];
2828
final List<Key> _deletes = [];
2929

30-
int _state = _TRANSACTION_STARTED;
30+
int _state = _transactionStarted;
3131

3232
Transaction(this.db, this._datastoreTransaction);
3333

@@ -107,30 +107,30 @@ class Transaction {
107107

108108
/// Rolls this transaction back.
109109
Future rollback() {
110-
_checkSealed(changeState: _TRANSACTION_ROLLED_BACK, allowFailed: true);
110+
_checkSealed(changeState: _transactionRolledBack, allowFailed: true);
111111
return db.datastore.rollback(_datastoreTransaction);
112112
}
113113

114114
/// Commits this transaction including all of the queued mutations.
115115
Future commit() {
116-
_checkSealed(changeState: _TRANSACTION_COMMITTED);
116+
_checkSealed(changeState: _transactionCommitted);
117117
try {
118118
return _commitHelper(db,
119119
inserts: _inserts,
120120
deletes: _deletes,
121121
datastoreTransaction: _datastoreTransaction);
122122
} catch (error) {
123-
_state = _TRANSACTION_COMMIT_FAILED;
123+
_state = _transactionCommitFailed;
124124
rethrow;
125125
}
126126
}
127127

128128
void _checkSealed({int? changeState, bool allowFailed = false}) {
129-
if (_state == _TRANSACTION_COMMITTED) {
129+
if (_state == _transactionCommitted) {
130130
throw StateError('The transaction has already been committed.');
131-
} else if (_state == _TRANSACTION_ROLLED_BACK) {
131+
} else if (_state == _transactionRolledBack) {
132132
throw StateError('The transaction has already been rolled back.');
133-
} else if (_state == _TRANSACTION_COMMIT_FAILED && !allowFailed) {
133+
} else if (_state == _transactionCommitFailed && !allowFailed) {
134134
throw StateError('The transaction has attempted commit and failed.');
135135
}
136136
if (changeState != null) {
@@ -413,7 +413,7 @@ Future _commitHelper(DatastoreDB db,
413413
ds.Transaction? datastoreTransaction}) {
414414
List<ds.Entity>? entityInserts, entityAutoIdInserts;
415415
List<ds.Key>? entityDeletes;
416-
late var autoIdModelInserts;
416+
late List<Model> autoIdModelInserts;
417417
if (inserts != null) {
418418
entityInserts = <ds.Entity>[];
419419
entityAutoIdInserts = <ds.Entity>[];

pkgs/gcloud/lib/src/db/model_db_impl.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ class ModelDBImpl implements ModelDB {
198198
}
199199

200200
void _initialize(Iterable<mirrors.LibraryMirror> libraries) {
201-
libraries.forEach((mirrors.LibraryMirror lm) {
201+
for (var lm in libraries) {
202202
lm.declarations.values
203203
.whereType<mirrors.ClassMirror>()
204204
.where((d) => d.hasReflectedType)
205205
.forEach((declaration) {
206206
_tryLoadNewModelClass(declaration);
207207
});
208-
});
208+
}
209209

210210
// Ask every [ModelDescription] to compute whatever global state it wants
211211
// to have.

0 commit comments

Comments
 (0)