fix: scan piped foreach grouping blocks

This commit is contained in:
Dante
2026-09-23 01:37:51 +08:00
parent 61c230c163
commit 306c217729
2 changed files with 4 additions and 0 deletions
@@ -428,6 +428,7 @@ function invokesContainerResult(prefix, options = {}) {
const pipelineStart = clause.lastIndexOf('|');
const pipelineCommand = clause.slice(pipelineStart + 1).trim();
const isForeachLoopHeader = Boolean(options.groupingExpression) &&
pipelineStart === -1 &&
/^foreach$/i.test(pipelineCommand);
return /(?:^|\s)(?:&|\.)\s*$/.test(clause) ||
/\.\s*(?:foreach|where)\s*$/i.test(clause) ||
@@ -488,6 +488,9 @@ test('distinguishes foreach statements from the pipeline alias', () => {
expectRules('1 | foreach { Remove-Item -Force C:/tmp/demo }', [
RULES.REMOVE_FORCE,
]);
expectRules('1 | foreach ({ Remove-Item -Force C:/tmp/demo })', [
RULES.REMOVE_FORCE,
]);
});
test('classifies invoked static script-block variables but leaves assignments inert', () => {