Skip to content

Commit 976087c

Browse files
committed
fix(MD022): accept per-level arrays during validation
Declare lines-above and lines-below as polymorphic configuration keys so documented six-entry arrays reach the existing MD022 deserializer without a false type-mismatch warning. Cover inline and file-backed strict configuration paths end to end.
1 parent 576e2c1 commit 976087c

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

‎src/rules/md022_blanks_around_headings.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,14 @@ impl Rule for MD022BlanksAroundHeadings {
733733
}
734734

735735
crate::impl_rule_config_methods!(MD022Config);
736+
737+
fn polymorphic_config_keys(&self) -> &'static [&'static str] {
738+
// Both options accept either one integer for every heading level or an
739+
// array of six integers, one for each of h1 through h6. The serialized
740+
// defaults are scalar, so validation must not reject the array form
741+
// before MD022's deserializer can read it.
742+
&["lines-above", "lines-below"]
743+
}
736744
}
737745

738746
#[cfg(test)]

‎tests/cli/cli_config_override_test.rs‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,91 @@ fn inline_override_unknown_global_warns() {
425425
"expected 'Unknown global option' warning for top-level key, got:\nstderr: {stderr}"
426426
);
427427
}
428+
429+
/// Issue #841: MD022 accepts a six-entry array, so validation must not infer the
430+
/// scalar default's integer type as the only valid representation.
431+
#[test]
432+
fn md022_per_level_inline_override_is_accepted_and_applied() {
433+
let dir = tempdir().unwrap();
434+
fs::write(dir.path().join("a.md"), "# Title\n\n## Section\n\nBody.\n").unwrap();
435+
436+
let output = Command::new(rumdl_bin())
437+
.current_dir(dir.path())
438+
.args([
439+
"check",
440+
"--no-config",
441+
"--no-cache",
442+
"--deny-config-warnings",
443+
"--config",
444+
"MD022.lines-above=[1,3,1,1,1,1]",
445+
"a.md",
446+
])
447+
.output()
448+
.unwrap();
449+
450+
let stdout = String::from_utf8_lossy(&output.stdout);
451+
let stderr = String::from_utf8_lossy(&output.stderr);
452+
assert_eq!(
453+
output.status.code(),
454+
Some(1),
455+
"the valid config should run and report the MD022 finding, not fail validation:\nstdout: {stdout}\nstderr: {stderr}"
456+
);
457+
assert!(
458+
stdout.contains("[MD022] Expected 3 blank lines above heading"),
459+
"the h2-specific value should be applied:\nstdout: {stdout}\nstderr: {stderr}"
460+
);
461+
assert!(
462+
!stderr.contains("[config warning]"),
463+
"a documented MD022 array must not produce a config warning:\n{stderr}"
464+
);
465+
}
466+
467+
/// The file-backed form follows the same validation path and supports `-1` in
468+
/// either per-level array, as documented by MD022.
469+
#[test]
470+
fn md022_per_level_config_file_is_accepted_and_applied() {
471+
let dir = tempdir().unwrap();
472+
fs::write(
473+
dir.path().join("custom.toml"),
474+
"[MD022]\nlines-above = [-1, 3, 1, 1, 1, 1]\nlines-below = [1, 1, 3, 1, 1, 1]\n",
475+
)
476+
.unwrap();
477+
fs::write(
478+
dir.path().join("a.md"),
479+
"# Title\n\n## Section\n\n### Subsection\n\nBody.\n",
480+
)
481+
.unwrap();
482+
483+
let output = Command::new(rumdl_bin())
484+
.current_dir(dir.path())
485+
.args([
486+
"check",
487+
"--no-cache",
488+
"--deny-config-warnings",
489+
"--config",
490+
"custom.toml",
491+
"a.md",
492+
])
493+
.output()
494+
.unwrap();
495+
496+
let stdout = String::from_utf8_lossy(&output.stdout);
497+
let stderr = String::from_utf8_lossy(&output.stderr);
498+
assert_eq!(
499+
output.status.code(),
500+
Some(1),
501+
"the valid config should run and report findings, not fail validation:\nstdout: {stdout}\nstderr: {stderr}"
502+
);
503+
assert!(
504+
stdout.contains("[MD022] Expected 3 blank lines above heading"),
505+
"the h2-specific lines-above value should be applied:\n{stdout}"
506+
);
507+
assert!(
508+
stdout.contains("[MD022] Expected 3 blank lines below heading"),
509+
"the h3-specific lines-below value should be applied:\n{stdout}"
510+
);
511+
assert!(
512+
!stderr.contains("[config warning]"),
513+
"documented MD022 arrays must not produce config warnings:\n{stderr}"
514+
);
515+
}

0 commit comments

Comments
 (0)