doubled_slash_in_uri
Reports a doubled slash in the path of an import, export or part URI, such as 'src//state.dart'. Write a single slash.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- writes a single slash for each run of slashes in the path
What it reports
Section titled “What it reports”The URI of an import, export, part or part of directive, or of a configuration of one, whose path holds a doubled slash: import 'src//state.dart';.
- The slashes of a scheme and its authority,
file:///, are no doubled slash. - A
package:ordart:URI with a doubled slash does not resolve at all, which the analyzer reports as an error of its own.
The URI resolves, so nothing else says a word, except the SDK lint below where a project switches it on. Yet it is a second spelling of the file. A program that imports the file under both spellings loads it as two libraries, each with its own top-level variables: a counter that one part of the program changes stays as it is for the other. Measured with the Dart VM, src//state.dart and src/state.dart gave two counters.
Example
Section titled “Example”import 'src//state.dart';import 'src/state.dart';The fix writes a single slash for each run of slashes, where the URI is written without escapes.
Left to the SDK
Section titled “Left to the SDK”From Dart 3.12 on, the SDK lint simple_directive_paths reports a relative URI with a doubled slash as well, where the project switches it on. No preset of assay switches it on: an SDK before 3.12 does not know the lint, and warns of its name in the options file.
One defect at one place is one violation. So on Dart 3.12 or later, where your configuration has the lint on and does not give it the severity ignore under analyzer.errors, the rule leaves relative URIs to it: both hosts drop those violations, and the lint reports the URI as an info, which is this rule’s tier as well. The lint leaves out a URI with a scheme or an absolute path, file:///a//b.dart or /a//b.dart, and the rule keeps reporting those on every SDK.
Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// Kept as written to reproduce a loader bug in a test.// ignore: assay/doubled_slash_in_uri// ignore_for_file: assay/doubled_slash_in_uri silences it in a whole file, and // ignore: doubled_slash_in_uri without the prefix works too. See Suppressions.