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