@zgeoff/format-codemod 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -50,10 +50,11 @@ no "never" rules.
50
50
  ```bash
51
51
  format-codemod [options] <file|dir|glob> ...
52
52
 
53
- --check exit 1 if any file would change; do not write
54
- --dry print unified diff to stdout; do not write
55
- --bench print parse stats as JSON to stderr
56
- --quiet only print files that would change
53
+ --check exit 1 if any file would change; do not write
54
+ --dry print unified diff to stdout; do not write
55
+ --bench print parse stats as JSON to stderr
56
+ --quiet only print files that would change
57
+ --ignore <glob> skip files matching the glob (repeatable)
57
58
  --version
58
59
  --help
59
60
  ```
@@ -79,6 +80,24 @@ file is processed once.
79
80
  `--dry` prints a real unified diff — `@@` hunk headers with three lines of context — that applies
80
81
  cleanly with `patch(1)`.
81
82
 
83
+ ### Ignoring files
84
+
85
+ A `.formatignore` file in the working directory supplies ignore globs without bloating the command
86
+ line — one per line, with blank lines and `#`-prefixed comment lines skipped:
87
+
88
+ ```gitignore
89
+ # committed codegen
90
+ src/generated/**
91
+
92
+ # build output
93
+ dist/**
94
+ ```
95
+
96
+ Each line uses the same glob semantics as `--ignore` (Node's `path.matchesGlob`, tried against both
97
+ the expanded path and the path relative to the working directory). It is not a gitignore dialect:
98
+ `!` negation and directory-anchoring rules are not supported. `--ignore` flags remain available and
99
+ merge additively with the file's globs.
100
+
82
101
  ## Dialect handling
83
102
 
84
103
  The filename picks the parse dialect: `.tsx` enables JSX, everything else parses as plain
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Reads `.formatignore` from the given directory: one glob per line, blank
3
+ * lines and `#`-prefixed comment lines skipped. Lines share --ignore's glob
4
+ * semantics — this is not a gitignore dialect, so `!` negation and directory
5
+ * anchoring don't apply. A missing file yields an empty list, so callers
6
+ * merge unconditionally.
7
+ */
8
+ export declare function loadFormatIgnore(dir: string): readonly string[];
package/dist/cli.js CHANGED
@@ -49,6 +49,18 @@ function isIgnored(file, patterns) {
49
49
  return patterns.some((pattern) => path.matchesGlob(file, pattern) || path.matchesGlob(relative, pattern));
50
50
  }
51
51
 
52
+ // src/cli/load-format-ignore.ts
53
+ import fs2 from "node:fs";
54
+ import path2 from "node:path";
55
+ function loadFormatIgnore(dir) {
56
+ const file = path2.join(dir, ".formatignore");
57
+ if (!fs2.existsSync(file)) {
58
+ return [];
59
+ }
60
+ return fs2.readFileSync(file, "utf8").split(`
61
+ `).map((line) => line.trim()).filter((line) => line.length > 0 && !line.startsWith("#"));
62
+ }
63
+
52
64
  // src/cli/parse-cli-args.ts
53
65
  import { parseArgs } from "node:util";
54
66
  function parseCLIArgs(argv) {
@@ -103,6 +115,11 @@ options:
103
115
  --version
104
116
  --help
105
117
 
118
+ files:
119
+ .formatignore read from the working directory when present: one glob per
120
+ line, blank lines and # comments skipped, merged with
121
+ --ignore
122
+
106
123
  exit codes:
107
124
  0 clean
108
125
  1 files would change (--check)
@@ -133,9 +150,9 @@ function printReport(file, report, quiet) {
133
150
  }
134
151
 
135
152
  // src/cli/read-package-version.ts
136
- import fs2 from "node:fs";
153
+ import fs3 from "node:fs";
137
154
  function readPackageVersion(pkgPath) {
138
- const parsed = JSON.parse(fs2.readFileSync(pkgPath, "utf8"));
155
+ const parsed = JSON.parse(fs3.readFileSync(pkgPath, "utf8"));
139
156
  if (!isPackageJSON(parsed)) {
140
157
  throw new TypeError("Invalid package.json");
141
158
  }
@@ -146,7 +163,7 @@ function isPackageJSON(value) {
146
163
  }
147
164
 
148
165
  // src/cli/check-file.ts
149
- import fs4 from "node:fs";
166
+ import fs5 from "node:fs";
150
167
 
151
168
  // src/transform/apply-edits.ts
152
169
  function applyEdits(src, edits) {
@@ -478,7 +495,7 @@ function transform(src, options) {
478
495
  }
479
496
 
480
497
  // src/cli/apply-diff-mode.ts
481
- import fs3 from "node:fs";
498
+ import fs4 from "node:fs";
482
499
 
483
500
  // src/cli/build-unified-diff.ts
484
501
  function buildUnifiedDiff(before, after, label) {
@@ -642,13 +659,13 @@ function applyDiffMode(edit, mode) {
642
659
  if (mode === "dry") {
643
660
  return { message: null, stdout: buildUnifiedDiff(edit.src, edit.result.output, edit.file) };
644
661
  }
645
- fs3.writeFileSync(edit.file, edit.result.output);
662
+ fs4.writeFileSync(edit.file, edit.result.output);
646
663
  return { message: `WROTE ${edit.file} ${edit.result.edits} edit(s)`, stdout: null };
647
664
  }
648
665
 
649
666
  // src/cli/check-file.ts
650
667
  function checkFile(file, mode) {
651
- const src = fs4.readFileSync(file, "utf8");
668
+ const src = fs5.readFileSync(file, "utf8");
652
669
  const bytes = Buffer.byteLength(src);
653
670
  const result = transform(src, { filename: file });
654
671
  if (result.parseError !== null) {
@@ -701,7 +718,8 @@ if (parsedArgs.version) {
701
718
  process.exit(0);
702
719
  }
703
720
  var t0 = Date.now();
704
- var files = await expandInputs(inputs, parsedArgs.ignore);
721
+ var ignore = [...loadFormatIgnore(process.cwd()), ...parsedArgs.ignore];
722
+ var files = await expandInputs(inputs, ignore);
705
723
  if (files.length === 0) {
706
724
  console.error("no files matched");
707
725
  process.exit(2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/format-codemod",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Enforce blank-line padding conventions in TypeScript via a fast text-splice codemod",
5
5
  "license": "MIT",
6
6
  "repository": {