-
Notifications
You must be signed in to change notification settings - Fork 0
Cleanup refactoring #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5d42ebd
Refactor rendering and validation result handling
Coderrob 879b389
refactor: reorganize imports and update type definitions across multi…
Coderrob 50326ef
fix: import isObject from type.helper for improved type checking
Coderrob 8347839
fix: update task summary reference to use task title for changelog entry
Coderrob e8e3549
Update src/core/storage/task.manager.ts
Coderrob ed32658
Update src/commands/task-management/complete-task.command.ts
Coderrob d3db978
Update src/core/rendering/console-output.writer.ts
Coderrob e17f55b
feat: enhance task fixing functionality with TaskFixResult interface …
Coderrob 8e5ce9d
feat: update writeFormatted method to use OutputFormat enum for bette…
Coderrob 8c7ad19
feat: add validate and fix command for task management
Coderrob 16b8fe1
Refactor command names to use CommandName enum
Coderrob 824d65d
fix: update chalk mock to use Object.assign for better compatibility
Coderrob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ dist | |
| .docusaurus | ||
| .coverage | ||
| test/validator.test.js | ||
| __mocks__ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| const chalk = Object.assign((text) => text, { | ||
| green: (text) => text, | ||
| red: (text) => text, | ||
| yellow: (text) => text, | ||
| blue: (text) => text, | ||
| cyan: (text) => text, | ||
| magenta: (text) => text, | ||
| white: (text) => text, | ||
| black: (text) => text, | ||
| gray: (text) => text, | ||
| grey: (text) => text, | ||
| redBright: (text) => text, | ||
| greenBright: (text) => text, | ||
| yellowBright: (text) => text, | ||
| blueBright: (text) => text, | ||
| magentaBright: (text) => text, | ||
| cyanBright: (text) => text, | ||
| whiteBright: (text) => text, | ||
| bgRed: (text) => text, | ||
| bgGreen: (text) => text, | ||
| bgYellow: (text) => text, | ||
| bgBlue: (text) => text, | ||
| bgMagenta: (text) => text, | ||
| bgCyan: (text) => text, | ||
| bgWhite: (text) => text, | ||
| bgBlack: (text) => text, | ||
| bgRedBright: (text) => text, | ||
| bgGreenBright: (text) => text, | ||
| bgYellowBright: (text) => text, | ||
| bgBlueBright: (text) => text, | ||
| bgMagentaBright: (text) => text, | ||
| bgCyanBright: (text) => text, | ||
| bgWhiteBright: (text) => text, | ||
| bold: (text) => text, | ||
| dim: (text) => text, | ||
| italic: (text) => text, | ||
| underline: (text) => text, | ||
| inverse: (text) => text, | ||
| strikethrough: (text) => text, | ||
| reset: (text) => text, | ||
| }); | ||
|
|
||
| module.exports = chalk; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Code Quality Standards | ||
|
|
||
| ## Architectural Rules | ||
|
|
||
| ### Index File Encapsulation | ||
|
|
||
| **NEVER** allow index files to export from outside their directory tree. | ||
|
|
||
| **❌ WRONG - Breaks encapsulation:** | ||
|
|
||
| ```typescript | ||
| // src/types/rendering/index.ts | ||
| export * from './IRenderer'; | ||
| export * from './OutputFormat'; | ||
| export { ConsoleOutputWriter } from '../../core/rendering/console-output.writer'; // ❌ BAD | ||
| ``` | ||
|
|
||
| **✅ CORRECT - Maintains encapsulation:** | ||
|
|
||
| ```typescript | ||
| // src/types/rendering/index.ts | ||
| export * from './IRenderer'; | ||
| export * from './OutputFormat'; | ||
|
|
||
| // Add exports to the appropriate domain index file instead: | ||
| // src/core/rendering/index.ts | ||
| export { ConsoleOutputWriter } from './console-output.writer'; | ||
| ``` | ||
|
|
||
| **Rationale:** | ||
|
|
||
| - Maintains clear module boundaries and encapsulation | ||
| - Prevents circular dependencies | ||
| - Makes dependencies explicit and traceable | ||
| - Follows domain-driven design principles | ||
| - Improves maintainability and refactoring safety | ||
|
|
||
| **Enforcement:** | ||
|
|
||
| - Code reviews must flag any index file reaching outside its directory | ||
| - Automated linting rules should be added to prevent this pattern | ||
| - Refactoring should move cross-domain exports to appropriate domain boundaries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import { Command } from 'commander'; | ||
|
|
||
| import { TaskManager } from '../core/storage'; | ||
| import { AddTaskArgs, CommandName, EXIT_CODES, ILogger, IOutputWriter } from '../types'; | ||
|
|
||
| import { AddTaskCommand } from './add-task.command'; | ||
|
|
||
| // Mock dependencies | ||
| jest.mock('../core/storage'); | ||
| jest.mock('commander'); | ||
|
|
||
| describe('AddTaskCommand', () => { | ||
| let logger: jest.Mocked<ILogger>; | ||
| let outputWriter: jest.Mocked<IOutputWriter>; | ||
| let command: AddTaskCommand; | ||
| let mockTaskManager: jest.Mocked<TaskManager>; | ||
|
|
||
| beforeEach(() => { | ||
| logger = { | ||
| info: jest.fn(), | ||
| error: jest.fn(), | ||
| warn: jest.fn(), | ||
| debug: jest.fn(), | ||
| child: jest.fn(), | ||
| } as jest.Mocked<ILogger>; | ||
|
|
||
| outputWriter = { | ||
| info: jest.fn(), | ||
| error: jest.fn(), | ||
| success: jest.fn(), | ||
| warning: jest.fn(), | ||
| write: jest.fn(), | ||
| newline: jest.fn(), | ||
| writeFormatted: jest.fn(), | ||
| section: jest.fn(), | ||
| keyValue: jest.fn(), | ||
| } as jest.Mocked<IOutputWriter>; | ||
|
|
||
| mockTaskManager = { | ||
| addTaskFromFile: jest.fn(), | ||
| } as unknown as jest.Mocked<TaskManager>; | ||
|
|
||
| // Mock the TaskManager constructor | ||
| (TaskManager as jest.MockedClass<typeof TaskManager>).mockImplementation(() => mockTaskManager); | ||
|
|
||
| command = new AddTaskCommand(logger, outputWriter); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('execute', () => { | ||
| const args: AddTaskArgs = { file: 'test-task.md' }; | ||
|
|
||
| it('should handle successful task addition', async () => { | ||
| mockTaskManager.addTaskFromFile.mockReturnValue(true); | ||
|
|
||
| await command.execute(args); | ||
|
|
||
| expect(mockTaskManager.addTaskFromFile).toHaveBeenCalledWith(args.file); | ||
| expect(outputWriter.success).toHaveBeenCalledWith(`Task added to TODO.md from ${args.file}`); | ||
| expect(logger.info).toHaveBeenCalledWith('Task added successfully', { file: args.file }); | ||
| expect(process.exitCode).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should handle failed task addition', async () => { | ||
| mockTaskManager.addTaskFromFile.mockReturnValue(false); | ||
|
|
||
| await command.execute(args); | ||
|
|
||
| expect(mockTaskManager.addTaskFromFile).toHaveBeenCalledWith(args.file); | ||
| expect(logger.error).toHaveBeenCalledWith(`Failed to add task from ${args.file}`, { | ||
| file: args.file, | ||
| }); | ||
| expect(process.exitCode).toBe(EXIT_CODES.GENERAL_ERROR); | ||
| }); | ||
|
|
||
| it('should handle errors during task addition', async () => { | ||
| const error = new Error('File not found'); | ||
| const mockImplementation = () => { | ||
| throw error; | ||
| }; | ||
| mockTaskManager.addTaskFromFile.mockImplementation(mockImplementation); | ||
|
|
||
| await command.execute(args); | ||
|
|
||
| expect(mockTaskManager.addTaskFromFile).toHaveBeenCalledWith(args.file); | ||
| expect(logger.error).toHaveBeenCalledWith(`Error adding task: ${error.message}`, { | ||
| error: error.message, | ||
| file: args.file, | ||
| }); | ||
| expect(process.exitCode).toBe(EXIT_CODES.NOT_FOUND); | ||
| }); | ||
|
|
||
| it('should handle unknown errors during task addition', async () => { | ||
| const error = 'Unknown error'; | ||
| const mockImplementation = () => { | ||
| throw error; | ||
| }; | ||
| mockTaskManager.addTaskFromFile.mockImplementation(mockImplementation); | ||
|
|
||
| await command.execute(args); | ||
|
|
||
| expect(mockTaskManager.addTaskFromFile).toHaveBeenCalledWith(args.file); | ||
| expect(logger.error).toHaveBeenCalledWith(`Error adding task: ${error}`, { | ||
| error: error, | ||
| file: args.file, | ||
| }); | ||
| expect(process.exitCode).toBe(EXIT_CODES.NOT_FOUND); | ||
| }); | ||
| }); | ||
|
|
||
| describe('configure', () => { | ||
| it('should configure the command with Commander.js', () => { | ||
| const parent = { | ||
| command: jest.fn().mockReturnValue({ | ||
| argument: jest.fn().mockReturnThis(), | ||
| description: jest.fn().mockReturnThis(), | ||
| action: jest.fn().mockReturnThis(), | ||
| }), | ||
| } as unknown as Command; | ||
|
|
||
| AddTaskCommand.configure(parent, logger, outputWriter); | ||
|
|
||
| expect(parent.command).toHaveBeenCalledWith(CommandName.ADD); | ||
| // Additional assertions can be added if needed for argument and action setup | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.