Skip to content

Commit

Permalink
Remove dartdoc section generation + joining from public API. (#1318)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Jan 17, 2024
1 parent 6670b00 commit 5a7f35a
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 218 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- deprecated APIs
- `InspectOptions.checkRemoteRepository` - repositories are verified by default
- `ProcessOutput.asBytes`
- `Report.joinSection()`
- `ToolEnvironment`:
- removed parameters from `dartdoc()`
- `detectFlutterUse()`
Expand All @@ -16,6 +17,8 @@
- `changelogFileNames`
- `currentAnalysisOptionsFileName`
- `dartdocFailedSection`
- `documentationCoverageSection()`
- `documentationSectionTitle`
- `firstFileFromNames`
- `licenseFileNames`
- `pubspecParseError`
Expand Down
1 change: 0 additions & 1 deletion lib/pana.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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.

export 'src/dartdoc_analyzer.dart';
export 'src/download_utils.dart';
export 'src/maintenance.dart' show exampleFileCandidates;
export 'src/model.dart';
Expand Down
6 changes: 3 additions & 3 deletions lib/src/dartdoc/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'dartdoc_index.dart';
import 'index_to_pubdata.dart';
import 'pub_dartdoc_data.dart';

final dartdocSubsectionHeadline =
final _dartdocSubsectionHeadline =
'20% or more of the public API has dartdoc comments';

Future<PubDartdocData> generateAndSavePubDataJson(
Expand All @@ -29,7 +29,7 @@ Future<PubDartdocData> generateAndSavePubDataJson(

Subsection dartdocFailedSubsection(String reason) {
return Subsection(
dartdocSubsectionHeadline,
_dartdocSubsectionHeadline,
[RawParagraph(reason)],
0,
10,
Expand Down Expand Up @@ -68,7 +68,7 @@ Future<Subsection> createDocumentationCoverageSection(
}

return Subsection(
dartdocSubsectionHeadline,
_dartdocSubsectionHeadline,
[RawParagraph(summary.toString())],
grantedPoints,
maxPoints,
Expand Down
55 changes: 0 additions & 55 deletions lib/src/dartdoc_analyzer.dart

This file was deleted.

36 changes: 0 additions & 36 deletions lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:math';

import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:pub_semver/pub_semver.dart';

Expand Down Expand Up @@ -237,41 +236,6 @@ class Report {

int get maxPoints =>
sections.fold<int>(0, (sum, section) => sum + section.maxPoints);

/// Creates a new [Report] instance with [section] extending and already
/// existing [ReportSection]. The sections are matched via the `title`.
///
/// The granted and max points will be added to the existing section.
/// The status will be min of the two statuses.
///
/// The summary will be appended to the end of the existing summary.
///
///
/// If there is no section matched, the section will be added to the end of
/// the sections list.
Report joinSection(ReportSection section) {
final matched = sections.firstWhereOrNull(
(s) => (s.id == section.id) || s.title == section.title);
if (matched == null) {
return Report(sections: [...sections, section]);
} else {
return Report(
sections: sections.map(
(s) {
if (s != matched) {
return s;
}
return ReportSection(
id: s.id,
title: s.title,
maxPoints: s.maxPoints + section.maxPoints,
grantedPoints: s.grantedPoints + section.grantedPoints,
summary: [s.summary.trim(), section.summary.trim()].join('\n\n'),
status: minStatus(s.status, section.status)!);
},
).toList());
}
}
}

abstract class ReportSectionId {
Expand Down
3 changes: 1 addition & 2 deletions lib/src/report/documentation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:collection/collection.dart';
import 'package:path/path.dart' as p;

import '../dartdoc/dartdoc.dart';
import '../dartdoc_analyzer.dart';
import '../maintenance.dart';
import '../model.dart';
import '../package_context.dart';
Expand Down Expand Up @@ -70,7 +69,7 @@ Future<ReportSection> hasDocumentation(PackageContext context) async {
final example = await _exampleSubsection(context);
return makeSection(
id: ReportSectionId.documentation,
title: documentationSectionTitle,
title: 'Provide documentation',
maxPoints: (documentation?.maxPoints ?? 0) + example.maxPoints,
subsections: [
if (documentation != null) documentation,
Expand Down
99 changes: 0 additions & 99 deletions test/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,105 +6,6 @@ import 'package:pana/src/model.dart';
import 'package:test/test.dart';

void main() {
group('Report', () {
test('join section with no match', () {
final report = Report(sections: [
ReportSection(
id: 'a',
title: 'a',
grantedPoints: 5,
maxPoints: 5,
summary: 'something',
status: ReportStatus.partial,
),
]);

final nr = report.joinSection(ReportSection(
id: 'b',
title: 'b',
grantedPoints: 10,
maxPoints: 10,
summary: 'other',
status: ReportStatus.passed,
));

expect(nr.toJson(), {
'sections': [
{
'id': 'a',
'title': 'a',
'grantedPoints': 5,
'maxPoints': 5,
'summary': 'something',
'status': 'partial'
},
{
'id': 'b',
'title': 'b',
'grantedPoints': 10,
'maxPoints': 10,
'summary': 'other',
'status': 'passed',
},
]
});
});

test('join with match', () {
final report = Report(sections: [
ReportSection(
id: 'a',
title: 'a',
grantedPoints: 5,
maxPoints: 5,
summary: 'something\n',
status: ReportStatus.partial,
),
ReportSection(
id: 'b',
title: 'b',
grantedPoints: 6,
maxPoints: 10,
summary: 'other',
status: ReportStatus.passed,
),
]);

final nr = report.joinSection(ReportSection(
id: 'a',
title: 'a',
grantedPoints: 3,
maxPoints: 7,
summary: '\nanother thing\n',
status: ReportStatus.failed,
));

expect(
nr.toJson(),
{
'sections': [
{
'id': 'a',
'title': 'a',
'grantedPoints': 8,
'maxPoints': 12,
'summary': 'something\n\nanother thing',
'status': 'failed'
},
{
'id': 'b',
'title': 'b',
'grantedPoints': 6,
'maxPoints': 10,
'summary': 'other',
'status': 'passed',
},
]
},
);
});
});

group('PanaRuntimeInfo', () {
test('no Flutter SDK', () {
final info = PanaRuntimeInfo(panaVersion: '1.0.0', sdkVersion: '2.0.0');
Expand Down
22 changes: 0 additions & 22 deletions test/report/documentation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,6 @@ import '../package_descriptor.dart';

void main() {
group('Provide documentation', () {
test('documentation percent', () {
expect(documentationCoverageSection(documented: 1, total: 21).summary,
contains('(4.8 %)'));
expect(documentationCoverageSection(documented: 0, total: 0).summary,
contains('(100.0 %)'));
expect(documentationCoverageSection(documented: 5, total: 7).summary,
contains('(71.4 %)'));
expect(documentationCoverageSection(documented: 7, total: 7).summary,
contains('(100.0 %)'));
});

test('documentation title', () {
expect(documentationCoverageSection(documented: 1, total: 21).summary,
contains('### [x] 0/10 points'));
expect(documentationCoverageSection(documented: 0, total: 0).summary,
contains('### [*] 10/10 points'));
expect(documentationCoverageSection(documented: 5, total: 7).summary,
contains('### [*] 10/10 points'));
expect(documentationCoverageSection(documented: 7, total: 7).summary,
contains('### [*] 10/10 points'));
});

test('finds example', () async {
final descriptor = package('my_package', extraFiles: [
d.dir('example', [
Expand Down

0 comments on commit 5a7f35a

Please sign in to comment.