1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

fix(doc): deno doc --lint mod.ts should output how many files checked (#21084)

As pointed out in https://github.com/denoland/deno/issues/21067 , it's
confusing that `deno doc --lint mod.ts` outputs the documentation to
stdout on success. Instead, it would be better if it outputted how many
files were checked similar to what `deno lint` does on success. It still
outputs the documentation if `--lint` or `--html` are provided so this
is non-breaking.
This commit is contained in:
David Sherret 2023-11-04 00:43:54 -04:00 committed by GitHub
parent efa1c1c964
commit 8acf059ac6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 94 additions and 27 deletions

View file

@ -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",

View file

@ -0,0 +1 @@
Checked 1 file

View file

@ -0,0 +1,5 @@
/** My test class. */
export class Test {
/** My property. */
prop: string;
}

View file

@ -0,0 +1 @@
Written 7 files to "./docs/"

View file

@ -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": []
}
}
]

View file

@ -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

View file

@ -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());