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

@hideConstantImplementations by default. #3576

Merged
merged 5 commits into from
Nov 16, 2023
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
35 changes: 0 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,41 +408,6 @@ markdown link isn't linked).
It's best to only inject HTML that is self-contained and doesn't depend upon
other elements on the page, since those may change in future versions of Dartdoc.

### Skipping constant rendering with one-line docs

For some classes or libraries full of well-documented constants, showing the
implementation on the enclosing `class` or `library` page can be distracting
or even misleading. To prevent the rendering of constant implementations,
place the `{@hideConstantImplementations}` in the documentation comment for
the enclosing context where the constant is defined. For members of a class,
place the directive in the class documentation where the constants are defined.
For top level constants, place the directive in the library where the constants
are defined.

For example:

```dart
/// This is truly an amazing library.
/// {@hideConstantImplementations}
library my_library;

/// This top level constant will not show its implementation.
const a = 7;

/// {@hideConstantImplementations}
class A {
/// This constant will not show its implementation.
static const aConst = 12;
}

class B {
/// Despite the library directive, because this is a class
/// member and there is no hideConstantImplementations
/// directive on the class, we will show this implementation.
static const bConst = 27;
}
```

### Auto including dependencies

If `--auto-include-dependencies` flag is provided, dartdoc tries to automatically add
Expand Down
22 changes: 0 additions & 22 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6121,13 +6121,6 @@ class _Renderer_Field extends RendererBase<Field> {
parent: r);
},
),
'hasHideConstantImplementation': Property(
getValue: (CT_ c) => c.hasHideConstantImplementation,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasHideConstantImplementation == true,
),
'href': Property(
getValue: (CT_ c) => c.href,
renderVariable:
Expand Down Expand Up @@ -6820,13 +6813,6 @@ class _Renderer_GetterSetterCombo extends RendererBase<GetterSetterCombo> {
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasGetterOrSetter == true,
),
'hasHideConstantImplementation': Property(
getValue: (CT_ c) => c.hasHideConstantImplementation,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasHideConstantImplementation == true,
),
'hasNoGetterSetter': Property(
getValue: (CT_ c) => c.hasNoGetterSetter,
renderVariable: (CT_ c, Property<CT_> self,
Expand Down Expand Up @@ -15135,13 +15121,6 @@ class _Renderer_TopLevelVariable extends RendererBase<TopLevelVariable> {
parent: r);
},
),
'hasHideConstantImplementation': Property(
getValue: (CT_ c) => c.hasHideConstantImplementation,
renderVariable: (CT_ c, Property<CT_> self,
List<String> remainingNames) =>
self.renderSimpleVariable(c, remainingNames, 'bool'),
getBool: (CT_ c) => c.hasHideConstantImplementation == true,
),
'href': Property(
getValue: (CT_ c) => c.href,
renderVariable:
Expand Down Expand Up @@ -16751,7 +16730,6 @@ const _invisibleGetters = {
'hasExplicitSetter',
'hasGetter',
'hasGetterOrSetter',
'hasHideConstantImplementation',
'hasNoGetterSetter',
'hasParameters',
'hasPublicGetter',
Expand Down
12 changes: 6 additions & 6 deletions lib/src/model/documentation_comment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import 'package:dartdoc/src/warnings.dart';
import 'package:meta/meta.dart';
import 'package:path/path.dart' as p show Context;

final _templatePattern = RegExp(
r'[ ]*\{@template\s+([^\s}].*?)\}([^]+?)\{@endtemplate\}[ ]*(\n?)');
final _htmlPattern = RegExp(
r'[ ]*\{@inject-html\s*\}([^]+?)\{@end-inject-html\}[ ]*\n?');
final _templatePattern =
RegExp(r'[ ]*\{@template\s+([^\s}].*?)\}([^]+?)\{@endtemplate\}[ ]*(\n?)');
final _htmlPattern =
RegExp(r'[ ]*\{@inject-html\s*\}([^]+?)\{@end-inject-html\}[ ]*\n?');

/// Matches all tool directives (even some invalid ones). This is so
/// we can give good error messages if the directive is malformed, instead of
/// just silently emitting it as-is.
final _basicToolPattern = RegExp(
r'[ ]*{@tool\s+([^\s}][^}]*)}\n?([^]+?)\n?{@end-tool}[ ]*\n?');
final _basicToolPattern =
RegExp(r'[ ]*{@tool\s+([^\s}][^}]*)}\n?([^]+?)\n?{@end-tool}[ ]*\n?');

final _examplePattern = RegExp(r'{@example\s+([^\s}][^}]*)}');

Expand Down
4 changes: 0 additions & 4 deletions lib/src/model/field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,4 @@ class Field extends ModelElement

@override
Inheritable? get overriddenElement => null;

@override
bool get hasHideConstantImplementation =>
definingEnclosingContainer.hasHideConstantImplementations;
}
11 changes: 1 addition & 10 deletions lib/src/model/getter_setter_combo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ mixin GetterSetterCombo on ModelElement {
bool get isInherited;

/// Whether this has a constant value which should be displayed.
bool get hasConstantValueForDisplay {
final element = this.element;
if (element is! ConstVariableElement) return false;
if (hasHideConstantImplementation) return false;
return element.constantInitializer != null;
}
bool get hasConstantValueForDisplay => false;

Expression? get constantInitializer =>
(element as ConstVariableElement).constantInitializer;
Expand Down Expand Up @@ -263,10 +258,6 @@ mixin GetterSetterCombo on ModelElement {
// TODO(srawlins): This should be private.
bool get writeOnly => hasPublicSetter && !hasPublicGetter;

/// True if the @hideConstantImplementations directive is present
/// in the defining enclosing element.
bool get hasHideConstantImplementation;

@override
late final Map<String, CommentReferable> referenceChildren = {
if (hasParameters) ...parameters.explicitOnCollisionWith(this),
Expand Down
4 changes: 0 additions & 4 deletions lib/src/model/top_level_variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,4 @@ class TopLevelVariable extends ModelElement

@override
Iterable<CommentReferable> get referenceParents => [definingLibrary];

@override
bool get hasHideConstantImplementation =>
definingLibrary.hasHideConstantImplementations;
}
37 changes: 37 additions & 0 deletions test/constant_values_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ void main() {
if (namedArgumentsAnywhereAllowed) {
defineReflectiveTests(ConstantValuesWithNamedArgumentsAnywhereTest);
}
defineReflectiveTests(HiddenConstantsTest);
});
}

Expand Down Expand Up @@ -179,3 +180,39 @@ const r = C(c: 1, d: 2, 3, 4);
equals('<a href="$linkPrefix/C/C.html">C</a>(c: 1, d: 2, 3, 4)'));
}
}

@reflectiveTest
class HiddenConstantsTest extends DartdocTestBase {
@override
String get libraryName => 'hidden_constants';

void test_field() async {
var library = await bootPackageWithLibrary('''
/// Some documentation.
class A {
static const int aConst = 12;
}
''');
var aClass = library.classes.named('A');
var aConst = aClass.constantFields.named('aConst');
expect(aConst.hasConstantValueForDisplay, isFalse);
expect(aClass.documentation, equals('Some documentation.'));
}

void test_topLevel() async {
var library = await bootPackageWithLibrary('''
class A {
static const int aConst = 12;
}

static const aTopLevelConst = 37;
''', libraryPreamble: '''
/// Some documentation.
''');
var aConst = library.classes.named('A').constantFields.named('aConst');
expect(aConst.hasConstantValueForDisplay, isFalse);
var aTopLevelConst = library.constants.named('aTopLevelConst');
expect(aTopLevelConst.hasConstantValueForDisplay, isFalse);
expect(library.documentation, equals('Some documentation.'));
}
}
65 changes: 0 additions & 65 deletions test/directives/hide_constant_implementations_test.dart

This file was deleted.

Loading