Add warning when using $in at the beginning of a block

This commit is contained in:
132ikl
2025-02-26 22:01:54 -05:00
parent 12b8b4580c
commit 649b428f19
3 changed files with 60 additions and 2 deletions

View File

@ -1132,6 +1132,21 @@ impl<'a> GetSpan for &'a StateWorkingSet<'a> {
}
}
impl GetSpan for StateWorkingSet<'_> {
fn get_span(&self, span_id: SpanId) -> Span {
let num_permanent_spans = self.permanent_state.num_spans();
if span_id.get() < num_permanent_spans {
self.permanent_state.get_span(span_id)
} else {
*self
.delta
.spans
.get(span_id.get() - num_permanent_spans)
.expect("internal error: missing span")
}
}
}
impl miette::SourceCode for &StateWorkingSet<'_> {
fn read_span<'b>(
&'b self,

View File

@ -14,12 +14,20 @@ pub enum ParseWarning {
span: Span,
url: String,
},
#[error("Found $in at the start of a command.")]
#[diagnostic(help("Using $in at the start of a command collects the pipeline input.\nIf you did mean to collect the pipeline input, replace this with the `collect` command."))]
UnnecessaryInVariable {
#[label("try removing this")]
span: Span,
},
}
impl ParseWarning {
pub fn span(&self) -> Span {
match self {
ParseWarning::DeprecatedWarning { span, .. } => *span,
ParseWarning::UnnecessaryInVariable { span, .. } => *span,
}
}
}