chore: formatting

This commit is contained in:
Eyal Toledano
2025-05-28 10:25:39 -04:00
parent f9b89dc25c
commit 78397fe0be

View File

@@ -1,7 +1,7 @@
import path from "path";
import { log, readJSON, writeJSON } from "../utils.js";
import { isTaskDependentOn } from "../task-manager.js";
import generateTaskFiles from "./generate-task-files.js";
import path from 'path';
import { log, readJSON, writeJSON } from '../utils.js';
import { isTaskDependentOn } from '../task-manager.js';
import generateTaskFiles from './generate-task-files.js';
/**
* Move one or more tasks/subtasks to new positions
@@ -18,8 +18,8 @@ async function moveTask(
generateFiles = true
) {
// Check if we have comma-separated IDs (multiple moves)
const sourceIds = sourceId.split(",").map((id) => id.trim());
const destinationIds = destinationId.split(",").map((id) => id.trim());
const sourceIds = sourceId.split(',').map((id) => id.trim());
const destinationIds = destinationId.split(',').map((id) => id.trim());
// If multiple IDs, validate they match in count
if (sourceIds.length > 1 || destinationIds.length > 1) {
@@ -63,8 +63,8 @@ async function moveMultipleTasks(
) {
try {
log(
"info",
`Moving multiple tasks/subtasks: ${sourceIds.join(", ")} to ${destinationIds.join(", ")}...`
'info',
`Moving multiple tasks/subtasks: ${sourceIds.join(', ')} to ${destinationIds.join(', ')}...`
);
const results = [];
@@ -82,16 +82,16 @@ async function moveMultipleTasks(
// Generate task files once at the end if requested
if (generateFiles) {
log("info", "Regenerating task files...");
log('info', 'Regenerating task files...');
await generateTaskFiles(tasksPath, path.dirname(tasksPath));
}
return {
message: `Successfully moved ${sourceIds.length} tasks/subtasks`,
moves: results,
moves: results
};
} catch (error) {
log("error", `Error moving multiple tasks/subtasks: ${error.message}`);
log('error', `Error moving multiple tasks/subtasks: ${error.message}`);
throw error;
}
}
@@ -111,7 +111,7 @@ async function moveSingleTask(
generateFiles = true
) {
try {
log("info", `Moving task/subtask ${sourceId} to ${destinationId}...`);
log('info', `Moving task/subtask ${sourceId} to ${destinationId}...`);
// Read the existing tasks
const data = readJSON(tasksPath);
@@ -120,7 +120,7 @@ async function moveSingleTask(
}
// Parse source ID to determine if it's a task or subtask
const isSourceSubtask = sourceId.includes(".");
const isSourceSubtask = sourceId.includes('.');
let sourceTask,
sourceParentTask,
sourceSubtask,
@@ -128,13 +128,13 @@ async function moveSingleTask(
sourceSubtaskIndex;
// Parse destination ID to determine the target
const isDestinationSubtask = destinationId.includes(".");
const isDestinationSubtask = destinationId.includes('.');
let destTask, destParentTask, destSubtask, destTaskIndex, destSubtaskIndex;
// Validate source exists
if (isSourceSubtask) {
// Source is a subtask
const [parentIdStr, subtaskIdStr] = sourceId.split(".");
const [parentIdStr, subtaskIdStr] = sourceId.split('.');
const parentIdNum = parseInt(parentIdStr, 10);
const subtaskIdNum = parseInt(subtaskIdStr, 10);
@@ -172,7 +172,7 @@ async function moveSingleTask(
// Validate destination exists
if (isDestinationSubtask) {
// Destination is a subtask (target will be the parent of this subtask)
const [parentIdStr, subtaskIdStr] = destinationId.split(".");
const [parentIdStr, subtaskIdStr] = destinationId.split('.');
const parentIdNum = parseInt(parentIdStr, 10);
const subtaskIdNum = parseInt(subtaskIdStr, 10);
@@ -210,15 +210,15 @@ async function moveSingleTask(
if (destTaskIndex === -1) {
// Create placeholder for destination if it doesn't exist
log("info", `Creating placeholder for destination task ${destIdNum}`);
log('info', `Creating placeholder for destination task ${destIdNum}`);
const newTask = {
id: destIdNum,
title: `Task ${destIdNum}`,
description: "",
status: "pending",
priority: "medium",
details: "",
testStrategy: "",
description: '',
status: 'pending',
priority: 'medium',
details: '',
testStrategy: ''
};
// Find correct position to insert the new task
@@ -241,14 +241,14 @@ async function moveSingleTask(
// Validate that we aren't trying to move a task to itself
if (sourceId === destinationId) {
throw new Error("Cannot move a task/subtask to itself");
throw new Error('Cannot move a task/subtask to itself');
}
// Prevent moving a parent to its own subtask
if (!isSourceSubtask && isDestinationSubtask) {
const destParentId = parseInt(destinationId.split(".")[0], 10);
const destParentId = parseInt(destinationId.split('.')[0], 10);
if (parseInt(sourceId, 10) === destParentId) {
throw new Error("Cannot move a parent task to one of its own subtasks");
throw new Error('Cannot move a parent task to one of its own subtasks');
}
}
@@ -300,8 +300,8 @@ async function moveSingleTask(
} else if (isSourceSubtask && isDestinationSubtask) {
// Case 4: Move subtask to another parent or position
// First check if it's the same parent
const sourceParentId = parseInt(sourceId.split(".")[0], 10);
const destParentId = parseInt(destinationId.split(".")[0], 10);
const sourceParentId = parseInt(sourceId.split('.')[0], 10);
const destParentId = parseInt(destinationId.split('.')[0], 10);
if (sourceParentId === destParentId) {
// Case 4a: Move subtask within the same parent (reordering)
@@ -327,13 +327,13 @@ async function moveSingleTask(
// Generate task files if requested
if (generateFiles) {
log("info", "Regenerating task files...");
log('info', 'Regenerating task files...');
await generateTaskFiles(tasksPath, path.dirname(tasksPath));
}
return movedTask;
} catch (error) {
log("error", `Error moving task/subtask: ${error.message}`);
log('error', `Error moving task/subtask: ${error.message}`);
throw error;
}
}
@@ -363,7 +363,7 @@ function moveTaskToTask(data, sourceTask, sourceTaskIndex, destTask) {
const newSubtask = {
...sourceTask,
id: newSubtaskId,
parentTaskId: destTask.id,
parentTaskId: destTask.id
};
// Add to destination's subtasks
@@ -373,7 +373,7 @@ function moveTaskToTask(data, sourceTask, sourceTaskIndex, destTask) {
data.tasks.splice(sourceTaskIndex, 1);
log(
"info",
'info',
`Moved task ${sourceTask.id} to become subtask ${destTask.id}.${newSubtaskId}`
);
@@ -412,7 +412,7 @@ function moveTaskToSubtaskPosition(
const newSubtask = {
...sourceTask,
id: newSubtaskId,
parentTaskId: destParentTask.id,
parentTaskId: destParentTask.id
};
// Insert at specific position
@@ -425,7 +425,7 @@ function moveTaskToSubtaskPosition(
data.tasks.splice(sourceTaskIndex, 1);
log(
"info",
'info',
`Moved task ${sourceTask.id} to become subtask ${destParentTask.id}.${newSubtaskId}`
);
@@ -456,7 +456,7 @@ function moveSubtaskToTask(
const newTask = {
...sourceSubtask,
id: newTaskId,
priority: sourceParentTask.priority || "medium", // Inherit priority from parent
priority: sourceParentTask.priority || 'medium' // Inherit priority from parent
};
delete newTask.parentTaskId;
@@ -483,7 +483,7 @@ function moveSubtaskToTask(
}
log(
"info",
'info',
`Moved subtask ${sourceParentTask.id}.${sourceSubtask.id} to become task ${newTaskId}`
);
@@ -510,7 +510,7 @@ function reorderSubtask(parentTask, sourceIndex, destIndex) {
parentTask.subtasks.splice(adjustedDestIndex, 0, subtask);
log(
"info",
'info',
`Reordered subtask ${parentTask.id}.${subtask.id} within parent task ${parentTask.id}`
);
@@ -544,7 +544,7 @@ function moveSubtaskToAnotherParent(
const newSubtask = {
...sourceSubtask,
id: newSubtaskId,
parentTaskId: destParentTask.id,
parentTaskId: destParentTask.id
};
// If the subtask depends on its original parent, keep that dependency
@@ -570,7 +570,7 @@ function moveSubtaskToAnotherParent(
}
log(
"info",
'info',
`Moved subtask ${sourceParentTask.id}.${sourceSubtask.id} to become subtask ${destParentTask.id}.${newSubtaskId}`
);
@@ -596,7 +596,7 @@ function moveTaskToNewId(
// Create a copy of the source task with the new ID
const movedTask = {
...sourceTask,
id: destTask.id,
id: destTask.id
};
// Get numeric IDs for comparison
@@ -608,7 +608,7 @@ function moveTaskToNewId(
// Update subtasks to reference the new parent ID if needed
movedTask.subtasks = sourceTask.subtasks.map((subtask) => ({
...subtask,
parentTaskId: destIdNum,
parentTaskId: destIdNum
}));
}
@@ -650,7 +650,7 @@ function moveTaskToNewId(
data.tasks.splice(sourceTaskIndex, 0, movedTask);
}
log("info", `Moved task ${sourceIdNum} to replace task ${destIdNum}`);
log('info', `Moved task ${sourceIdNum} to replace task ${destIdNum}`);
return movedTask;
}