Add block scalar newline warning (#295)

In YAML, block scalars (`|` and `>`) silently add a trailing newline by default
("clip" chomping). This can cause subtle bugs when the newline is unintentional.

This PR adds a warning when clip chomping is used in fields where trailing
newlines commonly cause issues:

- Environment variables (workflow, job, step, container, service levels)
- Action inputs (`with:`)
- Reusable workflow inputs and secrets
- Job outputs
- Matrix values (including `include` and `exclude`)
- Concurrency groups

The warning suggests using `|-` (strip) or `|+` (keep) to be explicit.

Intentionally does NOT warn for:
- `run:` scripts (trailing newlines are normal)
- Fields trimmed server-side (`if:`, `name:`, `runs-on:`, etc.)

The feature is gated behind the `blockScalarChompingWarning` feature flag.
This commit is contained in:
eric sciple
2026-01-12 09:36:43 -06:00
committed by GitHub
parent 54404aa9ff
commit 2816233a40
14 changed files with 1479 additions and 25 deletions
@@ -152,11 +152,27 @@ export class YamlObjectReader implements ObjectReader {
return new BooleanToken(fileId, range, value, undefined);
case "string": {
let source: string | undefined;
let blockScalarHeader: string | undefined;
if (token.srcToken && "source" in token.srcToken) {
source = token.srcToken.source;
// Extract block scalar header (e.g., |-, |+, >-)
//
// CST node interfaces are supported and documented per yaml library maintainer:
// https://eemeli.org/yaml/#parser -> "For a complete description of CST node
// interfaces, please consult the cst.ts source."
// See also: https://github.com/eemeli/yaml/issues/643
if (token.srcToken.type === "block-scalar" && "props" in token.srcToken) {
const props = token.srcToken.props as Array<{type: string; source?: string}>;
const headerProp = props.find(p => p.type === "block-scalar-header");
if (headerProp?.source) {
blockScalarHeader = headerProp.source;
}
}
}
return new StringToken(fileId, range, value, undefined, source);
return new StringToken(fileId, range, value, undefined, source, blockScalarHeader);
}
default:
throw new Error(`Unexpected value type '${typeof value}' when reading object`);