diff options
Diffstat (limited to 'cli/tools/registry/diagnostics.rs')
-rw-r--r-- | cli/tools/registry/diagnostics.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs index 49f8de045..1c3a3bd58 100644 --- a/cli/tools/registry/diagnostics.rs +++ b/cli/tools/registry/diagnostics.rs @@ -15,6 +15,7 @@ use deno_ast::diagnostics::DiagnosticSourcePos; use deno_ast::diagnostics::DiagnosticSourceRange; use deno_ast::swc::common::util::take::Take; use deno_ast::SourcePos; +use deno_ast::SourceRange; use deno_ast::SourceRanged; use deno_ast::SourceTextInfo; use deno_core::anyhow::anyhow; @@ -115,6 +116,11 @@ pub enum PublishDiagnostic { text_info: SourceTextInfo, referrer: deno_graph::Range, }, + BannedTripleSlashDirectives { + specifier: Url, + text_info: SourceTextInfo, + range: SourceRange, + }, } impl PublishDiagnostic { @@ -162,6 +168,7 @@ impl Diagnostic for PublishDiagnostic { UnsupportedJsxTsx { .. } => DiagnosticLevel::Warning, ExcludedModule { .. } => DiagnosticLevel::Error, MissingConstraint { .. } => DiagnosticLevel::Error, + BannedTripleSlashDirectives { .. } => DiagnosticLevel::Error, } } @@ -177,6 +184,9 @@ impl Diagnostic for PublishDiagnostic { UnsupportedJsxTsx { .. } => Cow::Borrowed("unsupported-jsx-tsx"), ExcludedModule { .. } => Cow::Borrowed("excluded-module"), MissingConstraint { .. } => Cow::Borrowed("missing-constraint"), + BannedTripleSlashDirectives { .. } => { + Cow::Borrowed("banned-triple-slash-directives") + } } } @@ -196,6 +206,7 @@ impl Diagnostic for PublishDiagnostic { UnsupportedJsxTsx { .. } => Cow::Borrowed("JSX and TSX files are currently not supported"), ExcludedModule { .. } => Cow::Borrowed("module in package's module graph was excluded from publishing"), MissingConstraint { specifier, .. } => Cow::Owned(format!("specifier '{}' is missing a version constraint", specifier)), + BannedTripleSlashDirectives { .. } => Cow::Borrowed("triple slash directives that modify globals are not allowed"), } } @@ -253,6 +264,15 @@ impl Diagnostic for PublishDiagnostic { text_info, .. } => from_referrer_range(referrer, text_info), + BannedTripleSlashDirectives { + specifier, + range, + text_info, + } => DiagnosticLocation::ModulePosition { + specifier: Cow::Borrowed(specifier), + source_pos: DiagnosticSourcePos::SourcePos(range.start), + text_info: Cow::Borrowed(text_info), + }, } } @@ -319,6 +339,19 @@ impl Diagnostic for PublishDiagnostic { text_info, .. } => from_range(text_info, referrer), + BannedTripleSlashDirectives { + range, text_info, .. + } => Some(DiagnosticSnippet { + source: Cow::Borrowed(text_info), + highlight: DiagnosticSnippetHighlight { + style: DiagnosticSnippetHighlightStyle::Error, + range: DiagnosticSourceRange { + start: DiagnosticSourcePos::SourcePos(range.start), + end: DiagnosticSourcePos::SourcePos(range.end), + }, + description: Some("the triple slash directive".into()), + }, + }), } } @@ -348,6 +381,9 @@ impl Diagnostic for PublishDiagnostic { "specify a version constraint for the specifier in the import map" })) }, + BannedTripleSlashDirectives { .. } => Some( + Cow::Borrowed("remove the triple slash directive"), + ), } } @@ -420,6 +456,10 @@ impl Diagnostic for PublishDiagnostic { ), Cow::Borrowed("major version if one is published in the future and potentially break"), ]), + BannedTripleSlashDirectives { .. } => Cow::Borrowed(&[ + Cow::Borrowed("instead instruct the user of your package to specify these directives"), + Cow::Borrowed("or set their 'lib' compiler option appropriately"), + ]), } } @@ -449,6 +489,9 @@ impl Diagnostic for PublishDiagnostic { MissingConstraint { .. } => { Some(Cow::Borrowed("https://jsr.io/go/missing-constraint")) } + BannedTripleSlashDirectives { .. } => Some(Cow::Borrowed( + "https://jsr.io/go/banned-triple-slash-directives", + )), } } } |