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

[dartdoc_test] add documentation samples analyzer #242

Merged
merged 23 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions dartdoc_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.dartdoc_test
31 changes: 29 additions & 2 deletions dartdoc_test/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
dartdoc_test
============
# dartdoc_test

This package provides an easy way to test code samples embedded in dartdoc
documentation comments.

**Disclaimer:** This is not an officially supported Google product.

# Using in cli

```bash
# Add dartdoc_test as dev dependency
dart pub add dev:dartdoc_test

# Run dartdoc_test directly
dart run dartdoc_test analyze
```

# Using in test

You can test documentation code samples by creating `test/dartdoc_test.dart`.

```dart
import 'package:dartdoc_test/dartdoc_test.dart';

void main() {
runDartdocTest();
}

```

and then

```bash
dart test
```
6 changes: 0 additions & 6 deletions dartdoc_test/bin/analyze.dart

This file was deleted.

17 changes: 1 addition & 16 deletions dartdoc_test/bin/dartdoc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:args/args.dart';
import 'package:dartdoc_test/dartdoc_test.dart';

final _parser = ArgParser()
..addFlag(
'help',
abbr: 'h',
help: 'Show help',
negatable: false,
)
..addMultiOption(
'directory',
abbr: 'd',
help: 'Directories to analyze',
);

Future<void> main(List<String> args) async {
final dartdocTest = DartDocTest();
await dartdocTest.run();
await DartdocTestCommandRunner().run(args);
}
3 changes: 3 additions & 0 deletions dartdoc_test/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
3 changes: 3 additions & 0 deletions dartdoc_test/example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
3 changes: 3 additions & 0 deletions dartdoc_test/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# dartdoc_test example

This application shows how to use `package:dartdoc_test` in a dart project and how it works.
30 changes: 30 additions & 0 deletions dartdoc_test/example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
/// Example of documentation comments and code samples in Dart.
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'dart:convert';

/// Example of documentation comments and code samples in Dart.

/// This is a simple class example.
///
/// This class demonstrates a simple Dart class with a single method.
Expand Down
35 changes: 35 additions & 0 deletions dartdoc_test/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/// Simple function that prints `"Hello world!"`.
///
/// **Example**
/// ```dart
/// sayHello(); // prints: Hello world!
/// ```
void sayHello() {
// My comment
print('Hello world!');
}

/// Simple function that prints `"Hello world!"`.
///
/// **Example**
/// ```dart
/// foo(); // prints: Hello world!
/// ```
void foo() {
// My comment
print('foo!');
}
21 changes: 0 additions & 21 deletions dartdoc_test/example/main.dart

This file was deleted.

18 changes: 18 additions & 0 deletions dartdoc_test/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: example
description: A sample command-line application.
version: 1.0.0
# repository: https://github.com/my_org/my_repo

environment:
sdk: ^3.3.0

# Add regular dependencies here.
dependencies:
# path: ^1.8.0

dev_dependencies:
lints: ^3.0.0
test: ^1.24.0

dartdoc_test:
path: ../
18 changes: 18 additions & 0 deletions dartdoc_test/example/test/dartdoc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:dartdoc_test/dartdoc_test.dart';

/// [runDartdocTest] is a test function that tests code samples.
void main() => runDartdocTest();
Loading
Loading