Skip to content

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

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: or dart: 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.

Violating
import 'src//state.dart';
Corrected
import 'src/state.dart';

The fix writes a single slash for each run of slashes, where the URI is written without escapes.

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.

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.

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.