mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix: update deno_lint and swc (#21718)
Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
parent
741afc4b94
commit
69959aa01f
14 changed files with 320 additions and 300 deletions
|
@ -56,7 +56,7 @@
|
|||
"ext/websocket/autobahn/reports"
|
||||
],
|
||||
"plugins": [
|
||||
"https://plugins.dprint.dev/typescript-0.88.7.wasm",
|
||||
"https://plugins.dprint.dev/typescript-0.88.8.wasm",
|
||||
"https://plugins.dprint.dev/json-0.19.1.wasm",
|
||||
"https://plugins.dprint.dev/markdown-0.16.3.wasm",
|
||||
"https://plugins.dprint.dev/toml-0.5.4.wasm",
|
||||
|
|
2
.github/workflows/ci.generate.ts
vendored
2
.github/workflows/ci.generate.ts
vendored
|
@ -426,6 +426,8 @@ const ci = {
|
|||
env: {
|
||||
CARGO_TERM_COLOR: "always",
|
||||
RUST_BACKTRACE: "full",
|
||||
// disable anyhow's library backtrace
|
||||
RUST_LIB_BACKTRACE: 0,
|
||||
},
|
||||
steps: skipJobsIfPrAndMarkedSkip([
|
||||
reconfigureWindowsStorage,
|
||||
|
|
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
|
@ -113,6 +113,7 @@ jobs:
|
|||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
RUST_BACKTRACE: full
|
||||
RUST_LIB_BACKTRACE: 0
|
||||
steps:
|
||||
- name: Reconfigure Windows Storage
|
||||
if: '!(matrix.skip) && (startsWith(matrix.os, ''windows'') && !endsWith(matrix.os, ''-xl''))'
|
||||
|
|
355
Cargo.lock
generated
355
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -40,7 +40,7 @@ license = "MIT"
|
|||
repository = "https://github.com/denoland/deno"
|
||||
|
||||
[workspace.dependencies]
|
||||
deno_ast = { version = "0.31.6", features = ["transpiling"] }
|
||||
deno_ast = { version = "1.0.1", features = ["transpiling"] }
|
||||
deno_core = { version = "0.244.0" }
|
||||
|
||||
deno_runtime = { version = "0.138.0", path = "./runtime" }
|
||||
|
|
|
@ -60,16 +60,18 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_gra
|
|||
deno_cache_dir = "=0.6.1"
|
||||
deno_config = "=0.6.5"
|
||||
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
||||
deno_doc = { version = "=0.85.0", features = ["html"] }
|
||||
deno_emit = "=0.32.0"
|
||||
deno_graph = "=0.62.2"
|
||||
deno_lint = { version = "=0.52.2", features = ["docs"] }
|
||||
deno_doc = { version = "=0.89.0", features = ["html"] }
|
||||
deno_emit = "=0.33.0"
|
||||
deno_graph = "=0.63.0"
|
||||
deno_lint = { version = "=0.53.0", features = ["docs"] }
|
||||
deno_lockfile.workspace = true
|
||||
deno_npm = "0.15.3"
|
||||
deno_npm = "=0.15.3"
|
||||
deno_runtime = { workspace = true, features = ["dont_create_runtime_snapshot", "include_js_files_for_snapshotting"] }
|
||||
deno_semver = "0.5.1"
|
||||
# todo(dsherret): investigate https://github.com/denoland/deno_semver/commit/98f9174baef199809295077b3b68c9fa58defb9b causing
|
||||
# lsp_completions_auto_import_and_quick_fix_with_import_map to fail when bumping this version
|
||||
deno_semver = "=0.5.1"
|
||||
deno_task_shell = "=0.14.0"
|
||||
eszip = "=0.56.0"
|
||||
eszip = "=0.57.0"
|
||||
napi_sym.workspace = true
|
||||
|
||||
async-trait.workspace = true
|
||||
|
@ -91,7 +93,7 @@ dotenvy = "0.15.7"
|
|||
dprint-plugin-json = "=0.19.1"
|
||||
dprint-plugin-jupyter = "=0.1.2"
|
||||
dprint-plugin-markdown = "=0.16.3"
|
||||
dprint-plugin-typescript = "=0.88.7"
|
||||
dprint-plugin-typescript = "=0.88.8"
|
||||
encoding_rs.workspace = true
|
||||
env_logger = "=0.10.0"
|
||||
fancy-regex = "=0.10.0"
|
||||
|
@ -100,7 +102,7 @@ flate2.workspace = true
|
|||
fs3.workspace = true
|
||||
glob = "0.3.1"
|
||||
hex.workspace = true
|
||||
import_map = { version = "=0.18.0", features = ["ext"] }
|
||||
import_map = { version = "=0.18.1", features = ["ext"] }
|
||||
indexmap.workspace = true
|
||||
jsonc-parser = { version = "=0.23.0", features = ["serde"] }
|
||||
lazy-regex.workspace = true
|
||||
|
|
11
cli/cache/module_info.rs
vendored
11
cli/cache/module_info.rs
vendored
|
@ -6,11 +6,9 @@ use deno_ast::MediaType;
|
|||
use deno_ast::ModuleSpecifier;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde_json;
|
||||
use deno_graph::CapturingModuleParser;
|
||||
use deno_graph::DefaultModuleAnalyzer;
|
||||
use deno_graph::ModuleInfo;
|
||||
use deno_graph::ModuleParser;
|
||||
use deno_graph::ParsedSourceStore;
|
||||
use deno_runtime::deno_webstorage::rusqlite::params;
|
||||
|
||||
use super::cache_db::CacheDB;
|
||||
|
@ -115,19 +113,18 @@ impl ModuleInfoCache {
|
|||
|
||||
pub fn as_module_analyzer<'a>(
|
||||
&'a self,
|
||||
parser: Option<&'a dyn ModuleParser>,
|
||||
store: &'a dyn ParsedSourceStore,
|
||||
parser: &'a dyn ModuleParser,
|
||||
) -> ModuleInfoCacheModuleAnalyzer<'a> {
|
||||
ModuleInfoCacheModuleAnalyzer {
|
||||
module_info_cache: self,
|
||||
parser: CapturingModuleParser::new(parser, store),
|
||||
parser,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ModuleInfoCacheModuleAnalyzer<'a> {
|
||||
module_info_cache: &'a ModuleInfoCache,
|
||||
parser: CapturingModuleParser<'a>,
|
||||
parser: &'a dyn ModuleParser,
|
||||
}
|
||||
|
||||
impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> {
|
||||
|
@ -156,7 +153,7 @@ impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> {
|
|||
}
|
||||
|
||||
// otherwise, get the module info from the parsed source cache
|
||||
let analyzer = DefaultModuleAnalyzer::new(&self.parser);
|
||||
let analyzer = DefaultModuleAnalyzer::new(self.parser);
|
||||
let module_info = analyzer.analyze(specifier, source, media_type)?;
|
||||
|
||||
// then attempt to cache it
|
||||
|
|
30
cli/cache/parsed_source.rs
vendored
30
cli/cache/parsed_source.rs
vendored
|
@ -9,6 +9,7 @@ use deno_ast::ParsedSource;
|
|||
use deno_core::parking_lot::Mutex;
|
||||
use deno_graph::CapturingModuleParser;
|
||||
use deno_graph::ModuleParser;
|
||||
use deno_graph::ParseOptions;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ParsedSourceCache {
|
||||
|
@ -37,7 +38,13 @@ impl ParsedSourceCache {
|
|||
) -> deno_core::anyhow::Result<ParsedSource, deno_ast::Diagnostic> {
|
||||
let parser = self.as_capturing_parser();
|
||||
// this will conditionally parse because it's using a CapturingModuleParser
|
||||
parser.parse_module(specifier, source, media_type)
|
||||
parser.parse_module(ParseOptions {
|
||||
specifier,
|
||||
source,
|
||||
media_type,
|
||||
// don't bother enabling because this method is currently only used for emitting
|
||||
scope_analysis: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Frees the parsed source from memory.
|
||||
|
@ -50,10 +57,6 @@ impl ParsedSourceCache {
|
|||
pub fn as_capturing_parser(&self) -> CapturingModuleParser {
|
||||
CapturingModuleParser::new(None, self)
|
||||
}
|
||||
|
||||
pub fn as_store(self: &Arc<Self>) -> Arc<dyn deno_graph::ParsedSourceStore> {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// It's ok that this is racy since in non-LSP situations
|
||||
|
@ -76,4 +79,21 @@ impl deno_graph::ParsedSourceStore for ParsedSourceCache {
|
|||
) -> Option<ParsedSource> {
|
||||
self.sources.lock().get(specifier).cloned()
|
||||
}
|
||||
|
||||
fn get_scope_analysis_parsed_source(
|
||||
&self,
|
||||
specifier: &deno_graph::ModuleSpecifier,
|
||||
) -> Option<ParsedSource> {
|
||||
let mut sources = self.sources.lock();
|
||||
let parsed_source = sources.get(specifier)?;
|
||||
if parsed_source.has_scope_analysis() {
|
||||
Some(parsed_source.clone())
|
||||
} else {
|
||||
// upgrade to have scope analysis
|
||||
let parsed_source = sources.remove(specifier).unwrap();
|
||||
let parsed_source = parsed_source.into_with_scope_analysis();
|
||||
sources.insert(specifier.clone(), parsed_source.clone());
|
||||
Some(parsed_source)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use crate::util::path::specifier_to_file_path;
|
|||
use crate::util::sync::TaskQueue;
|
||||
use crate::util::sync::TaskQueuePermit;
|
||||
|
||||
use deno_config::ConfigFile;
|
||||
use deno_core::anyhow::bail;
|
||||
use deno_core::anyhow::Context;
|
||||
use deno_core::error::custom_error;
|
||||
|
@ -32,7 +33,6 @@ use deno_graph::source::Loader;
|
|||
use deno_graph::source::ResolveError;
|
||||
use deno_graph::GraphKind;
|
||||
use deno_graph::Module;
|
||||
use deno_graph::ModuleAnalyzer;
|
||||
use deno_graph::ModuleError;
|
||||
use deno_graph::ModuleGraph;
|
||||
use deno_graph::ModuleGraphError;
|
||||
|
@ -193,8 +193,11 @@ pub fn graph_lock_or_exit(graph: &ModuleGraph, lockfile: &mut Lockfile) {
|
|||
pub struct CreateGraphOptions<'a> {
|
||||
pub graph_kind: GraphKind,
|
||||
pub roots: Vec<ModuleSpecifier>,
|
||||
pub loader: &'a mut dyn Loader,
|
||||
pub analyzer: &'a dyn ModuleAnalyzer,
|
||||
/// Whether to do fast check on workspace members. This is mostly only
|
||||
/// useful when publishing.
|
||||
pub workspace_fast_check: bool,
|
||||
/// Specify `None` to use the default CLI loader.
|
||||
pub loader: Option<&'a mut dyn Loader>,
|
||||
}
|
||||
|
||||
pub struct ModuleGraphBuilder {
|
||||
|
@ -261,14 +264,12 @@ impl ModuleGraphBuilder {
|
|||
roots: Vec<ModuleSpecifier>,
|
||||
loader: &mut dyn Loader,
|
||||
) -> Result<deno_graph::ModuleGraph, AnyError> {
|
||||
let store = self.parsed_source_cache.as_store();
|
||||
let analyzer = self.module_info_cache.as_module_analyzer(None, &*store);
|
||||
self
|
||||
.create_graph_with_options(CreateGraphOptions {
|
||||
graph_kind,
|
||||
roots,
|
||||
loader,
|
||||
analyzer: &analyzer,
|
||||
loader: Some(loader),
|
||||
workspace_fast_check: false,
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
@ -277,14 +278,23 @@ impl ModuleGraphBuilder {
|
|||
&self,
|
||||
options: CreateGraphOptions<'_>,
|
||||
) -> Result<deno_graph::ModuleGraph, AnyError> {
|
||||
let maybe_imports = self.options.to_maybe_imports()?;
|
||||
let maybe_workspace_config = self.options.maybe_workspace_config();
|
||||
let workspace_members = if let Some(wc) = maybe_workspace_config {
|
||||
workspace_config_to_workspace_members(wc)?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
enum MutLoaderRef<'a> {
|
||||
Borrowed(&'a mut dyn Loader),
|
||||
Owned(cache::FetchCacher),
|
||||
}
|
||||
|
||||
impl<'a> MutLoaderRef<'a> {
|
||||
pub fn as_mut_loader(&mut self) -> &mut dyn Loader {
|
||||
match self {
|
||||
Self::Borrowed(loader) => *loader,
|
||||
Self::Owned(loader) => loader,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let parser = self.parsed_source_cache.as_capturing_parser();
|
||||
let analyzer = self.module_info_cache.as_module_analyzer(&parser);
|
||||
let maybe_imports = self.options.to_maybe_imports()?;
|
||||
let cli_resolver = self.resolver.clone();
|
||||
let graph_resolver = cli_resolver.as_graph_resolver();
|
||||
let graph_npm_resolver = cli_resolver.as_graph_npm_resolver();
|
||||
|
@ -292,22 +302,28 @@ impl ModuleGraphBuilder {
|
|||
.maybe_file_watcher_reporter
|
||||
.as_ref()
|
||||
.map(|r| r.as_reporter());
|
||||
let mut loader = match options.loader {
|
||||
Some(loader) => MutLoaderRef::Borrowed(loader),
|
||||
None => MutLoaderRef::Owned(self.create_graph_loader()),
|
||||
};
|
||||
|
||||
let mut graph = ModuleGraph::new(options.graph_kind);
|
||||
self
|
||||
.build_graph_with_npm_resolution(
|
||||
&mut graph,
|
||||
options.roots,
|
||||
options.loader,
|
||||
loader.as_mut_loader(),
|
||||
deno_graph::BuildOptions {
|
||||
is_dynamic: false,
|
||||
imports: maybe_imports,
|
||||
resolver: Some(graph_resolver),
|
||||
file_system: Some(&DenoGraphFsAdapter(self.fs.as_ref())),
|
||||
npm_resolver: Some(graph_npm_resolver),
|
||||
module_analyzer: Some(options.analyzer),
|
||||
module_analyzer: Some(&analyzer),
|
||||
module_parser: Some(&parser),
|
||||
reporter: maybe_file_watcher_reporter,
|
||||
workspace_members,
|
||||
workspace_fast_check: options.workspace_fast_check,
|
||||
workspace_members: self.get_deno_graph_workspace_members()?,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
@ -327,17 +343,11 @@ impl ModuleGraphBuilder {
|
|||
) -> Result<Arc<deno_graph::ModuleGraph>, AnyError> {
|
||||
let mut cache = self.create_graph_loader();
|
||||
let maybe_imports = self.options.to_maybe_imports()?;
|
||||
let maybe_workspace_config = self.options.maybe_workspace_config();
|
||||
let workspace_members = if let Some(wc) = maybe_workspace_config {
|
||||
workspace_config_to_workspace_members(wc)?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
let cli_resolver = self.resolver.clone();
|
||||
let graph_resolver = cli_resolver.as_graph_resolver();
|
||||
let graph_npm_resolver = cli_resolver.as_graph_npm_resolver();
|
||||
let store = self.parsed_source_cache.as_store();
|
||||
let analyzer = self.module_info_cache.as_module_analyzer(None, &*store);
|
||||
let parser = self.parsed_source_cache.as_capturing_parser();
|
||||
let analyzer = self.module_info_cache.as_module_analyzer(&parser);
|
||||
let graph_kind = self.options.type_check_mode().as_graph_kind();
|
||||
let mut graph = ModuleGraph::new(graph_kind);
|
||||
let maybe_file_watcher_reporter = self
|
||||
|
@ -357,8 +367,10 @@ impl ModuleGraphBuilder {
|
|||
resolver: Some(graph_resolver),
|
||||
npm_resolver: Some(graph_npm_resolver),
|
||||
module_analyzer: Some(&analyzer),
|
||||
module_parser: Some(&parser),
|
||||
reporter: maybe_file_watcher_reporter,
|
||||
workspace_members,
|
||||
workspace_fast_check: false,
|
||||
workspace_members: self.get_deno_graph_workspace_members()?,
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
@ -391,6 +403,30 @@ impl ModuleGraphBuilder {
|
|||
Ok(graph)
|
||||
}
|
||||
|
||||
fn get_deno_graph_workspace_members(
|
||||
&self,
|
||||
) -> Result<Vec<deno_graph::WorkspaceMember>, AnyError> {
|
||||
let maybe_workspace_config = self.options.maybe_workspace_config();
|
||||
if let Some(wc) = maybe_workspace_config {
|
||||
workspace_config_to_workspace_members(wc)
|
||||
} else {
|
||||
Ok(
|
||||
self
|
||||
.options
|
||||
.maybe_config_file()
|
||||
.as_ref()
|
||||
.and_then(|c| match config_to_workspace_member(c) {
|
||||
Ok(m) => Some(vec![m]),
|
||||
Err(e) => {
|
||||
log::debug!("Deno config was not a package: {:#}", e);
|
||||
None
|
||||
}
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn build_graph_with_npm_resolution<'a>(
|
||||
&self,
|
||||
graph: &mut ModuleGraph,
|
||||
|
@ -435,7 +471,7 @@ impl ModuleGraphBuilder {
|
|||
.strip_prefix("jsr:")
|
||||
.and_then(|value| PackageNv::from_str(value).ok())
|
||||
{
|
||||
graph.packages.add(key, value);
|
||||
graph.packages.add_nv(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -777,36 +813,34 @@ pub fn workspace_config_to_workspace_members(
|
|||
.members
|
||||
.iter()
|
||||
.map(|member| {
|
||||
workspace_member_config_try_into_workspace_member(member).with_context(
|
||||
|| {
|
||||
format!(
|
||||
"Failed to resolve configuration for '{}' workspace member at '{}'",
|
||||
member.member_name,
|
||||
member.config_file.specifier.as_str()
|
||||
)
|
||||
},
|
||||
)
|
||||
config_to_workspace_member(&member.config_file).with_context(|| {
|
||||
format!(
|
||||
"Failed to resolve configuration for '{}' workspace member at '{}'",
|
||||
member.member_name,
|
||||
member.config_file.specifier.as_str()
|
||||
)
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn workspace_member_config_try_into_workspace_member(
|
||||
config: &deno_config::WorkspaceMemberConfig,
|
||||
fn config_to_workspace_member(
|
||||
config: &ConfigFile,
|
||||
) -> Result<deno_graph::WorkspaceMember, AnyError> {
|
||||
let nv = deno_semver::package::PackageNv {
|
||||
name: config.package_name.clone(),
|
||||
version: deno_semver::Version::parse_standard(&config.package_version)?,
|
||||
name: match &config.json.name {
|
||||
Some(name) => name.clone(),
|
||||
None => bail!("Missing 'name' field in config file."),
|
||||
},
|
||||
version: match &config.json.version {
|
||||
Some(name) => deno_semver::Version::parse_standard(name)?,
|
||||
None => bail!("Missing 'version' field in config file."),
|
||||
},
|
||||
};
|
||||
Ok(deno_graph::WorkspaceMember {
|
||||
base: ModuleSpecifier::from_directory_path(&config.path).unwrap(),
|
||||
base: config.specifier.join("./").unwrap(),
|
||||
nv,
|
||||
exports: config
|
||||
.config_file
|
||||
.to_exports_config()?
|
||||
.into_map()
|
||||
// todo(dsherret): deno_graph should use an IndexMap
|
||||
.into_iter()
|
||||
.collect(),
|
||||
exports: config.to_exports_config()?.into_map(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -133,7 +133,7 @@ pub fn get_lint_references(
|
|||
parsed_source: &deno_ast::ParsedSource,
|
||||
lint_rules: Vec<&'static dyn LintRule>,
|
||||
) -> Result<Vec<Reference>, AnyError> {
|
||||
let linter = create_linter(parsed_source.media_type(), lint_rules);
|
||||
let linter = create_linter(lint_rules);
|
||||
let lint_diagnostics = linter.lint_with_ast(parsed_source);
|
||||
|
||||
Ok(
|
||||
|
|
|
@ -138,8 +138,8 @@ impl ModuleLoadPreparer {
|
|||
.as_ref()
|
||||
.map(|r| r.as_reporter());
|
||||
|
||||
let store = self.parsed_source_cache.as_store();
|
||||
let analyzer = self.module_info_cache.as_module_analyzer(None, &*store);
|
||||
let parser = self.parsed_source_cache.as_capturing_parser();
|
||||
let analyzer = self.module_info_cache.as_module_analyzer(&parser);
|
||||
|
||||
log::debug!("Creating module graph.");
|
||||
let mut graph_update_permit =
|
||||
|
@ -163,8 +163,10 @@ impl ModuleLoadPreparer {
|
|||
file_system: Some(&DenoGraphFsAdapter(self.fs.as_ref())),
|
||||
resolver: Some(graph_resolver),
|
||||
npm_resolver: Some(graph_npm_resolver),
|
||||
module_parser: Some(&parser),
|
||||
module_analyzer: Some(&analyzer),
|
||||
reporter: maybe_file_watcher_reporter,
|
||||
workspace_fast_check: false,
|
||||
workspace_members,
|
||||
},
|
||||
)
|
||||
|
|
|
@ -10,7 +10,6 @@ use crate::display::write_json_to_stdout;
|
|||
use crate::display::write_to_stdout_ignore_sigpipe;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::graph_util::graph_lock_or_exit;
|
||||
use crate::graph_util::CreateGraphOptions;
|
||||
use crate::tsc::get_types_declaration_file_text;
|
||||
use crate::util::fs::collect_specifiers;
|
||||
use crate::util::glob::FilePatterns;
|
||||
|
@ -20,10 +19,9 @@ use deno_core::anyhow::Context;
|
|||
use deno_core::error::AnyError;
|
||||
use deno_core::futures::FutureExt;
|
||||
use deno_doc as doc;
|
||||
use deno_graph::CapturingModuleParser;
|
||||
use deno_graph::DefaultParsedSourceStore;
|
||||
use deno_graph::GraphKind;
|
||||
use deno_graph::ModuleAnalyzer;
|
||||
use deno_graph::ModuleParser;
|
||||
use deno_graph::ModuleSpecifier;
|
||||
use doc::DocDiagnostic;
|
||||
use indexmap::IndexMap;
|
||||
|
@ -35,7 +33,7 @@ use std::sync::Arc;
|
|||
async fn generate_doc_nodes_for_builtin_types(
|
||||
doc_flags: DocFlags,
|
||||
cli_options: &Arc<CliOptions>,
|
||||
capturing_parser: CapturingModuleParser<'_>,
|
||||
parser: &dyn ModuleParser,
|
||||
analyzer: &dyn ModuleAnalyzer,
|
||||
) -> Result<IndexMap<ModuleSpecifier, Vec<doc::DocNode>>, AnyError> {
|
||||
let source_file_specifier =
|
||||
|
@ -65,7 +63,7 @@ async fn generate_doc_nodes_for_builtin_types(
|
|||
.await;
|
||||
let doc_parser = doc::DocParser::new(
|
||||
&graph,
|
||||
capturing_parser,
|
||||
parser,
|
||||
doc::DocParserOptions {
|
||||
diagnostics: false,
|
||||
private: doc_flags.private,
|
||||
|
@ -80,19 +78,16 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
|
|||
let factory = CliFactory::from_flags(flags).await?;
|
||||
let cli_options = factory.cli_options();
|
||||
let module_info_cache = factory.module_info_cache()?;
|
||||
let source_parser = deno_graph::DefaultModuleParser::new_for_analysis();
|
||||
let store = DefaultParsedSourceStore::default();
|
||||
let analyzer =
|
||||
module_info_cache.as_module_analyzer(Some(&source_parser), &store);
|
||||
let capturing_parser =
|
||||
CapturingModuleParser::new(Some(&source_parser), &store);
|
||||
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);
|
||||
|
||||
let doc_nodes_by_url = match doc_flags.source_files {
|
||||
DocSourceFileFlag::Builtin => {
|
||||
generate_doc_nodes_for_builtin_types(
|
||||
doc_flags.clone(),
|
||||
cli_options,
|
||||
capturing_parser,
|
||||
&capturing_parser,
|
||||
&analyzer,
|
||||
)
|
||||
.await?
|
||||
|
@ -123,14 +118,8 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
|
|||
},
|
||||
|_, _| true,
|
||||
)?;
|
||||
let mut loader = module_graph_builder.create_graph_loader();
|
||||
let graph = module_graph_builder
|
||||
.create_graph_with_options(CreateGraphOptions {
|
||||
graph_kind: GraphKind::TypesOnly,
|
||||
roots: module_specifiers.clone(),
|
||||
loader: &mut loader,
|
||||
analyzer: &analyzer,
|
||||
})
|
||||
.create_graph(GraphKind::TypesOnly, module_specifiers.clone())
|
||||
.await?;
|
||||
|
||||
if let Some(lockfile) = maybe_lockfile {
|
||||
|
@ -139,7 +128,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
|
|||
|
||||
let doc_parser = doc::DocParser::new(
|
||||
&graph,
|
||||
capturing_parser,
|
||||
&capturing_parser,
|
||||
doc::DocParserOptions {
|
||||
private: doc_flags.private,
|
||||
diagnostics: doc_flags.lint,
|
||||
|
@ -168,7 +157,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
|
|||
let deno_ns = generate_doc_nodes_for_builtin_types(
|
||||
doc_flags.clone(),
|
||||
cli_options,
|
||||
capturing_parser,
|
||||
&capturing_parser,
|
||||
&analyzer,
|
||||
)
|
||||
.await?;
|
||||
|
|
|
@ -23,6 +23,7 @@ use deno_core::error::AnyError;
|
|||
use deno_core::error::JsStackFrame;
|
||||
use deno_core::serde_json;
|
||||
use deno_lint::diagnostic::LintDiagnostic;
|
||||
use deno_lint::linter::LintFileOptions;
|
||||
use deno_lint::linter::Linter;
|
||||
use deno_lint::linter::LinterBuilder;
|
||||
use deno_lint::rules;
|
||||
|
@ -249,14 +250,10 @@ pub fn print_rules_list(json: bool, maybe_rules_tags: Option<Vec<String>>) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_linter(
|
||||
media_type: MediaType,
|
||||
rules: Vec<&'static dyn LintRule>,
|
||||
) -> Linter {
|
||||
pub fn create_linter(rules: Vec<&'static dyn LintRule>) -> Linter {
|
||||
LinterBuilder::default()
|
||||
.ignore_file_directive("deno-lint-ignore-file")
|
||||
.ignore_diagnostic_directive("deno-lint-ignore")
|
||||
.media_type(media_type)
|
||||
.rules(rules)
|
||||
.build()
|
||||
}
|
||||
|
@ -266,12 +263,16 @@ fn lint_file(
|
|||
source_code: String,
|
||||
lint_rules: Vec<&'static dyn LintRule>,
|
||||
) -> Result<(Vec<LintDiagnostic>, String), AnyError> {
|
||||
let file_name = file_path.to_string_lossy().to_string();
|
||||
let filename = file_path.to_string_lossy().to_string();
|
||||
let media_type = MediaType::from_path(file_path);
|
||||
|
||||
let linter = create_linter(media_type, lint_rules);
|
||||
let linter = create_linter(lint_rules);
|
||||
|
||||
let (_, file_diagnostics) = linter.lint(file_name, source_code.clone())?;
|
||||
let (_, file_diagnostics) = linter.lint_file(LintFileOptions {
|
||||
filename,
|
||||
media_type,
|
||||
source_code: source_code.clone(),
|
||||
})?;
|
||||
|
||||
Ok((file_diagnostics, source_code))
|
||||
}
|
||||
|
@ -287,10 +288,13 @@ fn lint_stdin(
|
|||
return Err(generic_error("Failed to read from stdin"));
|
||||
}
|
||||
|
||||
let linter = create_linter(MediaType::TypeScript, lint_rules);
|
||||
let linter = create_linter(lint_rules);
|
||||
|
||||
let (_, file_diagnostics) =
|
||||
linter.lint(STDIN_FILE_NAME.to_string(), source_code.clone())?;
|
||||
let (_, file_diagnostics) = linter.lint_file(LintFileOptions {
|
||||
filename: STDIN_FILE_NAME.to_string(),
|
||||
source_code: source_code.clone(),
|
||||
media_type: MediaType::TypeScript,
|
||||
})?;
|
||||
|
||||
Ok((file_diagnostics, source_code))
|
||||
}
|
||||
|
|
|
@ -839,7 +839,7 @@ fn analyze_jsx_pragmas(
|
|||
|
||||
let mut analyzed_pragmas = AnalyzedJsxPragmas::default();
|
||||
|
||||
for c in parsed_source.get_leading_comments().iter() {
|
||||
for c in parsed_source.get_leading_comments()?.iter() {
|
||||
if c.kind != CommentKind::Block {
|
||||
continue; // invalid
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue