1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
This commit is contained in:
Marvin Hagemeister 2024-10-28 19:14:27 +01:00
parent 87cd38e4bd
commit fd5f10deb8
2 changed files with 163 additions and 108 deletions

View file

@ -3,6 +3,7 @@
//! This module provides file linting utilities using
//! [`deno_lint`](https://github.com/denoland/deno_lint).
use deno_ast::swc::utils::IsEmpty;
use deno_ast::ModuleSpecifier;
use deno_ast::ParsedSource;
use deno_config::deno_json::LintRulesConfig;
@ -20,6 +21,8 @@ use deno_core::unsync::future::LocalFutureExt;
use deno_core::unsync::future::SharedLocal;
use deno_graph::ModuleGraph;
use deno_lint::diagnostic::LintDiagnostic;
use deno_lint::diagnostic::LintDiagnosticDetails;
use deno_lint::diagnostic::LintDiagnosticRange;
use deno_lint::linter::LintConfig;
use log::debug;
use oxc::allocator::Allocator;
@ -53,6 +56,7 @@ use crate::tools::fmt::run_parallelized;
use crate::util::display;
use crate::util::file_watcher;
use crate::util::fs::canonicalize_path;
use crate::util::fs::specifier_from_file_path;
use crate::util::path::is_script_ext;
use crate::util::sync::AtomicFlag;
@ -277,6 +281,7 @@ impl WorkspaceLinter {
member_dir: WorkspaceDirectory,
paths: Vec<PathBuf>,
) -> Result<(), AnyError> {
eprintln!("LINT FILES {:#?}", paths);
self.file_count += paths.len();
let lint_rules = self.lint_rule_provider.resolve_lint_rules_err_empty(
@ -306,6 +311,7 @@ impl WorkspaceLinter {
let mut futures = Vec::with_capacity(2);
if linter.has_package_rules() {
eprintln!("PKG RULES");
if self.workspace_module_graph.is_none() {
let module_graph_creator = self.module_graph_creator.clone();
let packages = self.workspace_dir.jsr_packages_for_publish();
@ -372,11 +378,11 @@ impl WorkspaceLinter {
deno_ast::strip_bom(fs::read_to_string(&file_path)?);
// don't bother rechecking this file if it didn't have any diagnostics before
if let Some(incremental_cache) = &maybe_incremental_cache {
if incremental_cache.is_file_same(&file_path, &file_text) {
return Ok(());
}
}
// if let Some(incremental_cache) = &maybe_incremental_cache {
// if incremental_cache.is_file_same(&file_path, &file_text) {
// return Ok(());
// }
// }
let allocator = Allocator::default();
let source_type = SourceType::from_path(&file_path).unwrap();
@ -389,17 +395,64 @@ impl WorkspaceLinter {
let semantic = Rc::new(semantic_ret.semantic);
let messages = oxc_linter.run(&file_path, semantic);
let mut diagnostics: Vec<LintDiagnostic> = vec![];
let specifier = specifier_from_file_path(&file_path)?;
for msg in messages {
eprintln!("oxc {:#?}", msg.error)
eprintln!("oxc {:#?}", msg.error);
let range: Option<LintDiagnosticRange> =
if msg.error.labels.is_empty() {
None
} else {
if let Some(_labels) = &msg.error.labels {
// TODO: Multiple labels? Not sure what they are
// exactly
// TODO: I have no idea what SWC wants from me
// if let Some(first) = labels.first() {
// let start = SourcePos {};
// Some(LintDiagnosticRange {
// text_info: SourceTextInfo::from_string(file_text),
// range: SourceRange {
// start: SourcePos::unsafely_from_byte_pos(
// BytePos {
// (first.offset())
// },
// ),
// end: first.offset() + first.len(),
// },
// description: first.label().map(|s| s.to_string()),
// })
// }
None
} else {
None
}
};
diagnostics.push(LintDiagnostic {
specifier: specifier.clone(),
details: LintDiagnosticDetails {
message: msg.error.message.to_string(),
custom_docs_url: msg
.error
.url
.as_ref()
.map(|x| x.to_string()),
code: "foo".to_string(),
fixes: vec![],
hint: None,
info: vec![],
},
range,
});
}
let r = linter.lint_file(
let mut r = linter.lint_file(
&file_path,
file_text,
cli_options.ext_flag().as_deref(),
);
if let Ok((file_source, file_diagnostics)) = &r {
if let Ok((file_source, file_diagnostics)) = &mut r {
if let Some(incremental_cache) = &maybe_incremental_cache {
if file_diagnostics.is_empty() {
// update the incremental cache if there were no diagnostics
@ -410,6 +463,8 @@ impl WorkspaceLinter {
)
}
}
file_diagnostics.append(&mut diagnostics);
}
let success = handle_lint_result(

View file

@ -993,107 +993,107 @@ async fn main_server(
.unwrap(),
)
}
(&Method::POST, "/kv_blackhole/snapshot_read") => {
if req
.headers()
.get("authorization")
.and_then(|x| x.to_str().ok())
.unwrap_or_default()
!= format!("Bearer {}", KV_DATABASE_TOKEN)
{
return Ok(
Response::builder()
.status(StatusCode::UNAUTHORIZED)
.body(empty_body())
.unwrap(),
);
}
// (&Method::POST, "/kv_blackhole/snapshot_read") => {
// if req
// .headers()
// .get("authorization")
// .and_then(|x| x.to_str().ok())
// .unwrap_or_default()
// != format!("Bearer {}", KV_DATABASE_TOKEN)
// {
// return Ok(
// Response::builder()
// .status(StatusCode::UNAUTHORIZED)
// .body(empty_body())
// .unwrap(),
// );
// }
let body = req
.into_body()
.collect()
.await
.unwrap_or_default()
.to_bytes();
let Ok(body): Result<SnapshotRead, _> = prost::Message::decode(&body[..])
else {
return Ok(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(empty_body())
.unwrap(),
);
};
if body.ranges.is_empty() {
return Ok(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(empty_body())
.unwrap(),
);
}
Ok(
Response::builder()
.body(UnsyncBoxBody::new(Full::new(Bytes::from(
SnapshotReadOutput {
ranges: body
.ranges
.iter()
.map(|_| ReadRangeOutput { values: vec![] })
.collect(),
read_disabled: false,
read_is_strongly_consistent: true,
status: SnapshotReadStatus::SrSuccess.into(),
}
.encode_to_vec(),
))))
.unwrap(),
)
}
(&Method::POST, "/kv_blackhole/atomic_write") => {
if req
.headers()
.get("authorization")
.and_then(|x| x.to_str().ok())
.unwrap_or_default()
!= format!("Bearer {}", KV_DATABASE_TOKEN)
{
return Ok(
Response::builder()
.status(StatusCode::UNAUTHORIZED)
.body(empty_body())
.unwrap(),
);
}
// let body = req
// .into_body()
// .collect()
// .await
// .unwrap_or_default()
// .to_bytes();
// let Ok(body): Result<SnapshotRead, _> = prost::Message::decode(&body[..])
// else {
// return Ok(
// Response::builder()
// .status(StatusCode::BAD_REQUEST)
// .body(empty_body())
// .unwrap(),
// );
// };
// if body.ranges.is_empty() {
// return Ok(
// Response::builder()
// .status(StatusCode::BAD_REQUEST)
// .body(empty_body())
// .unwrap(),
// );
// }
// Ok(
// Response::builder()
// .body(UnsyncBoxBody::new(Full::new(Bytes::from(
// SnapshotReadOutput {
// ranges: body
// .ranges
// .iter()
// .map(|_| ReadRangeOutput { values: vec![] })
// .collect(),
// read_disabled: false,
// read_is_strongly_consistent: true,
// status: SnapshotReadStatus::SrSuccess.into(),
// }
// .encode_to_vec(),
// ))))
// .unwrap(),
// )
// }
// (&Method::POST, "/kv_blackhole/atomic_write") => {
// if req
// .headers()
// .get("authorization")
// .and_then(|x| x.to_str().ok())
// .unwrap_or_default()
// != format!("Bearer {}", KV_DATABASE_TOKEN)
// {
// return Ok(
// Response::builder()
// .status(StatusCode::UNAUTHORIZED)
// .body(empty_body())
// .unwrap(),
// );
// }
let body = req
.into_body()
.collect()
.await
.unwrap_or_default()
.to_bytes();
let Ok(_body): Result<AtomicWrite, _> = prost::Message::decode(&body[..])
else {
return Ok(
Response::builder()
.status(StatusCode::BAD_REQUEST)
.body(empty_body())
.unwrap(),
);
};
Ok(
Response::builder()
.body(UnsyncBoxBody::new(Full::new(Bytes::from(
AtomicWriteOutput {
status: AtomicWriteStatus::AwSuccess.into(),
versionstamp: vec![0u8; 10],
failed_checks: vec![],
}
.encode_to_vec(),
))))
.unwrap(),
)
}
// let body = req
// .into_body()
// .collect()
// .await
// .unwrap_or_default()
// .to_bytes();
// let Ok(_body): Result<AtomicWrite, _> = prost::Message::decode(&body[..])
// else {
// return Ok(
// Response::builder()
// .status(StatusCode::BAD_REQUEST)
// .body(empty_body())
// .unwrap(),
// );
// };
// Ok(
// Response::builder()
// .body(UnsyncBoxBody::new(Full::new(Bytes::from(
// AtomicWriteOutput {
// status: AtomicWriteStatus::AwSuccess.into(),
// versionstamp: vec![0u8; 10],
// failed_checks: vec![],
// }
// .encode_to_vec(),
// ))))
// .unwrap(),
// )
// }
(&Method::GET, "/upgrade/sleep/release-latest.txt") => {
tokio::time::sleep(Duration::from_secs(95)).await;
return Ok(