Repository: obsidian-tasks-group/obsidian-tasks
Pull request #1450 (2023-01-01 13:06:27)

refactor: Move Status class out to its own file
<!--- Provide a general summary of your changes in the Title above -->

# Description

Move Status out to its own file.

## Motivation and Context

Preparation for making Status a class.

## How has this been tested?

Running the tests.

## Screenshots (if appropriate)

## Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

Internal changes:

- [x] **Refactor** (prefix: `refactor` - non-breaking change which only improves the design or structure of existing code, and making no changes to its external behaviour)

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [x] My code follows the code style of this project and passes `yarn run lint`.
- [ ] My change requires a change to the documentation.
- [ ] I have [updated the documentation](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CONTRIBUTING.md#updating-documentation) accordingly.
- [x] My change has adequate [Unit Test coverage](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CONTRIBUTING.md#maintaining-the-tests).

## Terms

<!--
By submitting this pull request, you must agree to follow our
[contributing guide](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CONTRIBUTING.md) and
[Code of Conduct](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CODE_OF_CONDUCT.md).
Put an x in the boxes to confirm you agree.
-->

- [x] My contribution follow this project's [contributing guide](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CONTRIBUTING.md)
- [x] I agree to follow this project's [Code of Conduct](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CODE_OF_CONDUCT.md)



Patch:
diff --git a/src/Commands/CreateOrEditTaskParser.ts b/src/Commands/CreateOrEditTaskParser.ts
index 77c73c3e..6c7108bd 100644
--- a/src/Commands/CreateOrEditTaskParser.ts
+++ b/src/Commands/CreateOrEditTaskParser.ts
@@ -1,4 +1,5 @@
-import { Priority, Status, Task, TaskRegularExpressions } from '../Task';
+import { Status } from '../Status';
+import { Priority, Task, TaskRegularExpressions } from '../Task';
 import { DateFallback } from '../DateFallback';
 
 /**
diff --git a/src/Query/Filter/StatusField.ts b/src/Query/Filter/StatusField.ts
index 85dca098..e55549d5 100644
--- a/src/Query/Filter/StatusField.ts
+++ b/src/Query/Filter/StatusField.ts
@@ -1,4 +1,5 @@
-import { Status, Task } from '../../Task';
+import { Status } from '../../Status';
+import type { Task } from '../../Task';
 import type { Comparator } from '../Sorter';
 import { FilterInstructionsBasedField } from './FilterInstructionsBasedField';
 
diff --git a/src/Status.ts b/src/Status.ts
new file mode 100644
index 00000000..30412e9d
--- /dev/null
+++ b/src/Status.ts
@@ -0,0 +1,10 @@
+/**
+ * Collection of status types supported by the plugin.
+ * TODO: Make this a class so it can support other types and easier mapping to status character.
+ * @export
+ * @enum {number}
+ */
+export enum Status {
+    TODO = 'Todo',
+    DONE = 'Done',
+}
diff --git a/src/Task.ts b/src/Task.ts
index 891e9488..d9204e8d 100644
--- a/src/Task.ts
+++ b/src/Task.ts
@@ -3,23 +3,13 @@ import { LayoutOptions, TaskLayout } from './TaskLayout';
 import type { TaskLayoutComponent } from './TaskLayout';
 import { Recurrence } from './Recurrence';
 import { getSettings } from './Config/Settings';
+import { Status } from './Status';
 import { Urgency } from './Urgency';
 import { DateField } from './Query/Filter/DateField';
 import { renderTaskLine } from './TaskLineRenderer';
 import type { TaskLineRenderDetails } from './TaskLineRenderer';
 import { DateFallback } from './DateFallback';
 
-/**
- * Collection of status types supported by the plugin.
- * TODO: Make this a class so it can support other types and easier mapping to status character.
- * @export
- * @enum {number}
- */
-export enum Status {
-    TODO = 'Todo',
-    DONE = 'Done',
-}
-
 /**
  * When sorting, make sure low always comes after none. This way any tasks with low will be below any exiting
  * tasks that have no priority which would be the default.
diff --git a/src/TaskLineRenderer.ts b/src/TaskLineRenderer.ts
index 5e195590..4d0369a5 100644
--- a/src/TaskLineRenderer.ts
+++ b/src/TaskLineRenderer.ts
@@ -1,5 +1,6 @@
 import { Component, MarkdownRenderer } from 'obsidian';
 import type { Moment } from 'moment';
+import { Status } from './Status';
 import type { Task } from './Task';
 import * as taskModule from './Task';
 import type { LayoutOptions, TaskLayoutComponent } from './TaskLayout';
@@ -59,7 +60,7 @@ export async function renderTaskLine(
     li.appendChild(checkbox);
     checkbox.classList.add('task-list-item-checkbox');
     checkbox.type = 'checkbox';
-    if (task.status !== taskModule.Status.TODO) {
+    if (task.status !== Status.TODO) {
         checkbox.checked = true;
         li.classList.add('is-checked');
     }
diff --git a/src/ui/EditTask.svelte b/src/ui/EditTask.svelte
index b73623bd..33bf726e 100644
--- a/src/ui/EditTask.svelte
+++ b/src/ui/EditTask.svelte
@@ -3,7 +3,8 @@
     import { onMount } from 'svelte';
     import { Recurrence } from '../Recurrence';
     import { getSettings } from '../Config/Settings';
-    import { Priority, Status, Task } from '../Task';
+    import { Status } from '../Status';
+    import { Priority, Task } from '../Task';
     import {
         prioritySymbols,
         recurrenceSymbol,


Test patch:
diff --git a/tests/Query.test.ts b/tests/Query.test.ts
index 2887db48..e6aa2432 100644
--- a/tests/Query.test.ts
+++ b/tests/Query.test.ts
@@ -3,7 +3,8 @@
  */
 import moment from 'moment';
 import { Query } from '../src/Query/Query';
-import { Priority, Status, Task } from '../src/Task';
+import { Status } from '../src/Status';
+import { Priority, Task } from '../src/Task';
 import { resetSettings, updateSettings } from '../src/Config/Settings';
 import { createTasksFromMarkdown, fromLine } from './TestHelpers';
 import { shouldSupportFiltering } from './TestingTools/FilterTestHelpers';
diff --git a/tests/Query/Filter/StatusField.test.ts b/tests/Query/Filter/StatusField.test.ts
index 83c6001f..a9139a39 100644
--- a/tests/Query/Filter/StatusField.test.ts
+++ b/tests/Query/Filter/StatusField.test.ts
@@ -2,7 +2,7 @@ import { StatusField } from '../../../src/Query/Filter/StatusField';
 import type { FilterOrErrorMessage } from '../../../src/Query/Filter/Filter';
 import { TaskBuilder } from '../../TestingTools/TaskBuilder';
 import { testFilter } from '../../TestingTools/FilterTestHelpers';
-import { Status } from '../../../src/Task';
+import { Status } from '../../../src/Status';
 import {
     expectTaskComparesAfter,
     expectTaskComparesBefore,
diff --git a/tests/Task.test.ts b/tests/Task.test.ts
index 584e1722..fee3b61b 100644
--- a/tests/Task.test.ts
+++ b/tests/Task.test.ts
@@ -3,7 +3,8 @@
  */
 import moment from 'moment';
 import type { Moment } from 'moment';
-import { Priority, Status, Task } from '../src/Task';
+import { Status } from '../src/Status';
+import { Priority, Task } from '../src/Task';
 import { resetSettings, updateSettings } from '../src/Config/Settings';
 import { fromLine } from './TestHelpers';
 import { TaskBuilder } from './TestingTools/TaskBuilder';
diff --git a/tests/TestingTools/TaskBuilder.test.ts b/tests/TestingTools/TaskBuilder.test.ts
index 0effe29d..9ce45df0 100644
--- a/tests/TestingTools/TaskBuilder.test.ts
+++ b/tests/TestingTools/TaskBuilder.test.ts
@@ -1,4 +1,5 @@
-import { Status, Task } from '../../src/Task';
+import type { Task } from '../../src/Task';
+import { Status } from '../../src/Status';
 import { TaskBuilder } from './TaskBuilder';
 
 export {};
diff --git a/tests/TestingTools/TaskBuilder.ts b/tests/TestingTools/TaskBuilder.ts
index e94085ad..ea5cef5f 100644
--- a/tests/TestingTools/TaskBuilder.ts
+++ b/tests/TestingTools/TaskBuilder.ts
@@ -1,6 +1,7 @@
 // Builder
 import type { Moment } from 'moment';
-import { Priority, Status, Task } from '../../src/Task';
+import { Status } from '../../src/Status';
+import { Priority, Task } from '../../src/Task';
 import type { Recurrence } from '../../src/Recurrence';
 import { DateParser } from '../../src/Query/DateParser';