Skip to content

Commit 9ab106d

Browse files
authored
file: enable and fix latest team lints (#1669)
1 parent 42effa6 commit 9ab106d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+534
-531
lines changed

pkgs/file/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## 7.0.2-wip
2+
13
## 7.0.1
24

35
* Update the pubspec repository field to reflect the new package repository.

pkgs/file/analysis_options.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
include: package:lints/recommended.yaml
2-
3-
analyzer:
4-
errors:
5-
# Allow having TODOs in the code
6-
todo: ignore
1+
include: package:dart_flutter_team_lints/analysis_options.yaml

pkgs/file/example/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import 'package:file/memory.dart';
77

88
Future<void> main() async {
99
final FileSystem fs = MemoryFileSystem();
10-
final Directory tmp = await fs.systemTempDirectory.createTemp('example_');
11-
final File outputFile = tmp.childFile('output');
10+
final tmp = await fs.systemTempDirectory.createTemp('example_');
11+
final outputFile = tmp.childFile('output');
1212
await outputFile.writeAsString('Hello world!');
1313
print(outputFile.readAsStringSync());
1414
}

pkgs/file/lib/chroot.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
/// A file system that provides a view into _another_ `FileSystem` via a path.
6+
library;
7+
68
export 'src/backends/chroot.dart';

pkgs/file/lib/file.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44

55
/// Core interfaces containing the abstract `FileSystem` interface definition
66
/// and all associated types used by `FileSystem`.
7+
library;
8+
79
export 'src/forwarding.dart';
810
export 'src/interface.dart';

pkgs/file/lib/local.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
/// A local file system implementation. This relies on the use of `dart:io`
66
/// and is thus not suitable for use in the browser.
7+
library;
8+
79
export 'src/backends/local.dart';

pkgs/file/lib/memory.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44

55
/// An implementation of `FileSystem` that exists entirely in memory with an
66
/// internal representation loosely based on the Filesystem Hierarchy Standard.
7+
library;
8+
79
export 'src/backends/memory.dart';
810
export 'src/backends/memory/operations.dart';

pkgs/file/lib/src/backends/chroot.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
library file.src.backends.chroot;
6-
75
import 'dart:convert';
86
import 'dart:typed_data';
97

10-
import 'package:file/file.dart';
11-
import 'package:file/src/common.dart' as common;
12-
import 'package:file/src/io.dart' as io;
138
import 'package:path/path.dart' as p;
149

10+
import '../common.dart' as common;
11+
import '../forwarding.dart';
12+
import '../interface.dart';
13+
import '../io.dart' as io;
14+
1515
part 'chroot/chroot_directory.dart';
1616
part 'chroot/chroot_file.dart';
1717
part 'chroot/chroot_file_system.dart';

pkgs/file/lib/src/backends/chroot/chroot_directory.dart

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of file.src.backends.chroot;
5+
part of '../chroot.dart';
66

77
class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
88
with ForwardingDirectory<Directory>, common.DirectoryAddOnsMixin {
9-
_ChrootDirectory(ChrootFileSystem fs, String path) : super(fs, path);
9+
_ChrootDirectory(super.fs, super.path);
1010

1111
factory _ChrootDirectory.wrapped(
1212
ChrootFileSystem fs,
1313
Directory delegate, {
1414
bool relative = false,
1515
}) {
16-
String localPath = fs._local(delegate.path, relative: relative);
16+
var localPath = fs._local(delegate.path, relative: relative);
1717
return _ChrootDirectory(fs, localPath);
1818
}
1919

@@ -32,7 +32,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
3232
if (await fileSystem.type(path) != expectedType) {
3333
throw common.notADirectory(path);
3434
}
35-
FileSystemEntityType type = await fileSystem.type(newPath);
35+
var type = await fileSystem.type(newPath);
3636
if (type != FileSystemEntityType.notFound) {
3737
if (type != expectedType) {
3838
throw common.notADirectory(newPath);
@@ -44,7 +44,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
4444
throw common.directoryNotEmpty(newPath);
4545
}
4646
}
47-
String target = await fileSystem.link(path).target();
47+
var target = await fileSystem.link(path).target();
4848
await fileSystem.link(path).delete();
4949
await fileSystem.link(newPath).create(target);
5050
return fileSystem.directory(newPath);
@@ -60,7 +60,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
6060
if (fileSystem.typeSync(path) != expectedType) {
6161
throw common.notADirectory(path);
6262
}
63-
FileSystemEntityType type = fileSystem.typeSync(newPath);
63+
var type = fileSystem.typeSync(newPath);
6464
if (type != FileSystemEntityType.notFound) {
6565
if (type != expectedType) {
6666
throw common.notADirectory(newPath);
@@ -72,7 +72,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
7272
throw common.directoryNotEmpty(newPath);
7373
}
7474
}
75-
String target = fileSystem.link(path).targetSync();
75+
var target = fileSystem.link(path).targetSync();
7676
fileSystem.link(path).deleteSync();
7777
fileSystem.link(newPath).createSync(target);
7878
return fileSystem.directory(newPath);
@@ -97,17 +97,15 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
9797
@override
9898
Future<Directory> create({bool recursive = false}) async {
9999
if (_isLink) {
100-
switch (await fileSystem.type(path)) {
101-
case FileSystemEntityType.notFound:
102-
throw common.noSuchFileOrDirectory(path);
103-
case FileSystemEntityType.file:
104-
throw common.fileExists(path);
105-
case FileSystemEntityType.directory:
100+
return switch (await fileSystem.type(path)) {
101+
FileSystemEntityType.notFound =>
102+
throw common.noSuchFileOrDirectory(path),
103+
FileSystemEntityType.file => throw common.fileExists(path),
104+
FileSystemEntityType.directory =>
106105
// Nothing to do.
107-
return this;
108-
default:
109-
throw AssertionError();
110-
}
106+
this,
107+
_ => throw AssertionError()
108+
};
111109
} else {
112110
return wrap(await delegate.create(recursive: recursive));
113111
}
@@ -137,8 +135,8 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
137135
bool recursive = false,
138136
bool followLinks = true,
139137
}) {
140-
Directory delegate = this.delegate as Directory;
141-
String dirname = delegate.path;
138+
var delegate = this.delegate as Directory;
139+
var dirname = delegate.path;
142140
return delegate
143141
.list(recursive: recursive, followLinks: followLinks)
144142
.map((io.FileSystemEntity entity) => _denormalize(entity, dirname));
@@ -149,18 +147,18 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
149147
bool recursive = false,
150148
bool followLinks = true,
151149
}) {
152-
Directory delegate = this.delegate as Directory;
153-
String dirname = delegate.path;
150+
var delegate = this.delegate as Directory;
151+
var dirname = delegate.path;
154152
return delegate
155153
.listSync(recursive: recursive, followLinks: followLinks)
156154
.map((io.FileSystemEntity entity) => _denormalize(entity, dirname))
157155
.toList();
158156
}
159157

