@zgeoff/format-codemod 0.0.3 → 0.0.4

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/dist/cli.js CHANGED
@@ -53,7 +53,7 @@ function isIgnored(file, patterns) {
53
53
  import { parseArgs } from "node:util";
54
54
  function parseCLIArgs(argv) {
55
55
  try {
56
- const { values, positionals } = parseArgs({
56
+ const parsed = parseArgs({
57
57
  args: [...argv],
58
58
  options: {
59
59
  check: { type: "boolean", default: false },
@@ -68,13 +68,13 @@ function parseCLIArgs(argv) {
68
68
  strict: true
69
69
  });
70
70
  return {
71
- mode: pickMode(values.check, values.dry),
72
- quiet: values.quiet,
73
- bench: values.bench,
74
- help: values.help,
75
- version: values.version,
76
- ignore: values.ignore,
77
- inputs: positionals
71
+ mode: pickMode(parsed.values.check, parsed.values.dry),
72
+ quiet: parsed.values.quiet,
73
+ bench: parsed.values.bench,
74
+ help: parsed.values.help,
75
+ version: parsed.values.version,
76
+ ignore: parsed.values.ignore,
77
+ inputs: parsed.positionals
78
78
  };
79
79
  } catch (error) {
80
80
  return error instanceof Error ? error.message : String(error);
@@ -222,11 +222,11 @@ function getStatementValues(node) {
222
222
  if (node.type === "VariableDeclaration") {
223
223
  return collectASTNodes(node["declarations"]).map((declarator) => declarator["init"]).filter((init) => isASTNode(init));
224
224
  }
225
- const { expression } = node;
225
+ const expression = node["expression"];
226
226
  if (node.type !== "ExpressionStatement" || !isASTNode(expression)) {
227
227
  return [];
228
228
  }
229
- const { right } = expression;
229
+ const right = expression["right"];
230
230
  if (expression.type === "AssignmentExpression" && isASTNode(right)) {
231
231
  return [right];
232
232
  }
@@ -291,7 +291,7 @@ function getStatementKind(node) {
291
291
  return isExpressionStatementOf(node, MUTATION_TYPES) ? "mutation" : null;
292
292
  }
293
293
  function isExpressionStatementOf(node, types) {
294
- const { expression } = node;
294
+ const expression = node["expression"];
295
295
  return node.type === "ExpressionStatement" && isASTNode(expression) && types.includes(expression.type);
296
296
  }
297
297
  var VAR_DECL_KINDS = new Set(["const", "let", "var"]);
@@ -553,10 +553,11 @@ class MyersDiff {
553
553
  return ops.toReversed();
554
554
  }
555
555
  unwindRound(pos, d) {
556
- const { prev, moveDown } = this.findPrevious(pos, d);
556
+ const previous = this.findPrevious(pos, d);
557
+ const prev = previous.prev;
557
558
  const ops = this.buildEqualOps(pos, prev);
558
559
  if (d > 0) {
559
- const changeOp = moveDown ? { kind: "+", text: this.b[prev.y] ?? "" } : { kind: "-", text: this.a[prev.x] ?? "" };
560
+ const changeOp = previous.moveDown ? { kind: "+", text: this.b[prev.y] ?? "" } : { kind: "-", text: this.a[prev.x] ?? "" };
560
561
  ops.push(changeOp);
561
562
  }
562
563
  return { ops, pos: prev };
@@ -571,7 +572,8 @@ class MyersDiff {
571
572
  }
572
573
  buildEqualOps(pos, prev) {
573
574
  const ops = [];
574
- let { x, y } = pos;
575
+ let x = pos.x;
576
+ let y = pos.y;
575
577
  while (x > prev.x && y > prev.y) {
576
578
  ops.push({ kind: " ", text: this.a[x - 1] ?? "" });
577
579
  x--;
@@ -601,12 +603,12 @@ function buildWindows(ops) {
601
603
  return windows;
602
604
  }
603
605
  function buildHunk(ops, w) {
604
- const { aLine, bLine } = countPrecedingLines(ops, w.from);
606
+ const preceding = countPrecedingLines(ops, w.from);
605
607
  const slice = ops.slice(w.from, w.to);
606
608
  const aCount = slice.filter((o) => o.kind !== "+").length;
607
609
  const bCount = slice.filter((o) => o.kind !== "-").length;
608
610
  return {
609
- header: `@@ -${formatRange(aLine, aCount)} +${formatRange(bLine, bCount)} @@
611
+ header: `@@ -${formatRange(preceding.aLine, aCount)} +${formatRange(preceding.bLine, bCount)} @@
610
612
  `,
611
613
  lines: slice.map((o) => `${o.kind}${o.text}
612
614
  `)
@@ -683,20 +685,23 @@ if (typeof parsedArgs === "string") {
683
685
  console.error(parsedArgs);
684
686
  process.exit(2);
685
687
  }
686
- var { mode, quiet, bench, help, version, ignore, inputs } = parsedArgs;
687
- if (help || inputs.length === 0 && !version) {
688
+ var mode = parsedArgs.mode;
689
+ var quiet = parsedArgs.quiet;
690
+ var bench = parsedArgs.bench;
691
+ var inputs = parsedArgs.inputs;
692
+ if (parsedArgs.help || inputs.length === 0 && !parsedArgs.version) {
688
693
  const exitCode = inputs.length === 0 ? 2 : 0;
689
694
  printHelp();
690
695
  process.exit(exitCode);
691
696
  }
692
- if (version) {
697
+ if (parsedArgs.version) {
693
698
  const pkgPath = fileURLToPath(new URL("../package.json", import.meta.url));
694
699
  process.stdout.write(`${readPackageVersion(pkgPath)}
695
700
  `);
696
701
  process.exit(0);
697
702
  }
698
703
  var t0 = Date.now();
699
- var files = await expandInputs(inputs, ignore);
704
+ var files = await expandInputs(inputs, parsedArgs.ignore);
700
705
  if (files.length === 0) {
701
706
  console.error("no files matched");
702
707
  process.exit(2);
package/dist/index.js CHANGED
@@ -72,11 +72,11 @@ function getStatementValues(node) {
72
72
  if (node.type === "VariableDeclaration") {
73
73
  return collectASTNodes(node["declarations"]).map((declarator) => declarator["init"]).filter((init) => isASTNode(init));
74
74
  }
75
- const { expression } = node;
75
+ const expression = node["expression"];
76
76
  if (node.type !== "ExpressionStatement" || !isASTNode(expression)) {
77
77
  return [];
78
78
  }
79
- const { right } = expression;
79
+ const right = expression["right"];
80
80
  if (expression.type === "AssignmentExpression" && isASTNode(right)) {
81
81
  return [right];
82
82
  }
@@ -141,7 +141,7 @@ function getStatementKind(node) {
141
141
  return isExpressionStatementOf(node, MUTATION_TYPES) ? "mutation" : null;
142
142
  }
143
143
  function isExpressionStatementOf(node, types) {
144
- const { expression } = node;
144
+ const expression = node["expression"];
145
145
  return node.type === "ExpressionStatement" && isASTNode(expression) && types.includes(expression.type);
146
146
  }
147
147
  var VAR_DECL_KINDS = new Set(["const", "let", "var"]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgeoff/format-codemod",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Enforce blank-line padding conventions in TypeScript via a fast text-splice codemod",
5
5
  "license": "MIT",
6
6
  "repository": {