summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/integration/doc_tests.rs17
-rw-r--r--cli/tests/testdata/doc/lint_success.out1
-rw-r--r--cli/tests/testdata/doc/lint_success.ts5
-rw-r--r--cli/tests/testdata/doc/lint_success_html.out1
-rw-r--r--cli/tests/testdata/doc/lint_success_json.out48
-rw-r--r--cli/tests/testdata/doc/referenced_private_types_fixed.out17
-rw-r--r--cli/tools/doc.rs32
7 files changed, 94 insertions, 27 deletions
diff --git a/cli/tests/integration/doc_tests.rs b/cli/tests/integration/doc_tests.rs
index f5ac44a02..7a3f08f48 100644
--- a/cli/tests/integration/doc_tests.rs
+++ b/cli/tests/integration/doc_tests.rs
@@ -70,6 +70,23 @@ itest!(deno_doc_html_lint_referenced_private_types_fixed {
output: "doc/referenced_private_types_lint.out",
});
+itest!(deno_doc_lint_success {
+ args: "doc --lint doc/lint_success.ts",
+ output: "doc/lint_success.out",
+});
+
+itest!(deno_doc_lint_json_success {
+ args: "doc --lint --json doc/lint_success.ts",
+ output: "doc/lint_success_json.out",
+});
+
+itest!(deno_doc_lint_html_success {
+ args: "doc --lint --html --name=Library lint_success.ts",
+ copy_temp_dir: Some("doc"),
+ cwd: Some("doc"),
+ output: "doc/lint_success_html.out",
+});
+
itest!(_060_deno_doc_displays_all_overloads_in_details_view {
args:
"doc --filter NS.test doc/060_deno_doc_displays_all_overloads_in_details_view.ts",
diff --git a/cli/tests/testdata/doc/lint_success.out b/cli/tests/testdata/doc/lint_success.out
new file mode 100644
index 000000000..c05ac45a1
--- /dev/null
+++ b/cli/tests/testdata/doc/lint_success.out
@@ -0,0 +1 @@
+Checked 1 file
diff --git a/cli/tests/testdata/doc/lint_success.ts b/cli/tests/testdata/doc/lint_success.ts
new file mode 100644
index 000000000..42c44b2d7
--- /dev/null
+++ b/cli/tests/testdata/doc/lint_success.ts
@@ -0,0 +1,5 @@
+/** My test class. */
+export class Test {
+ /** My property. */
+ prop: string;
+}
diff --git a/cli/tests/testdata/doc/lint_success_html.out b/cli/tests/testdata/doc/lint_success_html.out
new file mode 100644
index 000000000..8c4c2d187
--- /dev/null
+++ b/cli/tests/testdata/doc/lint_success_html.out
@@ -0,0 +1 @@
+Written 7 files to "./docs/"
diff --git a/cli/tests/testdata/doc/lint_success_json.out b/cli/tests/testdata/doc/lint_success_json.out
new file mode 100644
index 000000000..bf06a15cd
--- /dev/null
+++ b/cli/tests/testdata/doc/lint_success_json.out
@@ -0,0 +1,48 @@
+[
+ {
+ "kind": "class",
+ "name": "Test",
+ "location": {
+ "filename": "file:///[WILDCARD]/lint_success.ts",
+ "line": 2,
+ "col": 0
+ },
+ "declarationKind": "export",
+ "jsDoc": {
+ "doc": "My test class."
+ },
+ "classDef": {
+ "isAbstract": false,
+ "constructors": [],
+ "properties": [
+ {
+ "jsDoc": {
+ "doc": "My property."
+ },
+ "tsType": {
+ "repr": "string",
+ "kind": "keyword",
+ "keyword": "string"
+ },
+ "readonly": false,
+ "accessibility": null,
+ "optional": false,
+ "isAbstract": false,
+ "isStatic": false,
+ "name": "prop",
+ "location": {
+ "filename": "file:///[WILDCARD]/lint_success.ts",
+ "line": 4,
+ "col": 2
+ }
+ }
+ ],
+ "indexSignatures": [],
+ "methods": [],
+ "extends": null,
+ "implements": [],
+ "typeParams": [],
+ "superTypeParams": []
+ }
+ }
+]
diff --git a/cli/tests/testdata/doc/referenced_private_types_fixed.out b/cli/tests/testdata/doc/referenced_private_types_fixed.out
index 4621c6371..c05ac45a1 100644
--- a/cli/tests/testdata/doc/referenced_private_types_fixed.out
+++ b/cli/tests/testdata/doc/referenced_private_types_fixed.out
@@ -1,16 +1 @@
-Defined in file:///[WILDCARD]/referenced_private_types_fixed.ts:8:1
-
-class MyClass
- Doc comment
-
- prop: MyInterface
- Doc comment
-
-Defined in file:///[WILDCARD]/referenced_private_types_fixed.ts:2:1
-
-interface MyInterface
- Doc comment
-
- prop?: string
- Doc comment
-
+Checked 1 file
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index 9c88c8e84..75a559af1 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -138,9 +138,9 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
let mut doc_nodes_by_url =
IndexMap::with_capacity(module_specifiers.len());
- for module_specifier in &module_specifiers {
- let nodes = doc_parser.parse_with_reexports(module_specifier)?;
- doc_nodes_by_url.insert(module_specifier.clone(), nodes);
+ for module_specifier in module_specifiers {
+ let nodes = doc_parser.parse_with_reexports(&module_specifier)?;
+ doc_nodes_by_url.insert(module_specifier, nodes);
}
if doc_flags.lint {
@@ -157,9 +157,23 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
.boxed_local()
.await
} else {
- let doc_nodes: Vec<doc::DocNode> =
- doc_nodes_by_url.values().flatten().cloned().collect();
- print_docs(doc_flags, doc_nodes)
+ let modules_len = doc_nodes_by_url.len();
+ let doc_nodes =
+ doc_nodes_by_url.into_values().flatten().collect::<Vec<_>>();
+
+ if doc_flags.json {
+ write_json_to_stdout(&doc_nodes)
+ } else if doc_flags.lint {
+ // don't output docs if running with only the --lint flag
+ log::info!(
+ "Checked {} file{}",
+ modules_len,
+ if modules_len == 1 { "" } else { "s" }
+ );
+ Ok(())
+ } else {
+ print_docs_to_stdout(doc_flags, doc_nodes)
+ }
}
}
@@ -204,14 +218,10 @@ async fn generate_docs_directory(
Ok(())
}
-fn print_docs(
+fn print_docs_to_stdout(
doc_flags: DocFlags,
mut doc_nodes: Vec<deno_doc::DocNode>,
) -> Result<(), AnyError> {
- if doc_flags.json {
- return write_json_to_stdout(&doc_nodes);
- }
-
doc_nodes.retain(|doc_node| doc_node.kind != doc::DocNodeKind::Import);
let details = if let Some(filter) = doc_flags.filter {
let nodes = doc::find_nodes_by_name_recursively(doc_nodes, filter.clone());