160158
FileSystemEntity _denormalize(io.FileSystemEntity entity, String dirname) {
161-
p.Context ctx = fileSystem.path;
162-
String relativePart = ctx.relative(entity.path, from: dirname);
163-
String entityPath = ctx.join(path, relativePart);
159+
var ctx = fileSystem.path;
160+
var relativePart = ctx.relative(entity.path, from: dirname);
161+
var entityPath = ctx.join(path, relativePart);
164162
if (entity is io.File) {
165163
return _ChrootFile(fileSystem, entityPath);
166164
} else if (entity is io.Directory) {

pkgs/file/lib/src/backends/chroot/chroot_file.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
part of file.src.backends.chroot;
5+
part of '../chroot.dart';
66

77
typedef _SetupCallback = dynamic Function();
88

99
class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
1010
with ForwardingFile {
11-
_ChrootFile(ChrootFileSystem fs, String path) : super(fs, path);
11+
_ChrootFile(super.fs, super.path);
1212

1313
factory _ChrootFile.wrapped(
1414
ChrootFileSystem fs,
1515
io.File delegate, {
1616
bool relative = false,
1717
}) {
18-
String localPath = fs._local(delegate.path, relative: relative);
18+
var localPath = fs._local(delegate.path, relative: relative);
1919
return _ChrootFile(fs, localPath);
2020
}
2121

@@ -126,7 +126,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
126126

127127
@override
128128
Future<File> create({bool recursive = false, bool exclusive = false}) async {
129-
String path = fileSystem._resolve(
129+
var path = fileSystem._resolve(
130130
this.path,
131131
followLinks: false,
132132
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,
@@ -158,7 +158,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>
158158

159159
@override
160160
void createSync({bool recursive = false, bool exclusive = false}) {
161-
String path = fileSystem._resolve(
161+
var path = fileSystem._resolve(
162162
this.path,
163163
followLinks: false,
164164
notFound: recursive ? _NotFoundBehavior.mkdir : _NotFoundBehavior.allow,

0 commit comments

Comments
 (0)