Skip to content

Commit f66eb72

Browse files
authored
Use path as import prefix in lib/ and test/ (dart-lang#3471)
1 parent 34441f2 commit f66eb72

File tree

8 files changed

+53
-53
lines changed

8 files changed

+53
-53
lines changed

lib/src/dartdoc.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import 'package:dartdoc/src/validator.dart';
2323
import 'package:dartdoc/src/version.dart';
2424
import 'package:dartdoc/src/warnings.dart';
2525
import 'package:meta/meta.dart';
26-
import 'package:path/path.dart' as p;
26+
import 'package:path/path.dart' as path;
2727

2828
const String programName = 'dartdoc';
2929
// Update when pubspec version changes by running `pub run build_runner build`
@@ -72,7 +72,7 @@ class DartdocFileWriter implements FileWriter {
7272
}) {
7373
_validateMaxWriteStats(filePath, content.length);
7474
// Replace '/' separators with proper separators for the platform.
75-
var outFile = p.joinAll(filePath.split('/'));
75+
var outFile = path.joinAll(filePath.split('/'));
7676

7777
if (!allowOverwrite) {
7878
_warnAboutOverwrite(outFile, null);
@@ -91,7 +91,7 @@ class DartdocFileWriter implements FileWriter {
9191
_validateMaxWriteStats(filePath, bytes.length);
9292

9393
// Replace '/' separators with proper separators for the platform.
94-
var outFile = p.joinAll(filePath.split('/'));
94+
var outFile = path.joinAll(filePath.split('/'));
9595

9696
_warnAboutOverwrite(outFile, element);
9797
_fileElementMap[outFile] = element;

lib/src/model_utils.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:analyzer/file_system/file_system.dart';
1111
import 'package:dartdoc/src/failure.dart';
1212
import 'package:dartdoc/src/model/model.dart';
1313
import 'package:glob/glob.dart';
14-
import 'package:path/path.dart' as p;
14+
import 'package:path/path.dart' as path;
1515

1616
final _driveLetterMatcher = RegExp(r'^\w:\\');
1717

@@ -42,14 +42,14 @@ bool matchGlobs(List<String> globs, String fullName, {bool? isWindows}) {
4242
if (!driveGlob.hasMatch(glob)) continue;
4343
// `C:\` => `\` for rejoining via posix.
4444
glob = glob.replaceFirst(_driveLetterMatcher, r'/');
45-
filteredGlobs.add(p.posix.joinAll(p.windows.split(glob)));
45+
filteredGlobs.add(path.posix.joinAll(path.windows.split(glob)));
4646
}
4747
} else {
4848
filteredGlobs.addAll(globs);
4949
}
5050

51-
return filteredGlobs.any(
52-
(g) => Glob(g, context: windows ? p.windows : p.posix).matches(fullName));
51+
return filteredGlobs.any((g) =>
52+
Glob(g, context: windows ? path.windows : path.posix).matches(fullName));
5353
}
5454

5555
Iterable<T> filterHasCanonical<T extends ModelElement>(

lib/src/package_meta.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'package:analyzer/src/generated/sdk.dart' show DartSdk;
1414
import 'package:dartdoc/src/dartdoc_options.dart';
1515
import 'package:dartdoc/src/failure.dart';
1616
import 'package:meta/meta.dart';
17-
import 'package:path/path.dart' as p;
17+
import 'package:path/path.dart' as path;
1818
import 'package:yaml/yaml.dart';
1919

2020
final Map<String, PackageMeta?> _packageMetaCache = {};
@@ -121,7 +121,7 @@ abstract class PackageMeta {
121121
@override
122122
int get hashCode => pathContext.hash(pathContext.absolute(dir.path));
123123

124-
p.Context get pathContext => resourceProvider.pathContext;
124+
path.Context get pathContext => resourceProvider.pathContext;
125125

126126
/// Returns true if this represents a 'Dart' SDK.
127127
///
@@ -169,10 +169,10 @@ abstract class PubPackageMeta extends PackageMeta {
169169

170170
static final List<List<String>> _sdkDirFilePaths = Platform.isWindows
171171
? [
172-
for (var paths in _sdkDirFilePathsPosix)
172+
for (var filePaths in _sdkDirFilePathsPosix)
173173
[
174-
for (var path in paths)
175-
p.joinAll(p.Context(style: p.Style.posix).split(path)),
174+
for (var filePath in filePaths)
175+
path.joinAll(path.posix.split(filePath)),
176176
],
177177
]
178178
: _sdkDirFilePathsPosix;
@@ -375,7 +375,7 @@ File? _locate(Folder dir, List<String> fileNames) {
375375

376376
for (var name in fileNames) {
377377
for (var f in files) {
378-
var baseName = p.basename(f.path).toLowerCase();
378+
var baseName = path.basename(f.path).toLowerCase();
379379
if (baseName == name) return f;
380380
if (baseName.startsWith(name)) return f;
381381
}

lib/src/source_linker.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ library dartdoc.source_linker;
88
import 'package:analyzer/file_system/file_system.dart';
99
import 'package:dartdoc/src/dartdoc_options.dart';
1010
import 'package:dartdoc/src/model/model.dart';
11-
import 'package:path/path.dart' as p;
11+
import 'package:path/path.dart' as path;
1212

1313
final _uriTemplateRegExp = RegExp(r'(%[frl]%)');
1414

@@ -106,16 +106,16 @@ class SourceLinker {
106106
if (root == null || uriTemplate == null) {
107107
return '';
108108
}
109-
if (!p.isWithin(root, sourceFileName) ||
110-
excludes.any((String exclude) => p.isWithin(exclude, sourceFileName))) {
109+
if (!path.isWithin(root, sourceFileName) ||
110+
excludes
111+
.any((String exclude) => path.isWithin(exclude, sourceFileName))) {
111112
return '';
112113
}
113114
return uriTemplate.replaceAllMapped(_uriTemplateRegExp, (match) {
114115
switch (match[1]) {
115116
case '%f%':
116-
var urlContext = p.Context(style: p.Style.url);
117-
return urlContext
118-
.joinAll(p.split(p.relative(sourceFileName, from: root)));
117+
return path.url
118+
.joinAll(path.split(path.relative(sourceFileName, from: root)));
119119
case '%r%':
120120
return revision!;
121121
case '%l%':

lib/src/tool_runner.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:analyzer/file_system/file_system.dart';
1010
import 'package:dartdoc/src/dartdoc_options.dart';
1111
import 'package:dartdoc/src/io_utils.dart';
1212
import 'package:dartdoc/src/tool_definition.dart';
13-
import 'package:path/path.dart' as p;
13+
import 'package:path/path.dart' as path;
1414

1515
typedef ToolErrorCallback = void Function(String message);
1616
typedef FakeResultCallback = String Function(String tool,
@@ -240,5 +240,5 @@ class ToolRunner {
240240

241241
ResourceProvider get resourceProvider => toolConfiguration.resourceProvider;
242242

243-
p.Context get pathContext => resourceProvider.pathContext;
243+
path.Context get pathContext => resourceProvider.pathContext;
244244
}

lib/src/validator.dart

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'package:dartdoc/src/model/package_graph.dart';
1313
import 'package:dartdoc/src/runtime_stats.dart';
1414
import 'package:dartdoc/src/warnings.dart';
1515
import 'package:html/parser.dart' show parse;
16-
import 'package:path/path.dart' as p;
16+
import 'package:path/path.dart' as path;
1717

1818
class Validator {
1919
final PackageGraph _packageGraph;
@@ -28,7 +28,7 @@ class Validator {
2828

2929
Validator(this._packageGraph, this._config, String origin, this._writtenFiles,
3030
this._onCheckProgress)
31-
: _origin = p.normalize(origin),
31+
: _origin = path.normalize(origin),
3232
_hrefs = _packageGraph.allHrefs;
3333

3434
/// Don't call this method more than once, and only after you've
@@ -45,7 +45,7 @@ class Validator {
4545
}
4646

4747
void _collectLinks(String pathToCheck, [String? source, String? fullPath]) {
48-
fullPath ??= p.join(_origin, pathToCheck);
48+
fullPath ??= path.join(_origin, pathToCheck);
4949

5050
final pageLinks = _getLinksAndBaseHref(fullPath);
5151
if (pageLinks == null) {
@@ -67,16 +67,16 @@ class Validator {
6767
// the stack without this.
6868
final toVisit = <(String newPathToCheck, String newFullPath)>{};
6969
final pathDirectory = baseHref == null
70-
? p.dirname(pathToCheck)
71-
: '${p.dirname(pathToCheck)}/$baseHref';
70+
? path.dirname(pathToCheck)
71+
: '${path.dirname(pathToCheck)}/$baseHref';
7272

7373
for (final href in links) {
7474
final uri = Uri.tryParse(href);
7575
if (uri == null || !uri.hasAuthority && !uri.hasFragment) {
7676
var linkPath = '$pathDirectory/$href';
7777

78-
linkPath = p.normalize(linkPath);
79-
final newFullPath = p.join(_origin, linkPath);
78+
linkPath = path.normalize(linkPath);
79+
final newFullPath = path.join(_origin, linkPath);
8080
if (!_visited.contains(newFullPath)) {
8181
toVisit.add((linkPath, newFullPath));
8282
_visited.add(newFullPath);
@@ -91,13 +91,13 @@ class Validator {
9191
}
9292

9393
void _checkForOrphans() {
94-
final staticAssets = p.join(_origin, 'static-assets', '');
95-
final indexJson = p.join(_origin, 'index.json');
94+
final staticAssets = path.join(_origin, 'static-assets', '');
95+
final indexJson = path.join(_origin, 'index.json');
9696
var foundIndexJson = false;
9797

9898
void checkDirectory(Folder dir) {
9999
for (final child in dir.getChildren()) {
100-
final fullPath = p.normalize(child.path);
100+
final fullPath = path.normalize(child.path);
101101
if (_visited.contains(fullPath)) {
102102
continue;
103103
}
@@ -108,12 +108,12 @@ class Validator {
108108
if (fullPath.startsWith(staticAssets)) {
109109
continue;
110110
}
111-
if (p.equals(fullPath, indexJson)) {
111+
if (path.equals(fullPath, indexJson)) {
112112
foundIndexJson = true;
113113
_onCheckProgress.add(fullPath);
114114
continue;
115115
}
116-
final relativeFullPath = p.relative(fullPath, from: _origin);
116+
final relativeFullPath = path.relative(fullPath, from: _origin);
117117
if (!_writtenFiles.contains(relativeFullPath)) {
118118
// This isn't a file we wrote (this time); don't claim we did.
119119
_warn(PackageWarning.unknownFile, fullPath, _origin);
@@ -138,8 +138,8 @@ class Validator {
138138
}
139139

140140
void _checkSearchIndex() {
141-
final fullPath = p.join(_origin, 'index.json');
142-
final indexPath = p.join(_origin, 'index.html');
141+
final fullPath = path.join(_origin, 'index.json');
142+
final indexPath = path.join(_origin, 'index.html');
143143
final file = _config.resourceProvider.getFile(fullPath);
144144
if (!file.exists) {
145145
return;
@@ -154,8 +154,8 @@ class Validator {
154154
found.add(indexPath);
155155
for (var entry in jsonData.cast<Map<String, dynamic>>()) {
156156
if (entry.containsKey('href')) {
157-
final entryPath =
158-
p.joinAll([_origin, ...p.posix.split(entry['href'] as String)]);
157+
final entryPath = path
158+
.joinAll([_origin, ...path.posix.split(entry['href'] as String)]);
159159
if (!_visited.contains(entryPath)) {
160160
_warn(PackageWarning.brokenLink, entryPath, _origin,
161161
referredFrom: fullPath);
@@ -219,12 +219,12 @@ class Validator {
219219
Set<Warnable>? warnOnElements;
220220

221221
// Make all paths relative to origin.
222-
if (p.isWithin(origin, warnOn)) {
223-
warnOn = p.relative(warnOn, from: origin);
222+
if (path.isWithin(origin, warnOn)) {
223+
warnOn = path.relative(warnOn, from: origin);
224224
}
225225
if (referredFrom != null) {
226-
if (p.isWithin(origin, referredFrom)) {
227-
referredFrom = p.relative(referredFrom, from: origin);
226+
if (path.isWithin(origin, referredFrom)) {
227+
referredFrom = path.relative(referredFrom, from: origin);
228228
}
229229
final hrefReferredFrom = _hrefs[referredFrom];
230230
// Source paths are always relative.

test/templates/enum_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:analyzer/file_system/memory_file_system.dart';
66
import 'package:dartdoc/src/dartdoc.dart';
77
import 'package:dartdoc/src/model/model.dart';
8-
import 'package:path/path.dart' as p;
8+
import 'package:path/path.dart' as path;
99
import 'package:test/test.dart';
1010

1111
import '../src/test_descriptor_utils.dart' as d;
@@ -106,7 +106,7 @@ enum EnumWithDefaultConstructor {
106106
'--input',
107107
packagePath,
108108
'--output',
109-
p.join(packagePath, 'doc'),
109+
path.join(packagePath, 'doc'),
110110
'--sdk-dir',
111111
packageMetaProvider.defaultSdkDir.path,
112112
'--no-link-to-remote',
@@ -124,20 +124,20 @@ enum EnumWithDefaultConstructor {
124124
);
125125
await (await Dartdoc.fromContext(context, packageBuilder)).generateDocs();
126126
eLines = resourceProvider
127-
.getFile(p.join(packagePath, 'doc', 'lib', 'E.html'))
127+
.getFile(path.join(packagePath, 'doc', 'lib', 'E.html'))
128128
.readAsStringSync()
129129
.split('\n');
130130
eRightSidebarLines = resourceProvider
131-
.getFile(p.join(packagePath, 'doc', 'lib', 'E-enum-sidebar.html'))
131+
.getFile(path.join(packagePath, 'doc', 'lib', 'E-enum-sidebar.html'))
132132
.readAsStringSync()
133133
.split('\n');
134134
enumWithDefaultConstructorLines = resourceProvider
135-
.getFile(p.join(
135+
.getFile(path.join(
136136
packagePath, 'doc', 'lib', 'EnumWithDefaultConstructor.html'))
137137
.readAsStringSync()
138138
.split('\n');
139139
enumWithDefaultConstructorRightSidebarLines = resourceProvider
140-
.getFile(p.join(packagePath, 'doc', 'lib',
140+
.getFile(path.join(packagePath, 'doc', 'lib',
141141
'EnumWithDefaultConstructor-enum-sidebar.html'))
142142
.readAsStringSync()
143143
.split('\n');

test/tool_runner_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:dartdoc/src/dartdoc_options.dart';
1010
import 'package:dartdoc/src/package_meta.dart';
1111
import 'package:dartdoc/src/tool_definition.dart';
1212
import 'package:dartdoc/src/tool_runner.dart';
13-
import 'package:path/path.dart' as p;
13+
import 'package:path/path.dart' as path;
1414
import 'package:test/test.dart';
1515
import 'package:yaml/yaml.dart';
1616

@@ -19,7 +19,7 @@ final Directory _toolExecutableDir = Directory('testing/tool_executables');
1919

2020
void main() {
2121
ToolConfiguration toolMap;
22-
Directory? tempDir;
22+
late Directory tempDir;
2323
late File setupFile;
2424

2525
late ToolRunner runner;
@@ -29,7 +29,7 @@ void main() {
2929
setUpAll(() async {
3030
ProcessResult? result;
3131
tempDir = Directory.systemTemp.createTempSync('tool_runner_test_');
32-
var snapshotFile = p.join(tempDir!.path, 'drill.snapshot');
32+
var snapshotFile = path.join(tempDir.path, 'drill.snapshot');
3333
try {
3434
result = Process.runSync(
3535
Platform.resolvedExecutable,
@@ -49,10 +49,10 @@ void main() {
4949
stderr.writeln(result.stderr);
5050
}
5151
expect(result?.exitCode, equals(0));
52-
setupFile = File(p.join(tempDir!.path, 'setup.stamp'));
52+
setupFile = File(path.join(tempDir.path, 'setup.stamp'));
5353
var nonDartName = Platform.isWindows ? 'non_dart.bat' : 'non_dart.sh';
5454
var nonDartExecutable =
55-
p.join(_toolExecutableDir.absolute.path, nonDartName);
55+
path.join(_toolExecutableDir.absolute.path, nonDartName);
5656
// Have to replace backslashes on Windows with double-backslashes, to
5757
// escape them for YAML parser.
5858
var yamlMap = '''
@@ -93,7 +93,7 @@ echo:
9393
});
9494

9595
tearDownAll(() {
96-
tempDir?.deleteSync(recursive: true);
96+
tempDir.deleteSync(recursive: true);
9797
SnapshotCache.instanceFor(pubPackageMetaProvider.resourceProvider)
9898
.dispose();
9999
});

0 commit comments

Comments
 (0)