Skip to content

Commit 2a9a870

Browse files
committed
what: add --version flag, .gitignore/mdfmtignore cleanup, empty-file test
why: --version was returning 'Unknown flag' error instead of printing the package version. Also cleaned up stale .tgz artifact, converted .mdfmtignore from template to real config patterns, added empty/whitespace-only input test coverage.
1 parent fc2aada commit 2a9a870

8 files changed

Lines changed: 45 additions & 10 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ tmp/
1616
.pnpm-store/
1717
.yarn/
1818
.cache/
19-
*.tgz
19+
pack/
2020

2121
# Agent/tool local state
2222
.agents/

.mdfmtignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# .mdfmtignore — files and directories to skip with --all
1+
# .mdfmtignore — files and directories to skip when using --all
22
# One pattern per line. Lines starting with # are comments.
33
# Patterns ending with / match directory prefixes.
44
# Patterns containing * are treated as simple globs where *
55
# matches any characters except a path separator (/).
6-
# Examples:
7-
# vendor/ skip the vendor/ directory entirely
8-
# *.generated.md skip any file matching this pattern
9-
# tmp/ skip the tmp/ directory
6+
7+
node_modules/
8+
pack/
9+
*.structure.json
10+
*.snap

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ mdfmt [options] <path...>
102102
| `--dry-run`, `-n` | Run pipe-safety preflight, preview changes without writing |
103103
| `--audit-tables` | Print table row cell counts and pipe hazards without writing |
104104
| `--no-repair` | Report repairable table issues instead of modifying them |
105+
| `--version` | Print version number and exit |
105106
| `--help`, `-h` | Display help message |
106107

107108
### File exclusion

SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ binary. See the README for details on per-platform auto-wiring.
8383
- `--dry-run`, `-n`: Run pipe-safety preflight, then show what would be changed without writing files
8484
- `--audit-tables`: Print table row cell counts and pipe hazards without writing; use before/after agent table edits
8585
- `--no-repair`: In write modes, report repairable table issues instead of modifying them
86+
- `--version`: Print version number and exit
8687
- `--help`, `-h`: Display help message
8788

8889
### File exclusion

