Repository: obsidian-tasks-group/obsidian-tasks
Pull request #1124 (2022-09-06 20:49:41)

refactor: Capitalise the names of values in Status
<!--- Provide a general summary of your changes in the Title above -->

# Description

- `Status.Done` -> `Status.DONE`
- `Status.Todo` -> `Status.TODO`

<!--- Describe your changes in detail -->

## Motivation and Context

This is another small move to make the code more consistent with tasks-x, for ease of comparing the code bases.

## How has this been tested?

- running existing tests
- `yarn run lint`

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how -->
<!--- your change affects other areas of the code, etc. -->

## 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)

## 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/CreateOrEdit.ts b/src/Commands/CreateOrEdit.ts
index f27286f1..93e82105 100644
--- a/src/Commands/CreateOrEdit.ts
+++ b/src/Commands/CreateOrEdit.ts
@@ -56,7 +56,7 @@ const taskFromLine = ({ line, path }: { line: string; path: string }): Task => {
         // Should never happen; everything in the regex is optional.
         console.error('Tasks: Cannot create task on line:', line);
         return new Task({
-            status: Status.Todo,
+            status: Status.TODO,
             description: '',
             path,
             indentation: '',
@@ -78,7 +78,7 @@ const taskFromLine = ({ line, path }: { line: string; path: string }): Task => {
 
     const indentation: string = nonTaskMatch[1];
     const statusString: string = nonTaskMatch[3] ?? ' ';
-    const status = statusString === ' ' ? Status.Todo : Status.Done;
+    const status = statusString === ' ' ? Status.TODO : Status.DONE;
     let description: string = nonTaskMatch[4];
 
     const blockLinkMatch = line.match(TaskRegularExpressions.blockLinkRegex);
diff --git a/src/Query/Filter/StatusField.ts b/src/Query/Filter/StatusField.ts
index 083c5e8e..ebc7e83b 100644
--- a/src/Query/Filter/StatusField.ts
+++ b/src/Query/Filter/StatusField.ts
@@ -5,8 +5,8 @@ export class StatusField extends FilterInstructionsBasedField {
     constructor() {
         super();
 
-        this._filters.add('done', (task: Task) => task.status === Status.Done);
-        this._filters.add('not done', (task: Task) => task.status !== Status.Done);
+        this._filters.add('done', (task: Task) => task.status === Status.DONE);
+        this._filters.add('not done', (task: Task) => task.status !== Status.DONE);
     }
 
     public fieldName(): string {
diff --git a/src/Task.ts b/src/Task.ts
index afbe5828..946536d7 100644
--- a/src/Task.ts
+++ b/src/Task.ts
@@ -14,8 +14,8 @@ import { Sort } from './Query/Sort';
  * @enum {number}
  */
 export enum Status {
-    Todo = 'Todo',
-    Done = 'Done',
+    TODO = 'Todo',
+    DONE = 'Done',
 }
 
 /**
@@ -257,10 +257,10 @@ export class Task {
         let status: Status;
         switch (statusString) {
             case ' ':
-                status = Status.Todo;
+                status = Status.TODO;
                 break;
             default:
-                status = Status.Done;
+                status = Status.DONE;
         }
 
         // Match for block link and remove if found. Always expected to be
@@ -465,7 +465,7 @@ export class Task {
         const checkbox = li.createEl('input');
         checkbox.addClass('task-list-item-checkbox');
         checkbox.type = 'checkbox';
-        if (this.status !== Status.Todo) {
+        if (this.status !== Status.TODO) {
             checkbox.checked = true;
             li.addClass('is-checked');
         }
@@ -583,7 +583,7 @@ export class Task {
      * task is not recurring, it will return `[toggled]`.
      */
     public toggle(): Task[] {
-        const newStatus: Status = this.status === Status.Todo ? Status.Done : Status.Todo;
+        const newStatus: Status = this.status === Status.TODO ? Status.DONE : Status.TODO;
 
         let newDoneDate = null;
 
@@ -593,7 +593,7 @@ export class Task {
             dueDate: Moment | null;
         } | null = null;
 
-        if (newStatus !== Status.Todo) {
+        if (newStatus !== Status.TODO) {
             // Set done date only if setting value is true
             const { setDoneDate } = getSettings();
             if (setDoneDate) {
@@ -610,7 +610,7 @@ export class Task {
             ...this,
             status: newStatus,
             doneDate: newDoneDate,
-            originalStatusCharacter: newStatus === Status.Done ? 'x' : ' ',
+            originalStatusCharacter: newStatus === Status.DONE ? 'x' : ' ',
         });
 
         const newTasks: Task[] = [];
diff --git a/src/ui/EditTask.svelte b/src/ui/EditTask.svelte
index de41f5ac..bf0c71cc 100644
--- a/src/ui/EditTask.svelte
+++ b/src/ui/EditTask.svelte
@@ -28,7 +28,7 @@
         doneDate: string;
     } = {
         description: '',
-        status: Status.Todo,
+        status: Status.TODO,
         priority: 'none',
         recurrenceRule: '',
         startDate: '',
@@ -306,7 +306,7 @@
                 <input
                     type="checkbox"
                     class="task-list-item-checkbox tasks-modal-checkbox"
-                    checked={editableTask.status === Status.Done}
+                    checked={editableTask.status === Status.DONE}
                     disabled
                 />
                 <code>{editableTask.status}</code>


Test patch:
diff --git a/tests/Query.test.ts b/tests/Query.test.ts
index cf121d38..ccd2de60 100644
--- a/tests/Query.test.ts
+++ b/tests/Query.test.ts
@@ -234,7 +234,7 @@ describe('Query', () => {
             // Arrange
             const tasks = [
                 new Task({
-                    status: Status.Todo,
+                    status: Status.TODO,
                     description: 'description',
                     path: 'Ab/C D',
                     indentation: '',
@@ -252,7 +252,7 @@ describe('Query', () => {
                     tags: [],
                 }),
                 new Task({
-                    status: Status.Todo,
+                    status: Status.TODO,
                     description: 'description',
                     path: 'FF/C D',
                     indentation: '',
diff --git a/tests/Query/Filter/StatusField.test.ts b/tests/Query/Filter/StatusField.test.ts
index 2d4a65b1..30dcfa1f 100644
--- a/tests/Query/Filter/StatusField.test.ts
+++ b/tests/Query/Filter/StatusField.test.ts
@@ -15,8 +15,8 @@ describe('status', () => {
         const filter = new StatusField().createFilterOrErrorMessage('done');
 
         // Assert
-        testStatusFilter(filter, Status.Todo, false);
-        testStatusFilter(filter, Status.Done, true);
+        testStatusFilter(filter, Status.TODO, false);
+        testStatusFilter(filter, Status.DONE, true);
     });
 
     it('not done', () => {
@@ -24,7 +24,7 @@ describe('status', () => {
         const filter = new StatusField().createFilterOrErrorMessage('not done');
 
         // Assert
-        testStatusFilter(filter, Status.Todo, true);
-        testStatusFilter(filter, Status.Done, false);
+        testStatusFilter(filter, Status.TODO, true);
+        testStatusFilter(filter, Status.DONE, false);
     });
 });
diff --git a/tests/Task.test.ts b/tests/Task.test.ts
index 6e41296d..e718dbe9 100644
--- a/tests/Task.test.ts
+++ b/tests/Task.test.ts
@@ -24,7 +24,7 @@ describe('parsing', () => {
         // Assert
         expect(task).not.toBeNull();
         expect(task!.description).toEqual('this is a done task');
-        expect(task!.status).toStrictEqual(Status.Done);
+        expect(task!.status).toStrictEqual(Status.DONE);
         expect(task!.dueDate).not.toBeNull();
         expect(task!.dueDate!.isSame(moment('2021-09-12', 'YYYY-MM-DD'))).toStrictEqual(true);
         expect(task!.doneDate).not.toBeNull();
@@ -60,7 +60,7 @@ describe('parsing', () => {
         // Assert
         expect(task).not.toBeNull();
         expect(task!.description).toEqual('this is a ✅ done task');
-        expect(task!.status).toStrictEqual(Status.Done);
+        expect(task!.status).toStrictEqual(Status.DONE);
         expect(task!.dueDate).not.toBeNull();
         expect(task!.dueDate!.isSame(moment('2021-09-12', 'YYYY-MM-DD'))).toStrictEqual(true);
         expect(task!.doneDate).not.toBeNull();
@@ -79,7 +79,7 @@ describe('parsing', () => {
         // Assert
         expect(task).not.toBeNull();
         expect(task!.description).toEqual('this is a ✅ done task');
-        expect(task!.status).toStrictEqual(Status.Done);
+        expect(task!.status).toStrictEqual(Status.DONE);
         expect(task!.dueDate).not.toBeNull();
         expect(task!.dueDate!.isSame(moment('2021-09-12', 'YYYY-MM-DD'))).toStrictEqual(true);
         expect(task!.doneDate).not.toBeNull();
@@ -400,7 +400,7 @@ describe('toggle done', () => {
 
         // Assert
         expect(toggled).not.toBeNull();
-        expect(toggled!.status).toStrictEqual(Status.Done);
+        expect(toggled!.status).toStrictEqual(Status.DONE);
         expect(toggled!.doneDate).not.toBeNull();
         expect(toggled!.originalStatusCharacter).toStrictEqual('x');
         expect(toggled!.blockLink).toEqual(' ^my-precious');
@@ -418,7 +418,7 @@ describe('toggle done', () => {
 
         // Assert
         expect(toggled).not.toBeNull();
-        expect(toggled!.status).toStrictEqual(Status.Todo);
+        expect(toggled!.status).toStrictEqual(Status.TODO);
         expect(toggled!.originalStatusCharacter).toStrictEqual(' ');
         expect(toggled!.doneDate).toBeNull();
     });
@@ -746,9 +746,9 @@ expect.extend({
 
 describe('identicalTo', () => {
     it('should check status', () => {
-        const lhs = new TaskBuilder().status(Status.Todo);
-        expect(lhs).toBeIdenticalTo(new TaskBuilder().status(Status.Todo));
-        expect(lhs).not.toBeIdenticalTo(new TaskBuilder().status(Status.Done));
+        const lhs = new TaskBuilder().status(Status.TODO);
+        expect(lhs).toBeIdenticalTo(new TaskBuilder().status(Status.TODO));
+        expect(lhs).not.toBeIdenticalTo(new TaskBuilder().status(Status.DONE));
     });
 
     it('should check description', () => {
diff --git a/tests/TestingTools/TaskBuilder.ts b/tests/TestingTools/TaskBuilder.ts
index 6b6f68e9..6721d69f 100644
--- a/tests/TestingTools/TaskBuilder.ts
+++ b/tests/TestingTools/TaskBuilder.ts
@@ -17,7 +17,7 @@ import { DateParser } from '../../src/Query/DateParser';
  *            Create a new TaskBuilder object to start from a clean state,
  */
 export class TaskBuilder {
-    private _status: Status = Status.Todo;
+    private _status: Status = Status.TODO;
     private _description: string = 'my description';
     private _path: string = '';
     private _indentation: string = '';