2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2021-02-25 10:24:05 -05:00
|
|
|
|
2022-06-27 16:54:09 -04:00
|
|
|
use crate::args::DocFlags;
|
2023-11-01 11:25:05 -04:00
|
|
|
use crate::args::DocHtmlFlag;
|
2023-01-14 12:39:56 -05:00
|
|
|
use crate::args::DocSourceFileFlag;
|
2022-06-27 16:54:09 -04:00
|
|
|
use crate::args::Flags;
|
2024-02-06 15:57:10 -05:00
|
|
|
use crate::cache::LazyGraphSourceParser;
|
2021-02-25 10:24:05 -05:00
|
|
|
use crate::colors;
|
2024-01-23 10:37:43 -05:00
|
|
|
use crate::diagnostics::Diagnostic;
|
|
|
|
use crate::diagnostics::DiagnosticLevel;
|
|
|
|
use crate::diagnostics::DiagnosticLocation;
|
|
|
|
use crate::diagnostics::DiagnosticSnippet;
|
|
|
|
use crate::diagnostics::DiagnosticSnippetHighlight;
|
|
|
|
use crate::diagnostics::DiagnosticSnippetHighlightStyle;
|
|
|
|
use crate::diagnostics::DiagnosticSnippetSource;
|
|
|
|
use crate::diagnostics::DiagnosticSourcePos;
|
|
|
|
use crate::diagnostics::DiagnosticSourceRange;
|
|
|
|
use crate::diagnostics::SourceTextParsedSourceStore;
|
2022-10-28 11:03:33 -04:00
|
|
|
use crate::display::write_json_to_stdout;
|
|
|
|
use crate::display::write_to_stdout_ignore_sigpipe;
|
2023-05-01 14:35:23 -04:00
|
|
|
use crate::factory::CliFactory;
|
2023-03-13 17:04:00 -04:00
|
|
|
use crate::graph_util::graph_lock_or_exit;
|
2022-12-08 11:50:09 -05:00
|
|
|
use crate::tsc::get_types_declaration_file_text;
|
2024-01-08 12:18:42 -05:00
|
|
|
use crate::util::fs::collect_specifiers;
|
2024-01-15 19:15:39 -05:00
|
|
|
use deno_config::glob::FilePatterns;
|
|
|
|
use deno_config::glob::PathOrPatternSet;
|
2022-07-01 11:50:16 -04:00
|
|
|
use deno_core::anyhow::bail;
|
2023-11-01 11:25:05 -04:00
|
|
|
use deno_core::anyhow::Context;
|
2021-02-25 10:24:05 -05:00
|
|
|
use deno_core::error::AnyError;
|
2023-11-01 11:25:05 -04:00
|
|
|
use deno_core::futures::FutureExt;
|
2021-02-25 10:24:05 -05:00
|
|
|
use deno_doc as doc;
|
2023-06-06 17:07:46 -04:00
|
|
|
use deno_graph::GraphKind;
|
2023-11-01 11:25:05 -04:00
|
|
|
use deno_graph::ModuleAnalyzer;
|
2024-01-09 18:20:52 -05:00
|
|
|
use deno_graph::ModuleParser;
|
2021-09-02 11:38:19 -04:00
|
|
|
use deno_graph::ModuleSpecifier;
|
2023-10-31 18:19:42 -04:00
|
|
|
use doc::DocDiagnostic;
|
2024-01-23 10:37:43 -05:00
|
|
|
use doc::DocDiagnosticKind;
|
2023-10-31 18:19:42 -04:00
|
|
|
use indexmap::IndexMap;
|
2024-01-23 10:37:43 -05:00
|
|
|
use lsp_types::Url;
|
|
|
|
use std::borrow::Cow;
|
2023-11-01 11:25:05 -04:00
|
|
|
use std::collections::BTreeMap;
|
2023-12-01 15:12:10 -05:00
|
|
|
use std::rc::Rc;
|
2021-02-25 10:24:05 -05:00
|
|
|
|
2023-11-01 11:25:05 -04:00
|
|
|
async fn generate_doc_nodes_for_builtin_types(
|
2021-12-20 16:29:02 -05:00
|
|
|
doc_flags: DocFlags,
|
2024-01-09 18:20:52 -05:00
|
|
|
parser: &dyn ModuleParser,
|
2023-11-01 11:25:05 -04:00
|
|
|
analyzer: &dyn ModuleAnalyzer,
|
|
|
|
) -> Result<IndexMap<ModuleSpecifier, Vec<doc::DocNode>>, AnyError> {
|
|
|
|
let source_file_specifier =
|
|
|
|
ModuleSpecifier::parse("internal://lib.deno.d.ts").unwrap();
|
2024-01-14 12:29:17 -05:00
|
|
|
let content = get_types_declaration_file_text();
|
2023-11-01 11:25:05 -04:00
|
|
|
let mut loader = deno_graph::source::MemoryLoader::new(
|
|
|
|
vec![(
|
|
|
|
source_file_specifier.to_string(),
|
|
|
|
deno_graph::source::Source::Module {
|
|
|
|
specifier: source_file_specifier.to_string(),
|
|
|
|
content,
|
|
|
|
maybe_headers: None,
|
|
|
|
},
|
|
|
|
)],
|
|
|
|
Vec::new(),
|
|
|
|
);
|
|
|
|
let mut graph = deno_graph::ModuleGraph::new(GraphKind::TypesOnly);
|
|
|
|
graph
|
|
|
|
.build(
|
|
|
|
vec![source_file_specifier.clone()],
|
|
|
|
&mut loader,
|
|
|
|
deno_graph::BuildOptions {
|
|
|
|
module_analyzer: Some(analyzer),
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.await;
|
|
|
|
let doc_parser = doc::DocParser::new(
|
|
|
|
&graph,
|
2024-01-09 18:20:52 -05:00
|
|
|
parser,
|
2023-11-01 11:25:05 -04:00
|
|
|
doc::DocParserOptions {
|
|
|
|
diagnostics: false,
|
|
|
|
private: doc_flags.private,
|
|
|
|
},
|
|
|
|
)?;
|
|
|
|
let nodes = doc_parser.parse_module(&source_file_specifier)?.definitions;
|
|
|
|
|
|
|
|
Ok(IndexMap::from([(source_file_specifier, nodes)]))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
|
2023-05-01 14:35:23 -04:00
|
|
|
let factory = CliFactory::from_flags(flags).await?;
|
|
|
|
let cli_options = factory.cli_options();
|
2023-10-26 21:27:50 -04:00
|
|
|
let module_info_cache = factory.module_info_cache()?;
|
2024-01-09 18:20:52 -05:00
|
|
|
let parsed_source_cache = factory.parsed_source_cache();
|
|
|
|
let capturing_parser = parsed_source_cache.as_capturing_parser();
|
|
|
|
let analyzer = module_info_cache.as_module_analyzer(&capturing_parser);
|
2021-02-25 10:24:05 -05:00
|
|
|
|
2023-11-01 11:25:05 -04:00
|
|
|
let doc_nodes_by_url = match doc_flags.source_files {
|
2023-01-14 12:39:56 -05:00
|
|
|
DocSourceFileFlag::Builtin => {
|
2023-11-01 11:25:05 -04:00
|
|
|
generate_doc_nodes_for_builtin_types(
|
|
|
|
doc_flags.clone(),
|
2024-01-09 18:20:52 -05:00
|
|
|
&capturing_parser,
|
2023-11-01 11:25:05 -04:00
|
|
|
&analyzer,
|
|
|
|
)
|
|
|
|
.await?
|
2023-01-14 12:39:56 -05:00
|
|
|
}
|
2023-11-01 11:25:05 -04:00
|
|
|
DocSourceFileFlag::Paths(ref source_files) => {
|
2023-05-01 14:35:23 -04:00
|
|
|
let module_graph_builder = factory.module_graph_builder().await?;
|
|
|
|
let maybe_lockfile = factory.maybe_lockfile();
|
|
|
|
|
2024-01-08 12:18:42 -05:00
|
|
|
let module_specifiers = collect_specifiers(
|
|
|
|
FilePatterns {
|
2024-01-18 15:57:30 -05:00
|
|
|
base: cli_options.initial_cwd().to_path_buf(),
|
2024-01-15 19:15:39 -05:00
|
|
|
include: Some(PathOrPatternSet::from_relative_path_or_patterns(
|
|
|
|
cli_options.initial_cwd(),
|
|
|
|
source_files,
|
2024-01-08 12:18:42 -05:00
|
|
|
)?),
|
|
|
|
exclude: Default::default(),
|
|
|
|
},
|
|
|
|
|_, _| true,
|
|
|
|
)?;
|
2023-05-01 14:35:23 -04:00
|
|
|
let graph = module_graph_builder
|
2024-01-09 18:20:52 -05:00
|
|
|
.create_graph(GraphKind::TypesOnly, module_specifiers.clone())
|
2023-04-14 16:22:33 -04:00
|
|
|
.await?;
|
2023-03-13 17:04:00 -04:00
|
|
|
|
2023-05-01 14:35:23 -04:00
|
|
|
if let Some(lockfile) = maybe_lockfile {
|
2023-03-13 17:04:00 -04:00
|
|
|
graph_lock_or_exit(&graph, &mut lockfile.lock());
|
|
|
|
}
|
|
|
|
|
2023-10-30 23:49:43 -04:00
|
|
|
let doc_parser = doc::DocParser::new(
|
|
|
|
&graph,
|
2024-01-09 18:20:52 -05:00
|
|
|
&capturing_parser,
|
2023-10-30 23:49:43 -04:00
|
|
|
doc::DocParserOptions {
|
|
|
|
private: doc_flags.private,
|
2023-10-31 18:19:42 -04:00
|
|
|
diagnostics: doc_flags.lint,
|
2023-10-30 23:49:43 -04:00
|
|
|
},
|
|
|
|
)?;
|
2023-10-30 18:58:57 -04:00
|
|
|
|
2023-11-01 11:25:05 -04:00
|
|
|
let mut doc_nodes_by_url =
|
|
|
|
IndexMap::with_capacity(module_specifiers.len());
|
2023-10-30 18:58:57 -04:00
|
|
|
|
2023-11-04 00:43:54 -04:00
|
|
|
for module_specifier in module_specifiers {
|
|
|
|
let nodes = doc_parser.parse_with_reexports(&module_specifier)?;
|
|
|
|
doc_nodes_by_url.insert(module_specifier, nodes);
|
2023-10-30 18:58:57 -04:00
|
|
|
}
|
|
|
|
|
2023-10-31 18:19:42 -04:00
|
|
|
if doc_flags.lint {
|
|
|
|
let diagnostics = doc_parser.take_diagnostics();
|
2024-02-06 15:57:10 -05:00
|
|
|
check_diagnostics(
|
|
|
|
LazyGraphSourceParser::new(parsed_source_cache, &graph),
|
|
|
|
&diagnostics,
|
|
|
|
)?;
|
2023-10-31 18:19:42 -04:00
|
|
|
}
|
|
|
|
|
2023-11-01 11:25:05 -04:00
|
|
|
doc_nodes_by_url
|
2023-01-14 12:39:56 -05:00
|
|
|
}
|
2021-02-25 10:24:05 -05:00
|
|
|
};
|
|
|
|
|
2023-12-29 19:04:50 -05:00
|
|
|
if let Some(html_options) = &doc_flags.html {
|
|
|
|
let deno_ns = if doc_flags.source_files != DocSourceFileFlag::Builtin {
|
|
|
|
let deno_ns = generate_doc_nodes_for_builtin_types(
|
|
|
|
doc_flags.clone(),
|
2024-01-09 18:20:52 -05:00
|
|
|
&capturing_parser,
|
2023-12-29 19:04:50 -05:00
|
|
|
&analyzer,
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
let (_, deno_ns) = deno_ns.first().unwrap();
|
|
|
|
|
2024-01-23 05:25:44 -05:00
|
|
|
deno_doc::html::compute_namespaced_symbols(deno_ns, &[])
|
2023-12-29 19:04:50 -05:00
|
|
|
} else {
|
2024-01-23 05:25:44 -05:00
|
|
|
Default::default()
|
2023-12-29 19:04:50 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
generate_docs_directory(&doc_nodes_by_url, html_options, deno_ns)
|
2023-11-01 11:25:05 -04:00
|
|
|
.boxed_local()
|
|
|
|
.await
|
2021-02-25 10:24:05 -05:00
|
|
|
} else {
|
2023-11-04 00:43:54 -04:00
|
|
|
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)
|
|
|
|
}
|
2023-11-01 11:25:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-23 05:25:44 -05:00
|
|
|
struct DocResolver {
|
|
|
|
deno_ns: std::collections::HashSet<Vec<String>>,
|
|
|
|
}
|
2023-12-29 19:04:50 -05:00
|
|
|
|
|
|
|
impl deno_doc::html::HrefResolver for DocResolver {
|
2024-01-23 05:25:44 -05:00
|
|
|
fn resolve_global_symbol(&self, symbol: &[String]) -> Option<String> {
|
|
|
|
if self.deno_ns.contains(symbol) {
|
|
|
|
Some(format!(
|
|
|
|
"https://deno.land/api@{}?s={}",
|
|
|
|
env!("CARGO_PKG_VERSION"),
|
|
|
|
symbol.join(".")
|
|
|
|
))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2023-12-29 19:04:50 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn resolve_import_href(
|
|
|
|
&self,
|
|
|
|
symbol: &[String],
|
|
|
|
src: &str,
|
|
|
|
) -> Option<String> {
|
|
|
|
let mut url = ModuleSpecifier::parse(src).ok()?;
|
|
|
|
|
|
|
|
if url.domain() == Some("deno.land") {
|
|
|
|
url.set_query(Some(&format!("s={}", symbol.join("."))));
|
|
|
|
return Some(url.to_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resolve_usage(
|
|
|
|
&self,
|
|
|
|
_current_specifier: &ModuleSpecifier,
|
|
|
|
current_file: &str,
|
2024-01-31 12:34:15 -05:00
|
|
|
) -> Option<String> {
|
|
|
|
Some(current_file.to_string())
|
2023-12-29 19:04:50 -05:00
|
|
|
}
|
|
|
|
|
2024-01-31 12:34:15 -05:00
|
|
|
fn resolve_source(&self, location: &deno_doc::Location) -> Option<String> {
|
|
|
|
Some(location.filename.clone())
|
2023-12-29 19:04:50 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-01 11:25:05 -04:00
|
|
|
async fn generate_docs_directory(
|
|
|
|
doc_nodes_by_url: &IndexMap<ModuleSpecifier, Vec<doc::DocNode>>,
|
2023-12-29 19:04:50 -05:00
|
|
|
html_options: &DocHtmlFlag,
|
2024-01-23 05:25:44 -05:00
|
|
|
deno_ns: std::collections::HashSet<Vec<String>>,
|
2023-11-01 11:25:05 -04:00
|
|
|
) -> Result<(), AnyError> {
|
|
|
|
let cwd = std::env::current_dir().context("Failed to get CWD")?;
|
|
|
|
let output_dir_resolved = cwd.join(&html_options.output);
|
|
|
|
|
|
|
|
let options = deno_doc::html::GenerateOptions {
|
2023-12-29 19:04:50 -05:00
|
|
|
package_name: Some(html_options.name.to_owned()),
|
2023-12-01 15:12:10 -05:00
|
|
|
main_entrypoint: None,
|
2023-12-29 19:04:50 -05:00
|
|
|
rewrite_map: None,
|
|
|
|
hide_module_doc_title: false,
|
2024-01-23 05:25:44 -05:00
|
|
|
href_resolver: Rc::new(DocResolver { deno_ns }),
|
2023-12-29 19:04:50 -05:00
|
|
|
sidebar_flatten_namespaces: false,
|
2023-11-01 11:25:05 -04:00
|
|
|
};
|
2021-02-25 10:24:05 -05:00
|
|
|
|
2023-11-01 11:25:05 -04:00
|
|
|
let files = deno_doc::html::generate(options, doc_nodes_by_url)
|
|
|
|
.context("Failed to generate HTML documentation")?;
|
|
|
|
|
|
|
|
let path = &output_dir_resolved;
|
|
|
|
let _ = std::fs::remove_dir_all(path);
|
|
|
|
std::fs::create_dir(path)
|
|
|
|
.with_context(|| format!("Failed to create directory {:?}", path))?;
|
|
|
|
|
|
|
|
let no_of_files = files.len();
|
|
|
|
for (name, content) in files {
|
|
|
|
let this_path = path.join(name);
|
|
|
|
let prefix = this_path.parent().with_context(|| {
|
|
|
|
format!("Failed to get parent path for {:?}", this_path)
|
|
|
|
})?;
|
|
|
|
std::fs::create_dir_all(prefix)
|
|
|
|
.with_context(|| format!("Failed to create directory {:?}", prefix))?;
|
|
|
|
std::fs::write(&this_path, content)
|
|
|
|
.with_context(|| format!("Failed to write file {:?}", this_path))?;
|
2021-02-25 10:24:05 -05:00
|
|
|
}
|
2023-11-01 11:25:05 -04:00
|
|
|
|
|
|
|
log::info!(
|
|
|
|
"{}",
|
|
|
|
colors::green(format!(
|
|
|
|
"Written {} files to {:?}",
|
|
|
|
no_of_files, html_options.output
|
|
|
|
))
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-11-04 00:43:54 -04:00
|
|
|
fn print_docs_to_stdout(
|
2023-11-01 11:25:05 -04:00
|
|
|
doc_flags: DocFlags,
|
|
|
|
mut doc_nodes: Vec<deno_doc::DocNode>,
|
|
|
|
) -> Result<(), AnyError> {
|
|
|
|
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());
|
|
|
|
if nodes.is_empty() {
|
|
|
|
bail!("Node {} was not found!", filter);
|
|
|
|
}
|
|
|
|
format!(
|
|
|
|
"{}",
|
|
|
|
doc::DocPrinter::new(&nodes, colors::use_color(), doc_flags.private)
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"{}",
|
|
|
|
doc::DocPrinter::new(&doc_nodes, colors::use_color(), doc_flags.private)
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
write_to_stdout_ignore_sigpipe(details.as_bytes()).map_err(AnyError::from)
|
2021-02-25 10:24:05 -05:00
|
|
|
}
|
2023-10-31 18:19:42 -04:00
|
|
|
|
2024-01-23 10:37:43 -05:00
|
|
|
impl Diagnostic for DocDiagnostic {
|
|
|
|
fn level(&self) -> DiagnosticLevel {
|
|
|
|
DiagnosticLevel::Error
|
|
|
|
}
|
|
|
|
|
|
|
|
fn code(&self) -> impl std::fmt::Display + '_ {
|
|
|
|
match self.kind {
|
|
|
|
DocDiagnosticKind::MissingJsDoc => "missing-jsdoc",
|
|
|
|
DocDiagnosticKind::MissingExplicitType => "missing-explicit-type",
|
|
|
|
DocDiagnosticKind::MissingReturnType => "missing-return-type",
|
|
|
|
DocDiagnosticKind::PrivateTypeRef { .. } => "private-type-ref",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn message(&self) -> impl std::fmt::Display + '_ {
|
|
|
|
match &self.kind {
|
|
|
|
DocDiagnosticKind::MissingJsDoc => {
|
|
|
|
Cow::Borrowed("exported symbol is missing JSDoc documentation")
|
|
|
|
}
|
|
|
|
DocDiagnosticKind::MissingExplicitType => {
|
|
|
|
Cow::Borrowed("exported symbol is missing an explicit type annotation")
|
|
|
|
}
|
|
|
|
DocDiagnosticKind::MissingReturnType => Cow::Borrowed(
|
|
|
|
"exported function is missing an explicit return type annotation",
|
|
|
|
),
|
|
|
|
DocDiagnosticKind::PrivateTypeRef {
|
|
|
|
reference, name, ..
|
|
|
|
} => Cow::Owned(format!(
|
|
|
|
"public type '{name}' references private type '{reference}'",
|
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn location(&self) -> DiagnosticLocation {
|
|
|
|
let specifier = Url::parse(&self.location.filename).unwrap();
|
2024-01-24 16:24:52 -05:00
|
|
|
DiagnosticLocation::ModulePosition {
|
2024-01-23 10:37:43 -05:00
|
|
|
specifier: Cow::Owned(specifier),
|
|
|
|
source_pos: DiagnosticSourcePos::ByteIndex(self.location.byte_index),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn snippet(&self) -> Option<DiagnosticSnippet<'_>> {
|
|
|
|
let specifier = Url::parse(&self.location.filename).unwrap();
|
|
|
|
Some(DiagnosticSnippet {
|
|
|
|
source: DiagnosticSnippetSource::Specifier(Cow::Owned(specifier)),
|
|
|
|
highlight: DiagnosticSnippetHighlight {
|
|
|
|
style: DiagnosticSnippetHighlightStyle::Error,
|
|
|
|
range: DiagnosticSourceRange {
|
|
|
|
start: DiagnosticSourcePos::ByteIndex(self.location.byte_index),
|
|
|
|
end: DiagnosticSourcePos::ByteIndex(self.location.byte_index + 1),
|
|
|
|
},
|
|
|
|
description: None,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn hint(&self) -> Option<impl std::fmt::Display + '_> {
|
|
|
|
match &self.kind {
|
|
|
|
DocDiagnosticKind::PrivateTypeRef { .. } => {
|
|
|
|
Some("make the referenced type public or remove the reference")
|
|
|
|
}
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn snippet_fixed(&self) -> Option<DiagnosticSnippet<'_>> {
|
|
|
|
match &self.kind {
|
|
|
|
DocDiagnosticKind::PrivateTypeRef {
|
|
|
|
reference_location, ..
|
|
|
|
} => {
|
|
|
|
let specifier = Url::parse(&reference_location.filename).unwrap();
|
|
|
|
Some(DiagnosticSnippet {
|
|
|
|
source: DiagnosticSnippetSource::Specifier(Cow::Owned(specifier)),
|
|
|
|
highlight: DiagnosticSnippetHighlight {
|
|
|
|
style: DiagnosticSnippetHighlightStyle::Hint,
|
|
|
|
range: DiagnosticSourceRange {
|
|
|
|
start: DiagnosticSourcePos::ByteIndex(
|
|
|
|
reference_location.byte_index,
|
|
|
|
),
|
|
|
|
end: DiagnosticSourcePos::ByteIndex(
|
|
|
|
reference_location.byte_index + 1,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
description: Some(Cow::Borrowed("this is the referenced type")),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn info(&self) -> std::borrow::Cow<'_, [std::borrow::Cow<'_, str>]> {
|
|
|
|
match &self.kind {
|
|
|
|
DocDiagnosticKind::MissingJsDoc => Cow::Borrowed(&[]),
|
|
|
|
DocDiagnosticKind::MissingExplicitType => Cow::Borrowed(&[]),
|
|
|
|
DocDiagnosticKind::MissingReturnType => Cow::Borrowed(&[]),
|
|
|
|
DocDiagnosticKind::PrivateTypeRef { .. } => {
|
|
|
|
Cow::Borrowed(&[Cow::Borrowed(
|
|
|
|
"to ensure documentation is complete all types that are exposed in the public API must be public",
|
|
|
|
)])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn docs_url(&self) -> Option<impl std::fmt::Display + '_> {
|
|
|
|
None::<&str>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_diagnostics(
|
2024-02-06 15:57:10 -05:00
|
|
|
source_parser: LazyGraphSourceParser,
|
2024-01-23 10:37:43 -05:00
|
|
|
diagnostics: &[DocDiagnostic],
|
|
|
|
) -> Result<(), AnyError> {
|
2023-10-31 18:19:42 -04:00
|
|
|
if diagnostics.is_empty() {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
// group by location then by line (sorted) then column (sorted)
|
|
|
|
let mut diagnostic_groups = IndexMap::new();
|
|
|
|
for diagnostic in diagnostics {
|
|
|
|
diagnostic_groups
|
|
|
|
.entry(diagnostic.location.filename.clone())
|
|
|
|
.or_insert_with(BTreeMap::new)
|
|
|
|
.entry(diagnostic.location.line)
|
|
|
|
.or_insert_with(BTreeMap::new)
|
|
|
|
.entry(diagnostic.location.col)
|
|
|
|
.or_insert_with(Vec::new)
|
|
|
|
.push(diagnostic);
|
|
|
|
}
|
|
|
|
|
2024-01-23 10:37:43 -05:00
|
|
|
for (_, diagnostics_by_lc) in diagnostic_groups {
|
|
|
|
for (_, diagnostics_by_col) in diagnostics_by_lc {
|
|
|
|
for (_, diagnostics) in diagnostics_by_col {
|
2023-10-31 18:19:42 -04:00
|
|
|
for diagnostic in diagnostics {
|
2024-02-06 15:57:10 -05:00
|
|
|
let sources = SourceTextParsedSourceStore(source_parser);
|
|
|
|
log::error!("{}", diagnostic.display(&sources));
|
2023-10-31 18:19:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bail!(
|
2023-11-10 13:40:39 -05:00
|
|
|
"Found {} documentation lint error{}.",
|
2023-10-31 18:19:42 -04:00
|
|
|
colors::bold(diagnostics.len().to_string()),
|
|
|
|
if diagnostics.len() == 1 { "" } else { "s" }
|
|
|
|
);
|
|
|
|
}
|