Skip to content

Fix duplicate entries of elements in a category when re-exported. #4043

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

Merged
merged 2 commits into from
May 5, 2025
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
16 changes: 8 additions & 8 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<TopLevelVariable>',
'Set<TopLevelVariable>',
),

renderIterable: (
Expand Down Expand Up @@ -1735,7 +1735,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<Enum>',
'Set<Enum>',
),

renderIterable: (
Expand Down Expand Up @@ -1777,7 +1777,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<ExtensionType>',
'Set<ExtensionType>',
),

renderIterable: (
Expand All @@ -1804,7 +1804,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<Extension>',
'Set<Extension>',
),

renderIterable: (
Expand Down Expand Up @@ -1917,7 +1917,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<ModelFunction>',
'Set<ModelFunction>',
),

renderIterable: (
Expand Down Expand Up @@ -2054,7 +2054,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<Mixin>',
'Set<Mixin>',
),

renderIterable: (
Expand Down Expand Up @@ -2167,7 +2167,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<TopLevelVariable>',
'Set<TopLevelVariable>',
),

renderIterable: (
Expand Down Expand Up @@ -2320,7 +2320,7 @@ class _Renderer_Category extends RendererBase<Category> {
self.renderSimpleVariable(
c,
remainingNames,
'List<Typedef>',
'Set<Typedef>',
),

renderIterable: (
Expand Down
20 changes: 10 additions & 10 deletions lib/src/model/category.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,33 @@ class Category
@override
final DartdocOptionContext config;

final List<Class> _classes = [];
final Set<Class> _classes = {};

final List<Class> _exceptions = [];
final Set<Class> _exceptions = {};

@override
final List<TopLevelVariable> constants = [];
final Set<TopLevelVariable> constants = {};

@override
final List<Extension> extensions = [];
final Set<Extension> extensions = {};

@override
final List<ExtensionType> extensionTypes = [];
final Set<ExtensionType> extensionTypes = {};

@override
final List<Enum> enums = [];
final Set<Enum> enums = {};

@override
final List<ModelFunction> functions = [];
final Set<ModelFunction> functions = {};

@override
final List<Mixin> mixins = [];
final Set<Mixin> mixins = {};

@override
final List<TopLevelVariable> properties = [];
final Set<TopLevelVariable> properties = {};

@override
final List<Typedef> typedefs = [];
final Set<Typedef> typedefs = {};

final CategoryDefinition _categoryDefinition;

Expand Down
19 changes: 19 additions & 0 deletions test/end2end/model_special_cases_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,25 @@ void main() {
expect(SubForDocComments.categories.first.isDocumented, isFalse);
expect(SubForDocComments.displayedCategories, isEmpty);
});

test('No duplicate entries', () {
final categories = ginormousPackageGraph.localPackages
.firstWhere((p) => p.name == 'test_package')
.categories;
for (final c in categories) {
expect(c.classes.length, equals(c.classes.toSet().length));
expect(c.exceptions.length, equals(c.exceptions.toSet().length));
expect(c.extensions.length, equals(c.extensions.toSet().length));
expect(
c.extensionTypes.length, equals(c.extensionTypes.toSet().length));
expect(c.enums.length, equals(c.enums.toSet().length));
expect(c.mixins.length, equals(c.mixins.toSet().length));
expect(c.constants.length, equals(c.constants.toSet().length));
expect(c.properties.length, equals(c.properties.toSet().length));
expect(c.functions.length, equals(c.functions.toSet().length));
expect(c.typedefs.length, equals(c.typedefs.toSet().length));
}
});
});

group('Package', () {
Expand Down
21 changes: 20 additions & 1 deletion test/templates/category_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ extension type ExType(int it) {}
'''),
d.file('other.dart', '''
/// {@category Documented}
library;
library;

export 'lib.dart' show C1, E1;
'''),
],
files: [
Expand Down Expand Up @@ -229,6 +231,15 @@ library;
);
});

test('classes are not duplicated', () async {
expect(
topicOneLines
.where((l) => l.contains('<a href="../lib/C1-class.html">C1</a>')),
// Once in the sidebar and once in the main body
hasLength(2),
);
});

test('sidebar contains enums', () async {
expect(
topicOneLines,
Expand All @@ -240,6 +251,14 @@ library;
);
});

test('enums are not duplicated', () async {
expect(
topicOneLines.where((l) => l.contains('<a href="../lib/E1.html">E1</a>')),
// Once in the sidebar and once in the main body
hasLength(2),
);
});

test('sidebar contains mixins', () async {
expect(
topicOneLines,
Expand Down
1 change: 1 addition & 0 deletions testing/test_package/lib/src/somelib.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
library reexport.somelib;

/// {@category Unreal}
class SomeClass {}

class SomeOtherClass {}
Expand Down