avoid-incorrect-uri
- Group
- Suspicious
- Path
lint/suspicious/avoid-incorrect-uri- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 74 of 512
Reject runtime-invalid Uri constructor arguments: conflicting path or query inputs and query parameter values that are neither null, strings nor iterables of strings. Only resolved dart:core Uri constructors are checked; unknown values are skipped.
Invalid
import 'dart:core';
import 'dart:core' as core;
void f(int count) {
Uri(queryParameters: {'count': 1});
Uri.http('example.com', '/', {'flag': false});
Uri.https('example.com', '/', {'count': 1.5});
Uri(path: '', pathSegments: ['']);
new Uri(queryParameters: {'count': count});
core.Uri(queryParameters: {'count': 3});
core.Uri.https('example.com', '/', {'values': ['valid', 2]});
Uri(queryParameters: {'values': [null]});
Uri(query: 'key=value', queryParameters: {'key': 'value'});
}
void collections(bool includeCount, List<int> counts) {
Uri(queryParameters: {if (includeCount) 'count': 1});
Uri(queryParameters: {
if (includeCount) 'count': 1
else 'other': false,
for (final count in counts) 'count$count': 2,
for (final count in counts)
if (includeCount) 'nested$count': 1,
});
}void f(int count) { Uri(queryParameters: {'count': 1}); Uri(queryParameters: {'count': 1}); Uri.http('example.com', '/', {'flag': false}); Uri.http('example.com', '/', {'flag': false}); Uri.https('example.com', '/', {'count': 1.5}); Uri.https('example.com', '/', {'count': 1.5}); Uri(path: '', pathSegments: ['']); Uri(path: '', pathSegments: ['']); new Uri(queryParameters: {'count': count}); new Uri(queryParameters: {'count': count}); core.Uri(queryParameters: {'count': 3}); core.Uri(queryParameters: {'count': 3}); core.Uri.https('example.com', '/', {'values': ['valid', 2]}); core.Uri.https('example.com', '/', {'values': ['valid', 2]}); Uri(queryParameters: {'values': [null]}); Uri(queryParameters: {'values': [null]}); Uri(query: 'key=value', queryParameters: {'key': 'value'});void collections(bool includeCount, List<int> counts) { Uri(queryParameters: {if (includeCount) 'count': 1}); Uri(queryParameters: { if (includeCount) 'count': 1 if (includeCount) 'count': 1 else 'other': false, else 'other': false, for (final count in counts) 'count$count': 2, for (final count in counts) if (includeCount) 'nested$count': 1,Valid
import 'dart:core';
import 'dart:core' as core;
void f(dynamic unknown, Iterable<String> values, String? path) {
Uri(fragment: '', queryParameters: {'hello': 'world'});
Uri.https('example.com', '/', {'hello': 'world'});
Uri.http('example.com', '/', {'hello': ['world', 'again']});
Uri(path: '');
Uri(pathSegments: ['']);
Uri(path: null, pathSegments: ['']);
Uri(path: path, pathSegments: ['']);
Uri(queryParameters: {'empty': null});
Uri(queryParameters: {'empty': <String>[]});
Uri(queryParameters: {'values': <String>{'first', 'second'}});
Uri(queryParameters: {'values': values});
Uri(queryParameters: {'unknown': unknown});
core.Uri(queryParameters: {'hello': 'world'});
Uri(query: 'key=value');
Uri(queryParameters: {'key': 'value'});
Uri(query: null, queryParameters: {'key': 'value'});
Uri(query: 'key=value', queryParameters: null);
Uri(query: path, queryParameters: {'key': 'value'});
core.Uri(query: '', queryParameters: <String, String>{});
Uri(query: (r''), queryParameters: {'key': 'value'});
}
void shadowed(dynamic Uri) {
Uri(queryParameters: {'count': 1});
Uri.https('', '', {'count': 1});
}
class CustomUri {
CustomUri({dynamic queryParameters});
}
void other() {
CustomUri(queryParameters: {'count': 1});
}
void collections(bool includeCount, List<String> values) {
Uri(queryParameters: {
if (includeCount) 'count': '1' else 'other': null,
for (final value in values) value: value,
for (final value in values)
if (includeCount) 'nested$value': <String>['valid'],
});
}Configure avoid-incorrect-uri
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"suspicious": {
"avoid-incorrect-uri": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/suspicious/avoid-incorrect-uri: <reason>More suspicious rules
- avoid-inverted-boolean-checks
Prefer direct equality comparisons and De Morgan forms in control-flow conditions.
- avoid-multi-assignment
Split chained assignments into separate statements.
- avoid-mutating-parameters
Detects writes through named function, method and constructor parameter objects.
- avoid-negated-conditions
Prefer positive conditions when both branches can be swapped.
- avoid-nested-assignments
Require assignments to be standalone statements, arrow bodies or loop operations.
- avoid-non-final-exception-class-fields
Exception and Error payloads should not change after construction.
- avoid-passing-async-when-sync-expected
avoid-passing-async-when-sync-expectedrecommendedFlags an
asyncclosure passed to a proven synchronous callback parameter. - avoid-passing-bloc-to-blocbloc
Rejects direct Bloc and Cubit arguments to other blocs.