Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid duplicates on parts #51

Merged
merged 3 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/src/find_class_elements.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ Future<Iterable<ClassElement>> findClassElements({

final unitResult = await context.currentSession.getResolvedUnit(filePath);
if (unitResult is ResolvedUnitResult) {
unitResult.libraryElement.accept(collector);
// Skip parts files to avoid duplication.
if (!unitResult.isPart) {
unitResult.libraryElement.accept(collector);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/bindir/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ packages:
path: "../../.."
relative: true
source: path
version: "3.1.1"
version: "4.0.0"
file:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/inheritance/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ packages:
path: "../../.."
relative: true
source: path
version: "3.1.1"
version: "4.0.0"
file:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/simple/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ packages:
path: "../../.."
relative: true
source: path
version: "3.1.1"
version: "4.0.0"
file:
dependency: transitive
description:
Expand Down
33 changes: 33 additions & 0 deletions test/functional/parts_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:test/test.dart';

import 'utils.dart';

void main() {
setUpAll(() {
pubGetFixtures();
});

group('dcdg tool (parts cases)', () {
test('should not duplicate classes in files with parts', () {
final result = runWith(
[],
'test/fixtures/simple/',
);
expect(result.stderr, '');
expect(result.exitCode, 0);

final out = result.stdout as String;
for (final className in const [
'PublicInternalPublic',
'PublicPartInternalPartPublic',
'_PrivatePartInternalPartPrivate',
'_PrivateInternalPrivate',
]) {
final first = out.indexOf(className);
final last = out.lastIndexOf(className);
expect(first, isNot(-1));
expect(first, equals(last), reason: '$className is duplicated');
}
});
});
}
2 changes: 1 addition & 1 deletion tool/check.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh

dart pub get
dart run test -j 1 $@
dart run test -j 1 "$@"

2 changes: 1 addition & 1 deletion tool/format.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh

dartfmt -w --fix --set-exit-if-changed .
dart format --fix --set-exit-if-changed .