Skip to content

Commit 81aa780

Browse files
eseidelisoos
andauthored
chore: add uneccessary_* lints (#115)
* chore: add uneccessary_* lints Adding: - unnecessary_null_checks - unnecessary_parenthesis - unnecessary_raw_strings Each of these found real cases where fixing with the lint improved readability (one could argue about the raw strings). * Add explicit null check in PostgreSQLFormatIdentifier * Remove duplicate try-catch loop --------- Co-authored-by: István Soós <[email protected]>
1 parent 18b22c5 commit 81aa780

File tree

8 files changed

+19
-15
lines changed

8 files changed

+19
-15
lines changed

analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ linter:
5757
- unnecessary_lambdas
5858
- unnecessary_new
5959
- unnecessary_null_aware_assignments
60+
- unnecessary_null_checks
61+
- unnecessary_parenthesis
62+
- unnecessary_raw_strings
6063
- unnecessary_statements
6164
- unnecessary_this
6265
- unrelated_type_equality_checks

example/v3/example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void main() async {
55
final connection = await PgConnection.open(database);
66
print('has connection!');
77

8-
final statement = await connection.prepare(PgSql(r"SELECT 'foo';"));
8+
final statement = await connection.prepare(PgSql("SELECT 'foo';"));
99
print('has statement');
1010
final result = await statement.run();
1111
print(result);

lib/src/binary_codec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ final _hex = <String>[
2828
'f',
2929
];
3030
final _numericRegExp = RegExp(r'^(\d*)(\.\d*)?$');
31-
final _leadingZerosRegExp = RegExp(r'^0+');
31+
final _leadingZerosRegExp = RegExp('^0+');
3232
final _trailingZerosRegExp = RegExp(r'0+$');
3333

3434
class PostgresBinaryEncoder<T extends Object>

lib/src/exceptions.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ class PostgreSQLException implements Exception {
4545
}
4646

4747
PostgreSQLException._(List<ErrorField> errorFields) {
48-
ErrorField finder(int identifer) => (errorFields.firstWhere(
49-
(ErrorField e) => e.identificationToken == identifer,
50-
orElse: () => ErrorField(null, null)));
48+
ErrorField finder(int identifier) => errorFields.firstWhere(
49+
(ErrorField e) => e.identificationToken == identifier,
50+
orElse: () => ErrorField(null, null));
5151

5252
severity = ErrorField.severityFromString(
5353
finder(ErrorField.SeverityIdentifier).text);

lib/src/query.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Query<T> {
6464

6565
void sendExtended(Socket socket, {CachedQuery? cacheQuery}) {
6666
if (cacheQuery != null) {
67-
fieldDescriptions = cacheQuery.fieldDescriptions!;
67+
fieldDescriptions = cacheQuery.fieldDescriptions;
6868
sendCachedQuery(socket, cacheQuery, substitutionValues);
6969

7070
return;
@@ -95,7 +95,7 @@ class Query<T> {
9595
];
9696

9797
if (statementIdentifier != null) {
98-
cache = CachedQuery(statementIdentifier!, formatIdentifiers);
98+
cache = CachedQuery(statementIdentifier, formatIdentifiers);
9999
}
100100

101101
socket.add(ClientMessage.aggregateBytes(messages));
@@ -350,9 +350,8 @@ class PostgreSQLFormatIdentifier {
350350
name = variableComponents.first;
351351

352352
final dataTypeString = variableComponents.last;
353-
try {
354-
type = typeStringToCodeMap[dataTypeString]!;
355-
} catch (e) {
353+
type = typeStringToCodeMap[dataTypeString];
354+
if (type == null) {
356355
throw FormatException(
357356
"Invalid type code in substitution variable '$t'");
358357
}

lib/src/text_codec.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class PostgresTextEncoder extends Converter<Object, String> {
5757
}
5858

5959
final backslashCodeUnit = r'\'.codeUnitAt(0);
60-
final quoteCodeUnit = r"'".codeUnitAt(0);
60+
final quoteCodeUnit = "'".codeUnitAt(0);
6161

6262
var quoteCount = 0;
6363
var backslashCount = 0;

lib/src/v3/types.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ enum PgDataType<Dart extends Object> {
158158

159159
static final Map<int, PgDataType> byTypeOid = Map.unmodifiable({
160160
for (final type in values)
161-
if (type.oid != null) type.oid!: type,
161+
if (type.oid != null) type.oid: type,
162162
});
163163

164164
static final Map<String, PgDataType> bySubstitutionName = Map.unmodifiable({
@@ -170,7 +170,7 @@ enum PgDataType<Dart extends Object> {
170170
if (type != serial &&
171171
type != bigSerial &&
172172
type.nameForSubstitution != null)
173-
type.nameForSubstitution!: type,
173+
type.nameForSubstitution: type,
174174
});
175175

176176
static final Map<PgDataType, _BinaryTypeCodec> _binaryCodecs = {};

test/map_return_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ void clearOidQueryCount(PostgreSQLConnection connection) {
142142
dm.simpleName.toString().contains('_oidCache'));
143143
// TODO(eseidel): Fix this by using @visibleForTesting instead of mirrors?
144144
// ignore: avoid_dynamic_calls
145-
(reflect(connection).getField(oidCacheMirror.simpleName).reflectee).clear();
145+
reflect(connection).getField(oidCacheMirror.simpleName).reflectee.clear();
146146
}
147147

148148
int getOidQueryCount(PostgreSQLConnection connection) {
@@ -154,6 +154,8 @@ int getOidQueryCount(PostgreSQLConnection connection) {
154154
dm.simpleName.toString().contains('_oidCache'));
155155
// TODO(eseidel): Fix this by using @visibleForTesting instead of mirrors?
156156
// ignore: avoid_dynamic_calls
157-
return (reflect(connection).getField(oidCacheMirror.simpleName).reflectee)
157+
return reflect(connection)
158+
.getField(oidCacheMirror.simpleName)
159+
.reflectee
158160
.queryCount as int;
159161
}

0 commit comments

Comments
 (0)