src/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const { buildSnapshot, validateStructure, loadSnapshot, saveSnapshot, compareSna
3636
const SKILL_DIR = resolve(__dirname, "..");
3737
const FORMATTER_MODULE = join(SKILL_DIR, "src", "format-content.mjs");
3838
const NODE_RUNTIME_MIN_VERSION = 24;
39-
const LONG_FLAGS = new Set(["check", "fix", "all", "guard", "verify", "fences", "validate", "doctor", "dry-run", "audit-tables", "no-repair", "help"]);
39+
const LONG_FLAGS = new Set(["check", "fix", "all", "guard", "verify", "fences", "validate", "doctor", "dry-run", "audit-tables", "no-repair", "help", "version"]);
4040
const SHORT_FLAGS = { h: "help", n: "dry-run" };
41-
const READ_ONLY_FLAGS = new Set(["check", "validate", "fences", "verify", "doctor", "help", "dry-run", "audit-tables"]);
41+
const READ_ONLY_FLAGS = new Set(["check", "validate", "fences", "verify", "doctor", "help", "dry-run", "audit-tables", "version"]);
4242
const MARKDOWN_EXTENSIONS = new Set([".md", ".markdown", ".mdx"]);
4343

4444
/**
@@ -48,10 +48,10 @@ const MARKDOWN_EXTENSIONS = new Set([".md", ".markdown", ".mdx"]);
4848
* Throws on unknown flags. The -- separator stops flag parsing.
4949
*
5050
* @param {string[]} argv - Process argv array (e.g. process.argv).
51-
* @returns {{ _: string[], check: boolean, fix: boolean, all: boolean, guard: boolean, verify: boolean, fences: boolean, validate: boolean, doctor: boolean, 'dry-run': boolean, 'audit-tables': boolean, 'no-repair': boolean, help: boolean }}
51+
* @returns {{ _: string[], check: boolean, fix: boolean, all: boolean, guard: boolean, verify: boolean, fences: boolean, validate: boolean, doctor: boolean, 'dry-run': boolean, 'audit-tables': boolean, 'no-repair': boolean, help: boolean, version: boolean }}
5252
*/
5353
function parseArgs(argv) {
54-
const args = { _: [], check: false, fix: false, all: false, guard: false, verify: false, fences: false, validate: false, doctor: false, "dry-run": false, "audit-tables": false, "no-repair": false, help: false };
54+
const args = { _: [], check: false, fix: false, all: false, guard: false, verify: false, fences: false, validate: false, doctor: false, "dry-run": false, "audit-tables": false, "no-repair": false, help: false, version: false };
5555

5656
for (let i = 2; i < argv.length; i++) {
5757
const arg = argv[i];
@@ -95,6 +95,7 @@ Options:
9595
--dry-run, -n Run pipe-safety preflight, then preview changes
9696
--audit-tables Print table row cell counts and pipe hazards without writing
9797
--no-repair In write modes, report repairable table issues instead of modifying them
98+
--version Print version number and exit
9899
--help, -h Show this help
99100
100101
File exclusion:
@@ -1016,6 +1017,11 @@ function processFile(filePath, args) {
10161017
*/
10171018
function main(argv = process.argv) {
10181019
const args = parseArgs(argv);
1020+
if (args.version) {
1021+
const pkg = JSON.parse(readFileSync(join(SKILL_DIR, "package.json"), "utf8"));
1022+
console.log(pkg.version);
1023+
return 0;
1024+
}
10191025
if (args.doctor) return runDoctor() ? 0 : 1;
10201026
if (args.help || (args._.length === 0 && !args.all)) {
10211027
printHelp();

test/integration/cli.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,14 @@ describe('markdown formatter CLI integration', () => {
414414
assert.match(result.stdout, /--doctor/);
415415
});
416416

417+
it('--version prints package version and exits 0', () => {
418+
const pkg = JSON.parse(require('fs').readFileSync(join(ROOT, 'package.json'), 'utf8'));
419+
const result = runCli(['--version']);
420+
421+
assert.equal(result.status, 0, result.stdout + result.stderr);
422+
assert.equal(result.stdout.trim(), pkg.version);
423+
});
424+
417425
it('--validate blocks on adjacent pipes', () => {
418426
const file = 'test/fixtures/violations/table-adjacent-pipes.md';
419427

test/unit/format-content.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,15 @@ describe('format-content micro-formatter', () => {
158158
assert.doesNotMatch(result, /\r\n/, 'CRLF should be converted to LF');
159159
assert.match(result, /\n$/, 'should end with LF newline');
160160
});
161+
162+
it('handles empty string and whitespace-only input', () => {
163+
// Empty string becomes final newline only
164+
assert.equal(formatContent(''), '\n');
165+
// 2+ trailing spaces preserved as hard line breaks
166+
assert.equal(formatContent(' \n \n'), ' \n \n');
167+
// Multiple blank lines preserved (no trailing whitespace to strip)
168+
assert.equal(formatContent('\n\n\n'), '\n\n\n');
169+
// Single line with only spaces: trailing spaces preserved, final newline added
170+
assert.equal(formatContent(' '), ' \n');
171+
});
161172
});

test/unit/formatter.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ describe('formatter CLI helper unit tests', () => {
4848
assert.deepStrictEqual(args._, []);
4949
});
5050

51+
it('parses --version as a read-only flag', () => {
52+
const args = parseArgs(['node', 'index.js', '--version']);
53+
54+
assert.equal(args.version, true);
55+
assert.deepStrictEqual(args._, []);
56+
});
57+
5158
it('reports runtime readiness from --doctor checks', () => {
5259
const { result, output } = collectDoctor();
5360

0 commit comments

Comments
 (0)