feat(rust): use oxc-miette (#6938)

This commit is contained in:
Boshen 2024-10-27 13:30:20 +00:00
parent d323fe89d7
commit 6d97af46c7
11 changed files with 63 additions and 1561 deletions

View file

@ -8,7 +8,7 @@
{
"groupName": "rust crates",
"matchManagers": ["cargo"],
"ignoreDeps": ["syn", "ureq", "unicode-width"]
"ignoreDeps": ["syn", "ureq"]
},
{
"groupName": "vscode npm packages",

75
Cargo.lock generated
View file

@ -1150,31 +1150,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "miette"
version = "7.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4edc8853320c2a0dab800fbda86253c8938f6ea88510dc92c5f1ed20e794afc1"
dependencies = [
"cfg-if",
"miette-derive",
"owo-colors",
"textwrap",
"thiserror",
"unicode-width 0.1.14",
]
[[package]]
name = "miette-derive"
version = "7.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf09caffaac8068c346b6df2a7fc27a177fd20b39421a39ce0a211bde679a6c"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "mimalloc"
version = "0.1.43"
@ -1429,6 +1404,31 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "oxc-miette"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be1ef4c8027e4a7f932b83ca96b7c65274b887c9a3161c25ca0e5ae2c555c9a7"
dependencies = [
"cfg-if",
"owo-colors",
"oxc-miette-derive",
"textwrap",
"thiserror",
"unicode-width 0.2.0",
]
[[package]]
name = "oxc-miette-derive"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d83d93ebb57b593f858fb85ccb7053a2b25c24320e18221c308461ae9989b47b"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "oxc_allocator"
version = "0.34.0"
@ -1576,11 +1576,8 @@ dependencies = [
name = "oxc_diagnostics"
version = "0.34.0"
dependencies = [
"miette",
"owo-colors",
"oxc-miette",
"rustc-hash",
"textwrap",
"unicode-width 0.2.0",
]
[[package]]
@ -1929,7 +1926,7 @@ name = "oxc_span"
version = "0.34.0"
dependencies = [
"compact_str",
"miette",
"oxc-miette",
"oxc_allocator",
"oxc_ast_macros",
"oxc_estree",
@ -2076,8 +2073,8 @@ dependencies = [
"glob",
"ignore",
"jemallocator",
"miette",
"mimalloc",
"oxc-miette",
"oxc_diagnostics",
"oxc_linter",
"oxc_span",
@ -2331,9 +2328,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.88"
version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"
checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e"
dependencies = [
"unicode-ident",
]
@ -2925,9 +2922,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.82"
version = "2.0.85"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021"
checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56"
dependencies = [
"proc-macro2",
"quote",
@ -2971,18 +2968,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.64"
version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.64"
version = "1.0.65"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602"
dependencies = [
"proc-macro2",
"quote",

View file

@ -160,14 +160,13 @@ log = "0.4.22"
markdown = "1.0.0-alpha.21"
memchr = "2.7.4"
memoffset = "0.9.1"
miette = { version = "7.2.0", features = ["fancy-no-syscall"] }
miette = { package = "oxc-miette", version = "1.0.1", features = ["fancy-no-syscall"] }
mimalloc = "0.1.43"
mime_guess = "2.0.5"
nonmax = "0.5.5"
num-bigint = "0.4.6"
num-traits = "0.2.19"
once_cell = "1.20.2"
owo-colors = "4.1.0"
oxc-browserslist = "1.0.3"
oxc_resolver = "2.0.0"
petgraph = "0.6.5"
@ -192,12 +191,10 @@ sha1 = "0.10.6"
simdutf8 = { version = "0.1.5", features = ["aarch64_neon"] }
similar = "2.6.0"
tempfile = "3.13.0"
textwrap = "0.16.1"
tokio = "1.40.0"
tower-lsp = "0.20.0"
tracing-subscriber = "0.3.18"
tsify = "0.4.5"
unicode-width = "0.2.0"
ureq = { version = "2.10.1", default-features = false }
url = "2.5.2"
walkdir = "2.5.0"

View file

@ -20,8 +20,4 @@ doctest = false
[dependencies]
miette = { workspace = true }
owo-colors = { workspace = true }
rustc-hash = { workspace = true }
textwrap = { workspace = true }
unicode-width = { workspace = true }

File diff suppressed because it is too large Load diff

View file

@ -1,147 +0,0 @@
#![allow(clippy::must_use_candidate)]
#![allow(clippy::pedantic)]
#![allow(clippy::nursery)]
#![allow(dead_code)]
/// origin file: https://github.com/zkat/miette/blob/75fea0935e495d0215518c80d32dd820910982e3/src/handlers/theme.rs
use miette::ThemeCharacters;
use owo_colors::Style;
/**
Theme used by [`GraphicalReportHandler`](crate::GraphicalReportHandler) to
render fancy [`Diagnostic`](crate::Diagnostic) reports.
A theme consists of two things: the set of characters to be used for drawing,
and the
[`owo_colors::Style`](https://docs.rs/owo-colors/latest/owo_colors/struct.Style.html)s to be used to paint various items.
You can create your own custom graphical theme using this type, or you can use
one of the predefined ones using the methods below.
When created by [`Default::default`], themes are automatically selected based on the `NO_COLOR`
environment variable and whether the process is running in a terminal.
*/
#[derive(Debug, Clone)]
pub struct GraphicalTheme {
/// Characters to be used for drawing.
pub characters: ThemeCharacters,
/// Styles to be used for painting.
pub styles: ThemeStyles,
}
impl GraphicalTheme {
pub fn new(is_terminal: bool) -> Self {
match std::env::var("NO_COLOR") {
_ if !is_terminal => Self::none(),
Ok(string) if string != "0" => Self::unicode_nocolor(),
_ => Self::unicode(),
}
}
/// ASCII-art-based graphical drawing, with ANSI styling.
pub fn ascii() -> Self {
Self { characters: ThemeCharacters::ascii(), styles: ThemeStyles::ansi() }
}
/// Graphical theme that draws using both ansi colors and unicode
/// characters.
///
/// Note that full rgb colors aren't enabled by default because they're
/// an accessibility hazard, especially in the context of terminal themes
/// that can change the background color and make hardcoded colors illegible.
/// Such themes typically remap ansi codes properly, treating them more
/// like CSS classes than specific colors.
pub fn unicode() -> Self {
Self { characters: ThemeCharacters::unicode(), styles: ThemeStyles::rgb() }
}
/// Graphical theme that draws in monochrome, while still using unicode
/// characters.
pub fn unicode_nocolor() -> Self {
Self { characters: ThemeCharacters::unicode(), styles: ThemeStyles::none() }
}
/// A "basic" graphical theme that skips colors and unicode characters and
/// just does monochrome ascii art. If you want a completely non-graphical
/// rendering of your [`Diagnostic`](crate::Diagnostic)s
pub fn none() -> Self {
Self { characters: ThemeCharacters::ascii(), styles: ThemeStyles::none() }
}
}
/**
Styles for various parts of graphical rendering for the
[`GraphicalReportHandler`](crate::GraphicalReportHandler).
*/
#[derive(Debug, Clone)]
pub struct ThemeStyles {
/// Style to apply to things highlighted as "error".
pub error: Style,
/// Style to apply to things highlighted as "warning".
pub warning: Style,
/// Style to apply to things highlighted as "advice".
pub advice: Style,
/// Style to apply to the help text.
pub help: Style,
/// Style to apply to filenames/links/URLs.
pub link: Style,
/// Style to apply to line numbers.
pub linum: Style,
/// Styles to cycle through (using `.iter().cycle()`), to render the lines
/// and text for diagnostic highlights.
pub highlights: Vec<Style>,
}
fn style() -> Style {
Style::new()
}
impl ThemeStyles {
/// Nice RGB colors.
/// [Credit](http://terminal.sexy/#FRUV0NDQFRUVrEFCkKlZ9L91ap-1qnWfdbWq0NDQUFBQrEFCkKlZ9L91ap-1qnWfdbWq9fX1).
pub fn rgb() -> Self {
Self {
error: style().fg_rgb::<225, 80, 80>().bold(), // CHANGED: <255, 30, 30>
warning: style().fg_rgb::<244, 191, 117>().bold(),
advice: style().fg_rgb::<106, 159, 181>(),
help: style().fg_rgb::<106, 159, 181>(),
link: style().fg_rgb::<92, 157, 255>().bold(),
linum: style().dimmed(),
highlights: vec![
style().fg_rgb::<246, 87, 248>(),
style().fg_rgb::<30, 201, 212>(),
style().fg_rgb::<145, 246, 111>(),
],
}
}
/// ANSI color-based styles.
pub fn ansi() -> Self {
Self {
error: style().red(),
warning: style().yellow(),
advice: style().cyan(),
help: style().cyan(),
link: style().cyan().underline().bold(),
linum: style().dimmed(),
highlights: vec![
style().magenta().bold(),
style().yellow().bold(),
style().green().bold(),
],
}
}
/// No styling. Just regular ol' monochrome.
pub fn none() -> Self {
Self {
error: style(),
warning: style(),
advice: style(),
help: style(),
link: style(),
linum: style(),
highlights: vec![style()],
}
}
}

View file

@ -48,8 +48,6 @@
//! service.run();
//! ```
mod graphic_reporter;
mod graphical_theme;
mod reporter;
mod service;
@ -59,11 +57,7 @@ use std::{
ops::{Deref, DerefMut},
};
pub use crate::{
graphic_reporter::GraphicalReportHandler,
graphical_theme::GraphicalTheme,
service::{DiagnosticSender, DiagnosticService, DiagnosticTuple},
};
pub use crate::service::{DiagnosticSender, DiagnosticService, DiagnosticTuple};
pub type Error = miette::Error;
pub type Severity = miette::Severity;
@ -71,7 +65,7 @@ pub type Severity = miette::Severity;
pub type Result<T> = std::result::Result<T, OxcDiagnostic>;
use miette::{Diagnostic, SourceCode};
pub use miette::{LabeledSpan, NamedSource};
pub use miette::{GraphicalReportHandler, GraphicalTheme, LabeledSpan, NamedSource};
/// Describes an error or warning that occurred.
///

View file

@ -26,12 +26,10 @@ fn transform(path: &Path, source_text: &str) -> String {
.errors
.iter()
.map(|d| d.clone().with_source_code(Arc::clone(&source)))
.map(|error| format!("{error:?}"))
.collect::<Vec<_>>()
.join("\n");
.fold(String::new(), |s, error| s + &format!("{error:?}"));
snapshot.push_str(&format!(
"==================== Errors ====================\n\n{error_messages}\n\n```"
"==================== Errors ====================\n{error_messages}\n\n```"
));
}

View file

@ -104,6 +104,7 @@ export declare const D: {
"2": number;
};
export {};
x TS9010: Variable must have an explicit type annotation with
| --isolatedDeclarations.
,-[declarationComputedPropertyNames.d.ts:2:18]
@ -486,6 +487,7 @@ export declare class InClassMethodBad {
o(array: T, rParam: string): void;
}
export {};
x TS9025: Declaration emit for this parameter requires implicitly adding
| undefined to it's type. This is not supported with --isolatedDeclarations.
,-[fnDecl.d.ts:12:27]
@ -591,6 +593,7 @@ export declare const v2: (...a: [n: "n", a: "a"]) => {
n: typeof n;
};
export {};
x TS9010: Variable must have an explicit type annotation with
| --isolatedDeclarations.
,-[v2.d.ts:1:7]

View file

@ -211,9 +211,7 @@ impl Baseline {
self.oxc_diagnostics
.iter()
.map(|d| d.clone().with_source_code(Arc::clone(&source)))
.map(|error| format!("{error:?}"))
.collect::<Vec<_>>()
.join("\n")
.fold(String::new(), |s, error| s + &format!("{error:?}"))
}
}

View file

@ -1706,6 +1706,7 @@ x Output mismatch
# babel-preset-typescript (5/10)
* jsx-compat/ts-invalid/input.ts
x Expected `>` but found `/`
,-[tasks/coverage/babel/packages/babel-preset-typescript/test/fixtures/jsx-compat/ts-invalid/input.ts:1:7]
1 | (<div />);
@ -1743,9 +1744,9 @@ after transform: ["T", "x"]
rebuilt : ["x"]
* class/accessor-allowDeclareFields-false/input.ts
TS(18010)
x An accessibility modifier cannot be used with a private identifier.
x TS(18010): An accessibility modifier cannot be used with a private
| identifier.
,-[tasks/coverage/babel/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-false/input.ts:8:3]
7 | abstract accessor prop6: number;
8 | private accessor #p: any;
@ -1755,9 +1756,9 @@ TS(18010)
* class/accessor-allowDeclareFields-true/input.ts
TS(18010)
x An accessibility modifier cannot be used with a private identifier.
x TS(18010): An accessibility modifier cannot be used with a private
| identifier.
,-[tasks/coverage/babel/packages/babel-plugin-transform-typescript/test/fixtures/class/accessor-allowDeclareFields-true/input.ts:8:3]
7 | abstract accessor prop6: number;
8 | private accessor #p: any;
@ -2103,6 +2104,7 @@ after transform: ScopeId(0): [ScopeId(1)]
rebuilt : ScopeId(0): []
* exports/export=/input.ts
! `export = <value>;` is only supported when compiling modules to CommonJS.
| Please consider using `export default <value>;`, or add @babel/plugin-
| transform-modules-commonjs to your Babel config.
@ -2299,6 +2301,7 @@ after transform: ScopeId(0): ["A", "B"]
rebuilt : ScopeId(0): []
* imports/import=-module/input.ts
! `import lib = require(...);` is only supported when compiling modules
| to CommonJS.
| Please consider using `import lib from '...';` alongside Typescript's
@ -2953,6 +2956,7 @@ after transform: ScopeId(2): [SymbolId(2), SymbolId(4)]
rebuilt : ScopeId(2): [SymbolId(3), SymbolId(4)]
* namespace/mutable-fail/input.ts
! Namespaces exporting non-const are not supported by Babel. Change to const
| or see: https://babeljs.io/docs/en/babel-plugin-transform-typescript
,-[tasks/coverage/babel/packages/babel-plugin-transform-typescript/test/fixtures/namespace/mutable-fail/input.ts:2:14]
@ -2964,6 +2968,7 @@ rebuilt : ScopeId(2): [SymbolId(3), SymbolId(4)]
* namespace/namespace-flag/input.ts
! Namespace not marked type-only declare. Non-declarative namespaces are
| only supported experimentally in Babel. To enable and review caveats see:
| https://babeljs.io/docs/en/babel-plugin-transform-typescript
@ -3357,6 +3362,7 @@ pragma and pragmaFrag cannot be set when runtime is automatic.
Spread children are not supported in React.
* react/should-disallow-valueless-key/input.js
! Please provide an explicit key value. Using "key" as a shorthand for
| "key={true}" is not allowed.
,-[tasks/coverage/babel/packages/babel-plugin-transform-react-jsx/test/fixtures/react/should-disallow-valueless-key/input.js:2:15]
@ -3367,6 +3373,7 @@ Spread children are not supported in React.
* react/should-disallow-xml-namespacing/input.js
! Namespace tags are not supported by default. React's JSX doesn't support
| namespace tags. You can set `throwIfNamespace: false` to bypass this
| warning.
@ -3377,6 +3384,7 @@ Spread children are not supported in React.
* react/should-throw-error-namespaces-if-not-flag/input.js
! Namespace tags are not supported by default. React's JSX doesn't support
| namespace tags. You can set `throwIfNamespace: false` to bypass this
| warning.
@ -3399,6 +3407,7 @@ transform-react-jsx: unknown field `autoImport`, expected one of `runtime`, `dev
Spread children are not supported in React.
* react-automatic/should-disallow-valueless-key/input.js
! Please provide an explicit key value. Using "key" as a shorthand for
| "key={true}" is not allowed.
,-[tasks/coverage/babel/packages/babel-plugin-transform-react-jsx/test/fixtures/react-automatic/should-disallow-valueless-key/input.js:2:15]
@ -3409,6 +3418,7 @@ Spread children are not supported in React.
* react-automatic/should-disallow-xml-namespacing/input.js
! Namespace tags are not supported by default. React's JSX doesn't support
| namespace tags. You can set `throwIfNamespace: false` to bypass this
| warning.
@ -3419,6 +3429,7 @@ Spread children are not supported in React.
* react-automatic/should-throw-error-namespaces-if-not-flag/input.js
! Namespace tags are not supported by default. React's JSX doesn't support
| namespace tags. You can set `throwIfNamespace: false` to bypass this
| warning.
@ -3440,6 +3451,7 @@ x Output mismatch
# babel-plugin-transform-react-jsx-development (8/11)
* cross-platform/disallow-__self-as-jsx-attribute/input.js
! Duplicate __self prop found.
,-[tasks/coverage/babel/packages/babel-plugin-transform-react-jsx-development/test/fixtures/cross-platform/disallow-__self-as-jsx-attribute/input.js:1:14]
1 | var x = <div __self={self}></div>;
@ -3448,6 +3460,7 @@ x Output mismatch
* cross-platform/disallow-__source-as-jsx-attribute/input.js
! Duplicate __source prop found.
,-[tasks/coverage/babel/packages/babel-plugin-transform-react-jsx-development/test/fixtures/cross-platform/disallow-__source-as-jsx-attribute/input.js:1:14]
1 | var x = <div __source={source}></div>;