Files
sdk/pkg/linter/tool/util/path_utils.dart
T
Sam Rawlins 7320da0d19 linter: Add a PRESUBMIT check for example/all.yaml
Work towards https://github.com/dart-lang/sdk/issues/53578

Change-Id: Ia07d999abc2fcf4b8195c9f7688799bc099a1d88
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341385
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Jonas Termansen <sortie@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
2023-12-15 04:04:28 +00:00

29 lines
918 B
Dart

// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:io';
import 'package:path/path.dart' as path;
List<String> get _packageRoot {
var parts = path.split(path.dirname(path.fromUri(Platform.script.path)));
while (parts.last != 'linter') {
parts.removeLast();
if (parts.isEmpty) {
throw StateError("Script is not located inside a 'linter' directory? "
"'${Platform.script.path}'");
}
}
return parts;
}
String pathRelativeToPackageRoot(Iterable<String> parts) =>
path.joinAll([..._packageRoot, ...parts]);
String pathRelativeToPkgDir(Iterable<String> parts) {
var pathParts = _packageRoot;
pathParts.replaceRange(pathParts.length - 1, pathParts.length, parts);
return path.joinAll(pathParts);
}