From 2c0ffebe2f93a8c89311062fb33fe743a0a3cbf8 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:30:43 +0000 Subject: [PATCH 01/31] refactor: - Remove unnecessary initialisation of Query._queryId --- src/Query/Query.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index c0a0aa235c..0e472330dd 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -44,7 +44,7 @@ export class Query implements IQuery { logger = logging.getLogger('tasks.Query'); // Used internally to uniquely log each query execution in the console. - private _queryId: string = ''; + private _queryId: string; private readonly limitRegexp = /^limit (groups )?(to )?(\d+)( tasks?)?/i; From 0e98269c52a386ca600820e72b1ddd0206562520 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:32:13 +0000 Subject: [PATCH 02/31] refactor: . Make some fields in Query readonly - done by SonarLint --- src/Query/Query.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 0e472330dd..f696619b45 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -27,12 +27,12 @@ export class Query implements IQuery { private _limit: number | undefined = undefined; private _taskGroupLimit: number | undefined = undefined; - private _taskLayoutOptions: TaskLayoutOptions = new TaskLayoutOptions(); - private _queryLayoutOptions: QueryLayoutOptions = new QueryLayoutOptions(); - private _filters: Filter[] = []; + private readonly _taskLayoutOptions: TaskLayoutOptions = new TaskLayoutOptions(); + private readonly _queryLayoutOptions: QueryLayoutOptions = new QueryLayoutOptions(); + private readonly _filters: Filter[] = []; private _error: string | undefined = undefined; - private _sorting: Sorter[] = []; - private _grouping: Grouper[] = []; + private readonly _sorting: Sorter[] = []; + private readonly _grouping: Grouper[] = []; private _ignoreGlobalQuery: boolean = false; private readonly hideOptionsRegexp = @@ -44,7 +44,7 @@ export class Query implements IQuery { logger = logging.getLogger('tasks.Query'); // Used internally to uniquely log each query execution in the console. - private _queryId: string; + private readonly _queryId: string; private readonly limitRegexp = /^limit (groups )?(to )?(\d+)( tasks?)?/i; From 53483bda18744f0eff1afcb7672823a9823de64c Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:39:58 +0000 Subject: [PATCH 03/31] comment: Remove incorrect comments - 'show/hide tree' is now released --- src/Layout/QueryLayoutOptions.ts | 2 +- src/Query/Query.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Layout/QueryLayoutOptions.ts b/src/Layout/QueryLayoutOptions.ts index fc1add1bb6..673dbf1de0 100644 --- a/src/Layout/QueryLayoutOptions.ts +++ b/src/Layout/QueryLayoutOptions.ts @@ -9,7 +9,7 @@ export class QueryLayoutOptions { hideBacklinks: boolean = false; hideEditButton: boolean = false; hideUrgency: boolean = true; - hideTree: boolean = true; // WARNING: undocumented, and not yet ready for release. + hideTree: boolean = true; shortMode: boolean = false; explainQuery: boolean = false; } diff --git a/src/Query/Query.ts b/src/Query/Query.ts index f696619b45..cd60d31c59 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -310,7 +310,6 @@ ${statement.explainStatement(' ')} switch (option) { case 'tree': - // WARNING: undocumented, and not yet ready for release. this._queryLayoutOptions.hideTree = hide; break; case 'task count': From ff0de4dca25458c781435a32a7ba6f86ccf6f1e3 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:42:04 +0000 Subject: [PATCH 04/31] refactor: - Use early-return in Query.parseHideOptions() --- src/Query/Query.ts | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index cd60d31c59..4ac39c2da4 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -311,58 +311,58 @@ ${statement.explainStatement(' ')} switch (option) { case 'tree': this._queryLayoutOptions.hideTree = hide; - break; + return; case 'task count': this._queryLayoutOptions.hideTaskCount = hide; - break; + return; case 'backlink': this._queryLayoutOptions.hideBacklinks = hide; - break; + return; case 'postpone button': this._queryLayoutOptions.hidePostponeButton = hide; - break; + return; case 'priority': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); - break; + return; case 'cancelled date': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); - break; + return; case 'created date': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); - break; + return; case 'start date': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); - break; + return; case 'scheduled date': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); - break; + return; case 'due date': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); - break; + return; case 'done date': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); - break; + return; case 'recurrence rule': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); - break; + return; case 'edit button': this._queryLayoutOptions.hideEditButton = hide; - break; + return; case 'urgency': this._queryLayoutOptions.hideUrgency = hide; - break; + return; case 'tags': this._taskLayoutOptions.setTagsVisibility(!hide); - break; + return; case 'id': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); - break; + return; case 'depends on': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); - break; + return; case 'on completion': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); - break; + return; default: this.setError('do not understand hide/show option', new Statement(line, line)); } From 67e6c1f16f0f1b8f2f1f92a8de692dc125213e99 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:45:32 +0000 Subject: [PATCH 05/31] refactor: . Reorder cases in switch statement to group together related ones --- src/Query/Query.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 4ac39c2da4..18ae164474 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -321,6 +321,13 @@ ${statement.explainStatement(' ')} case 'postpone button': this._queryLayoutOptions.hidePostponeButton = hide; return; + case 'edit button': + this._queryLayoutOptions.hideEditButton = hide; + return; + case 'urgency': + this._queryLayoutOptions.hideUrgency = hide; + return; + case 'priority': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); return; @@ -345,12 +352,6 @@ ${statement.explainStatement(' ')} case 'recurrence rule': this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); return; - case 'edit button': - this._queryLayoutOptions.hideEditButton = hide; - return; - case 'urgency': - this._queryLayoutOptions.hideUrgency = hide; - return; case 'tags': this._taskLayoutOptions.setTagsVisibility(!hide); return; From a782dad4d0a82ddc43be0c93aa21aa76cacf8723 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:51:37 +0000 Subject: [PATCH 06/31] test: - Test recognition of show/hide backlinks (plural) --- tests/Query/Query.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Query/Query.test.ts b/tests/Query/Query.test.ts index 8621670414..dcec8bfcda 100644 --- a/tests/Query/Query.test.ts +++ b/tests/Query/Query.test.ts @@ -452,6 +452,7 @@ describe('Query parsing', () => { 'full', 'full mode', 'hide backlink', + 'hide backlinks', 'hide cancelled date', 'hide created date', 'hide depends on', @@ -476,6 +477,7 @@ describe('Query parsing', () => { 'short', 'short mode', 'show backlink', + 'show backlinks', 'show cancelled date', 'show created date', 'show depends on', From d51471ead389fe3e1afe9877572ba444c2f0355e Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:54:22 +0000 Subject: [PATCH 07/31] refactor: . Replace switch with if --- src/Query/Query.ts | 114 ++++++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 18ae164474..a7bd5a280a 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -308,64 +308,62 @@ ${statement.explainStatement(' ')} const hide = hideOptionsMatch[1].toLowerCase() === 'hide'; const option = hideOptionsMatch[2].toLowerCase(); - switch (option) { - case 'tree': - this._queryLayoutOptions.hideTree = hide; - return; - case 'task count': - this._queryLayoutOptions.hideTaskCount = hide; - return; - case 'backlink': - this._queryLayoutOptions.hideBacklinks = hide; - return; - case 'postpone button': - this._queryLayoutOptions.hidePostponeButton = hide; - return; - case 'edit button': - this._queryLayoutOptions.hideEditButton = hide; - return; - case 'urgency': - this._queryLayoutOptions.hideUrgency = hide; - return; - - case 'priority': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); - return; - case 'cancelled date': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); - return; - case 'created date': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); - return; - case 'start date': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); - return; - case 'scheduled date': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); - return; - case 'due date': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); - return; - case 'done date': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); - return; - case 'recurrence rule': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); - return; - case 'tags': - this._taskLayoutOptions.setTagsVisibility(!hide); - return; - case 'id': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); - return; - case 'depends on': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); - return; - case 'on completion': - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); - return; - default: - this.setError('do not understand hide/show option', new Statement(line, line)); + if (option === 'tree') { + this._queryLayoutOptions.hideTree = hide; + return; + } else if (option === 'task count') { + this._queryLayoutOptions.hideTaskCount = hide; + return; + } else if (option === 'backlink') { + this._queryLayoutOptions.hideBacklinks = hide; + return; + } else if (option === 'postpone button') { + this._queryLayoutOptions.hidePostponeButton = hide; + return; + } else if (option === 'edit button') { + this._queryLayoutOptions.hideEditButton = hide; + return; + } else if (option === 'urgency') { + this._queryLayoutOptions.hideUrgency = hide; + return; + } else if (option === 'priority') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); + return; + } else if (option === 'cancelled date') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); + return; + } else if (option === 'created date') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); + return; + } else if (option === 'start date') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); + return; + } else if (option === 'scheduled date') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); + return; + } else if (option === 'due date') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); + return; + } else if (option === 'done date') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); + return; + } else if (option === 'recurrence rule') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); + return; + } else if (option === 'tags') { + this._taskLayoutOptions.setTagsVisibility(!hide); + return; + } else if (option === 'id') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); + return; + } else if (option === 'depends on') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); + return; + } else if (option === 'on completion') { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); + return; + } else { + this.setError('do not understand hide/show option', new Statement(line, line)); } } } From 0bb36825bf0d6e065cbc0e49d45d4523af043d30 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 07:56:22 +0000 Subject: [PATCH 08/31] refactor: . Unwrap else statements --- src/Query/Query.ts | 54 ++++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index a7bd5a280a..6f8cddad45 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -311,60 +311,76 @@ ${statement.explainStatement(' ')} if (option === 'tree') { this._queryLayoutOptions.hideTree = hide; return; - } else if (option === 'task count') { + } + if (option === 'task count') { this._queryLayoutOptions.hideTaskCount = hide; return; - } else if (option === 'backlink') { + } + if (option === 'backlink') { this._queryLayoutOptions.hideBacklinks = hide; return; - } else if (option === 'postpone button') { + } + if (option === 'postpone button') { this._queryLayoutOptions.hidePostponeButton = hide; return; - } else if (option === 'edit button') { + } + if (option === 'edit button') { this._queryLayoutOptions.hideEditButton = hide; return; - } else if (option === 'urgency') { + } + if (option === 'urgency') { this._queryLayoutOptions.hideUrgency = hide; return; - } else if (option === 'priority') { + } + if (option === 'priority') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); return; - } else if (option === 'cancelled date') { + } + if (option === 'cancelled date') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); return; - } else if (option === 'created date') { + } + if (option === 'created date') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); return; - } else if (option === 'start date') { + } + if (option === 'start date') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); return; - } else if (option === 'scheduled date') { + } + if (option === 'scheduled date') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); return; - } else if (option === 'due date') { + } + if (option === 'due date') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); return; - } else if (option === 'done date') { + } + if (option === 'done date') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); return; - } else if (option === 'recurrence rule') { + } + if (option === 'recurrence rule') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); return; - } else if (option === 'tags') { + } + if (option === 'tags') { this._taskLayoutOptions.setTagsVisibility(!hide); return; - } else if (option === 'id') { + } + if (option === 'id') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); return; - } else if (option === 'depends on') { + } + if (option === 'depends on') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); return; - } else if (option === 'on completion') { + } + if (option === 'on completion') { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); return; - } else { - this.setError('do not understand hide/show option', new Statement(line, line)); } + this.setError('do not understand hide/show option', new Statement(line, line)); } } From 1e16bf3f8fe1d05592f6439b48d4136769b3c78a Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:07:11 +0000 Subject: [PATCH 09/31] refactor: Introduce expectedErrorMessage parameter to isInvalidQueryInstruction() --- tests/Query/Query.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Query/Query.test.ts b/tests/Query/Query.test.ts index dcec8bfcda..61a4880c14 100644 --- a/tests/Query/Query.test.ts +++ b/tests/Query/Query.test.ts @@ -84,8 +84,12 @@ function isValidQueryGroup(filter: string) { lowerCaseFilterGaveExpectionInstruction(filter, query.grouping[0].instruction); } -function isInvalidQueryInstruction(getQueryError: (source: string) => string | undefined, source: string) { - expect(getQueryError(source)).toEqual(`do not understand query +function isInvalidQueryInstruction( + getQueryError: (source: string) => string | undefined, + source: string, + expectedErrorMessage: string = 'do not understand query', +) { + expect(getQueryError(source)).toEqual(`${expectedErrorMessage} Problem line: "${source}"`); } From bcdca3319dbcbc18978a5a9c6b86c3eb09ee1168 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:09:41 +0000 Subject: [PATCH 10/31] refactor: - Move optional parameter up to isInvalidQueryInstructionLowerAndUpper() --- tests/Query/Query.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Query/Query.test.ts b/tests/Query/Query.test.ts index 61a4880c14..7f35cb37f2 100644 --- a/tests/Query/Query.test.ts +++ b/tests/Query/Query.test.ts @@ -87,15 +87,16 @@ function isValidQueryGroup(filter: string) { function isInvalidQueryInstruction( getQueryError: (source: string) => string | undefined, source: string, - expectedErrorMessage: string = 'do not understand query', + expectedErrorMessage: string, ) { expect(getQueryError(source)).toEqual(`${expectedErrorMessage} Problem line: "${source}"`); } function isInvalidQueryInstructionLowerAndUpper(getQueryError: (source: string) => string | undefined, source: string) { - isInvalidQueryInstruction(getQueryError, source); - isInvalidQueryInstruction(getQueryError, source.toUpperCase()); + const expectedErrorMessage = 'do not understand query'; + isInvalidQueryInstruction(getQueryError, source, expectedErrorMessage); + isInvalidQueryInstruction(getQueryError, source.toUpperCase(), expectedErrorMessage); } describe('Query parsing', () => { From 415f87909393e3d6a2c71e165cf8ea9d12efea16 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:10:44 +0000 Subject: [PATCH 11/31] refactor: - Add optional expectedErrorMessage to isInvalidQueryInstructionLowerAndUpper() --- tests/Query/Query.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/Query/Query.test.ts b/tests/Query/Query.test.ts index 7f35cb37f2..f51d4b33ff 100644 --- a/tests/Query/Query.test.ts +++ b/tests/Query/Query.test.ts @@ -93,8 +93,11 @@ function isInvalidQueryInstruction( Problem line: "${source}"`); } -function isInvalidQueryInstructionLowerAndUpper(getQueryError: (source: string) => string | undefined, source: string) { - const expectedErrorMessage = 'do not understand query'; +function isInvalidQueryInstructionLowerAndUpper( + getQueryError: (source: string) => string | undefined, + source: string, + expectedErrorMessage: string = 'do not understand query', +) { isInvalidQueryInstruction(getQueryError, source, expectedErrorMessage); isInvalidQueryInstruction(getQueryError, source.toUpperCase(), expectedErrorMessage); } From 86e5628ca7004a55af1646955b444f7992a27f66 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:27:00 +0000 Subject: [PATCH 12/31] test: - Demonstrate that show/hide do not allow extra spaces currently --- tests/Query/Query.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/Query/Query.test.ts b/tests/Query/Query.test.ts index f51d4b33ff..fc3e6a3f25 100644 --- a/tests/Query/Query.test.ts +++ b/tests/Query/Query.test.ts @@ -537,6 +537,20 @@ describe('Query parsing', () => { }); }); + it.failing('should allow spaces between show or hide and a Query option', () => { + // This fails as the regular-expression approach in Query.hideOptionsRegexp does not allow multiple spaces + const query1 = new Query('show tree'); + expect(query1.queryLayoutOptions.hideTree).toBe(false); + expect(query1.error).toBeUndefined(); + }); + + it.failing('should allow spaces between show or hide and a Task option', () => { + // This fails as the regular-expression approach in Query.hideOptionsRegexp does not allow multiple spaces + const query1 = new Query('hide priority'); + expect(query1.taskLayoutOptions.isShown(TaskLayoutComponent.Priority)).toBe(false); + expect(query1.error).toBeUndefined(); + }); + it('should parse ambiguous sort by queries correctly', () => { expect(new Query('sort by status').sorting[0].property).toEqual('status'); expect(new Query('SORT BY STATUS').sorting[0].property).toEqual('status'); From 6ee8017d8cad7050ec8c294a1e3e3be87052d496 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:30:08 +0000 Subject: [PATCH 13/31] refactor: - Simplify addition of new show/hide options, simplifying a RegEx This makes parsing of show/hide instructions a little more relaxed, in that multiple spaces after show/hide are now permitted. --- src/Query/Query.ts | 39 +++++++++++++++++++-------------------- tests/Query/Query.test.ts | 8 +++----- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 6f8cddad45..e210cfb4a2 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -35,8 +35,7 @@ export class Query implements IQuery { private readonly _grouping: Grouper[] = []; private _ignoreGlobalQuery: boolean = false; - private readonly hideOptionsRegexp = - /^(hide|show) (task count|backlink|priority|cancelled date|created date|start date|scheduled date|done date|due date|recurrence rule|edit button|postpone button|urgency|tags|depends on|id|on completion|tree)/i; + private readonly hideOptionsRegexp = /^(hide|show) +(.*)/i; private readonly shortModeRegexp = /^short/i; private readonly fullModeRegexp = /^full/i; private readonly explainQueryRegexp = /^explain/i; @@ -308,75 +307,75 @@ ${statement.explainStatement(' ')} const hide = hideOptionsMatch[1].toLowerCase() === 'hide'; const option = hideOptionsMatch[2].toLowerCase(); - if (option === 'tree') { + if (option.startsWith('tree')) { this._queryLayoutOptions.hideTree = hide; return; } - if (option === 'task count') { + if (option.startsWith('task count')) { this._queryLayoutOptions.hideTaskCount = hide; return; } - if (option === 'backlink') { + if (option.startsWith('backlink')) { this._queryLayoutOptions.hideBacklinks = hide; return; } - if (option === 'postpone button') { + if (option.startsWith('postpone button')) { this._queryLayoutOptions.hidePostponeButton = hide; return; } - if (option === 'edit button') { + if (option.startsWith('edit button')) { this._queryLayoutOptions.hideEditButton = hide; return; } - if (option === 'urgency') { + if (option.startsWith('urgency')) { this._queryLayoutOptions.hideUrgency = hide; return; } - if (option === 'priority') { + if (option.startsWith('priority')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); return; } - if (option === 'cancelled date') { + if (option.startsWith('cancelled date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); return; } - if (option === 'created date') { + if (option.startsWith('created date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); return; } - if (option === 'start date') { + if (option.startsWith('start date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); return; } - if (option === 'scheduled date') { + if (option.startsWith('scheduled date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); return; } - if (option === 'due date') { + if (option.startsWith('due date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); return; } - if (option === 'done date') { + if (option.startsWith('done date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); return; } - if (option === 'recurrence rule') { + if (option.startsWith('recurrence rule')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); return; } - if (option === 'tags') { + if (option.startsWith('tags')) { this._taskLayoutOptions.setTagsVisibility(!hide); return; } - if (option === 'id') { + if (option.startsWith('id')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); return; } - if (option === 'depends on') { + if (option.startsWith('depends on')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); return; } - if (option === 'on completion') { + if (option.startsWith('on completion')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); return; } diff --git a/tests/Query/Query.test.ts b/tests/Query/Query.test.ts index fc3e6a3f25..7c28af63b7 100644 --- a/tests/Query/Query.test.ts +++ b/tests/Query/Query.test.ts @@ -537,15 +537,13 @@ describe('Query parsing', () => { }); }); - it.failing('should allow spaces between show or hide and a Query option', () => { - // This fails as the regular-expression approach in Query.hideOptionsRegexp does not allow multiple spaces + it('should allow spaces between show or hide and a Query option', () => { const query1 = new Query('show tree'); expect(query1.queryLayoutOptions.hideTree).toBe(false); expect(query1.error).toBeUndefined(); }); - it.failing('should allow spaces between show or hide and a Task option', () => { - // This fails as the regular-expression approach in Query.hideOptionsRegexp does not allow multiple spaces + it('should allow spaces between show or hide and a Task option', () => { const query1 = new Query('hide priority'); expect(query1.taskLayoutOptions.isShown(TaskLayoutComponent.Priority)).toBe(false); expect(query1.error).toBeUndefined(); @@ -639,7 +637,7 @@ Problem line: "${source}"`, it('for invalid hide', () => { const source = 'hide nonsense'; - isInvalidQueryInstructionLowerAndUpper(getQueryError, source); + isInvalidQueryInstructionLowerAndUpper(getQueryError, source, 'do not understand hide/show option'); }); it('for unknown instruction', () => { From 265d2b1e1103aec92376b513a1249ced83a711a3 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:33:08 +0000 Subject: [PATCH 14/31] refactor: . flip if/else --- src/Query/Query.ts | 153 +++++++++++++++++++++++---------------------- 1 file changed, 77 insertions(+), 76 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index e210cfb4a2..dddd68f9fb 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -303,84 +303,85 @@ ${statement.explainStatement(' ')} private parseHideOptions(line: string): void { const hideOptionsMatch = line.match(this.hideOptionsRegexp); - if (hideOptionsMatch !== null) { - const hide = hideOptionsMatch[1].toLowerCase() === 'hide'; - const option = hideOptionsMatch[2].toLowerCase(); + if (hideOptionsMatch === null) { + return; + } + const hide = hideOptionsMatch[1].toLowerCase() === 'hide'; + const option = hideOptionsMatch[2].toLowerCase(); - if (option.startsWith('tree')) { - this._queryLayoutOptions.hideTree = hide; - return; - } - if (option.startsWith('task count')) { - this._queryLayoutOptions.hideTaskCount = hide; - return; - } - if (option.startsWith('backlink')) { - this._queryLayoutOptions.hideBacklinks = hide; - return; - } - if (option.startsWith('postpone button')) { - this._queryLayoutOptions.hidePostponeButton = hide; - return; - } - if (option.startsWith('edit button')) { - this._queryLayoutOptions.hideEditButton = hide; - return; - } - if (option.startsWith('urgency')) { - this._queryLayoutOptions.hideUrgency = hide; - return; - } - if (option.startsWith('priority')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); - return; - } - if (option.startsWith('cancelled date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); - return; - } - if (option.startsWith('created date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); - return; - } - if (option.startsWith('start date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); - return; - } - if (option.startsWith('scheduled date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); - return; - } - if (option.startsWith('due date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); - return; - } - if (option.startsWith('done date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); - return; - } - if (option.startsWith('recurrence rule')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); - return; - } - if (option.startsWith('tags')) { - this._taskLayoutOptions.setTagsVisibility(!hide); - return; - } - if (option.startsWith('id')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); - return; - } - if (option.startsWith('depends on')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); - return; - } - if (option.startsWith('on completion')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); - return; - } - this.setError('do not understand hide/show option', new Statement(line, line)); + if (option.startsWith('tree')) { + this._queryLayoutOptions.hideTree = hide; + return; + } + if (option.startsWith('task count')) { + this._queryLayoutOptions.hideTaskCount = hide; + return; + } + if (option.startsWith('backlink')) { + this._queryLayoutOptions.hideBacklinks = hide; + return; + } + if (option.startsWith('postpone button')) { + this._queryLayoutOptions.hidePostponeButton = hide; + return; + } + if (option.startsWith('edit button')) { + this._queryLayoutOptions.hideEditButton = hide; + return; + } + if (option.startsWith('urgency')) { + this._queryLayoutOptions.hideUrgency = hide; + return; + } + if (option.startsWith('priority')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); + return; + } + if (option.startsWith('cancelled date')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); + return; + } + if (option.startsWith('created date')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); + return; + } + if (option.startsWith('start date')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); + return; + } + if (option.startsWith('scheduled date')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); + return; + } + if (option.startsWith('due date')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); + return; + } + if (option.startsWith('done date')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); + return; + } + if (option.startsWith('recurrence rule')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); + return; + } + if (option.startsWith('tags')) { + this._taskLayoutOptions.setTagsVisibility(!hide); + return; + } + if (option.startsWith('id')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); + return; + } + if (option.startsWith('depends on')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); + return; + } + if (option.startsWith('on completion')) { + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); + return; } + this.setError('do not understand hide/show option', new Statement(line, line)); } private parseFilter(line: string, statement: Statement) { From d421f25ea0c4d68b3cee1412b9dc7014d50fa4f5 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:39:59 +0000 Subject: [PATCH 15/31] refactor: - Extract parseTaskShowHideOptions() --- src/Query/Query.ts | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index dddd68f9fb..f1813ef09c 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -333,55 +333,68 @@ ${statement.explainStatement(' ')} this._queryLayoutOptions.hideUrgency = hide; return; } + if (this.parseTaskShowHideOptions(option, hide)) { + return; + } + this.setError('do not understand hide/show option', new Statement(line, line)); + } + + /** + * Parse show/hide options for Task properties + * @param option - must already have been lower-cased + * @param hide + * @return True if the option was recognised, and false otherwise + */ + private parseTaskShowHideOptions(option: string, hide: boolean): boolean { if (option.startsWith('priority')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); - return; + return true; } if (option.startsWith('cancelled date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); - return; + return true; } if (option.startsWith('created date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); - return; + return true; } if (option.startsWith('start date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); - return; + return true; } if (option.startsWith('scheduled date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); - return; + return true; } if (option.startsWith('due date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); - return; + return true; } if (option.startsWith('done date')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); - return; + return true; } if (option.startsWith('recurrence rule')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); - return; + return true; } if (option.startsWith('tags')) { this._taskLayoutOptions.setTagsVisibility(!hide); - return; + return true; } if (option.startsWith('id')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); - return; + return true; } if (option.startsWith('depends on')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); - return; + return true; } if (option.startsWith('on completion')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); - return; + return true; } - this.setError('do not understand hide/show option', new Statement(line, line)); + return false; } private parseFilter(line: string, statement: Statement) { From 88f3c84dc321119c16fc99fbc5e3120ea46a32f5 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:40:49 +0000 Subject: [PATCH 16/31] refactor: . Extract variable visible --- src/Query/Query.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index f1813ef09c..f378a46067 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -346,52 +346,53 @@ ${statement.explainStatement(' ')} * @return True if the option was recognised, and false otherwise */ private parseTaskShowHideOptions(option: string, hide: boolean): boolean { + const visible = !hide; if (option.startsWith('priority')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); return true; } if (option.startsWith('cancelled date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, visible); return true; } if (option.startsWith('created date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, visible); return true; } if (option.startsWith('start date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, visible); return true; } if (option.startsWith('scheduled date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, visible); return true; } if (option.startsWith('due date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, visible); return true; } if (option.startsWith('done date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, visible); return true; } if (option.startsWith('recurrence rule')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, visible); return true; } if (option.startsWith('tags')) { - this._taskLayoutOptions.setTagsVisibility(!hide); + this._taskLayoutOptions.setTagsVisibility(visible); return true; } if (option.startsWith('id')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, visible); return true; } if (option.startsWith('depends on')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, visible); return true; } if (option.startsWith('on completion')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide); + this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, visible); return true; } return false; From 197d6fed0e622783929f7bca0aa70e9537978902 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:43:38 +0000 Subject: [PATCH 17/31] refactor: . Replace hide parameter with visible --- src/Query/Query.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index f378a46067..78e60851b9 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -333,7 +333,7 @@ ${statement.explainStatement(' ')} this._queryLayoutOptions.hideUrgency = hide; return; } - if (this.parseTaskShowHideOptions(option, hide)) { + if (this.parseTaskShowHideOptions(option, !hide)) { return; } this.setError('do not understand hide/show option', new Statement(line, line)); @@ -342,11 +342,10 @@ ${statement.explainStatement(' ')} /** * Parse show/hide options for Task properties * @param option - must already have been lower-cased - * @param hide + * @param visible - whether the option should be shown * @return True if the option was recognised, and false otherwise */ - private parseTaskShowHideOptions(option: string, hide: boolean): boolean { - const visible = !hide; + private parseTaskShowHideOptions(option: string, visible: boolean): boolean { if (option.startsWith('priority')) { this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); return true; From 43b4a228f76ac0fcd70ea10ae6abfa885813b18b Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:47:20 +0000 Subject: [PATCH 18/31] jsdoc: Improve wording --- src/Query/Query.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 78e60851b9..12cfe0651b 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -340,7 +340,7 @@ ${statement.explainStatement(' ')} } /** - * Parse show/hide options for Task properties + * Parse show/hide options for Task layout options * @param option - must already have been lower-cased * @param visible - whether the option should be shown * @return True if the option was recognised, and false otherwise From 105147ca33e04c7347055960dec152860510bc74 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:48:42 +0000 Subject: [PATCH 19/31] refactor: - Extract parseQueryShowHideOptions() --- src/Query/Query.ts | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 12cfe0651b..fa03121056 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -309,34 +309,47 @@ ${statement.explainStatement(' ')} const hide = hideOptionsMatch[1].toLowerCase() === 'hide'; const option = hideOptionsMatch[2].toLowerCase(); + if (this.parseQueryShowHideOptions(option, hide)) { + return; + } + if (this.parseTaskShowHideOptions(option, !hide)) { + return; + } + this.setError('do not understand hide/show option', new Statement(line, line)); + } + + /** + * Parse show/hide options for Query Layout options + * @param option - must already have been lower-cased + * @param hide - whether the option should be hidden + * @return True if the option was recognised, and false otherwise + */ + private parseQueryShowHideOptions(option: string, hide: boolean): boolean { if (option.startsWith('tree')) { this._queryLayoutOptions.hideTree = hide; - return; + return true; } if (option.startsWith('task count')) { this._queryLayoutOptions.hideTaskCount = hide; - return; + return true; } if (option.startsWith('backlink')) { this._queryLayoutOptions.hideBacklinks = hide; - return; + return true; } if (option.startsWith('postpone button')) { this._queryLayoutOptions.hidePostponeButton = hide; - return; + return true; } if (option.startsWith('edit button')) { this._queryLayoutOptions.hideEditButton = hide; - return; + return true; } if (option.startsWith('urgency')) { this._queryLayoutOptions.hideUrgency = hide; - return; - } - if (this.parseTaskShowHideOptions(option, !hide)) { - return; + return true; } - this.setError('do not understand hide/show option', new Statement(line, line)); + return false; } /** From 991978e4caa9c88a421a7570445e01ddb5c5edde Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:50:15 +0000 Subject: [PATCH 20/31] refactor: . Extract queryLayoutOptions --- src/Query/Query.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index fa03121056..36ff57bb50 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -325,28 +325,29 @@ ${statement.explainStatement(' ')} * @return True if the option was recognised, and false otherwise */ private parseQueryShowHideOptions(option: string, hide: boolean): boolean { + const queryLayoutOptions = this._queryLayoutOptions; if (option.startsWith('tree')) { - this._queryLayoutOptions.hideTree = hide; + queryLayoutOptions.hideTree = hide; return true; } if (option.startsWith('task count')) { - this._queryLayoutOptions.hideTaskCount = hide; + queryLayoutOptions.hideTaskCount = hide; return true; } if (option.startsWith('backlink')) { - this._queryLayoutOptions.hideBacklinks = hide; + queryLayoutOptions.hideBacklinks = hide; return true; } if (option.startsWith('postpone button')) { - this._queryLayoutOptions.hidePostponeButton = hide; + queryLayoutOptions.hidePostponeButton = hide; return true; } if (option.startsWith('edit button')) { - this._queryLayoutOptions.hideEditButton = hide; + queryLayoutOptions.hideEditButton = hide; return true; } if (option.startsWith('urgency')) { - this._queryLayoutOptions.hideUrgency = hide; + queryLayoutOptions.hideUrgency = hide; return true; } return false; From 648997b1b991a95e422e7d92e7d4f4764e92e543 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:55:51 +0000 Subject: [PATCH 21/31] refactor: . Extract parseQueryShowHideOptions() --- src/Query/Query.ts | 54 +++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 36ff57bb50..075f6d9c7e 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -20,6 +20,34 @@ import { Sort } from './Sort/Sort'; import type { Sorter } from './Sort/Sorter'; import { Statement } from './Statement'; +function parseQueryShowHideOptions(queryLayoutOptions: QueryLayoutOptions, option: string, hide: boolean) { + if (option.startsWith('tree')) { + queryLayoutOptions.hideTree = hide; + return true; + } + if (option.startsWith('task count')) { + queryLayoutOptions.hideTaskCount = hide; + return true; + } + if (option.startsWith('backlink')) { + queryLayoutOptions.hideBacklinks = hide; + return true; + } + if (option.startsWith('postpone button')) { + queryLayoutOptions.hidePostponeButton = hide; + return true; + } + if (option.startsWith('edit button')) { + queryLayoutOptions.hideEditButton = hide; + return true; + } + if (option.startsWith('urgency')) { + queryLayoutOptions.hideUrgency = hide; + return true; + } + return false; +} + export class Query implements IQuery { /** Note: source is the raw source, before expanding any placeholders */ public readonly source: string; @@ -326,31 +354,7 @@ ${statement.explainStatement(' ')} */ private parseQueryShowHideOptions(option: string, hide: boolean): boolean { const queryLayoutOptions = this._queryLayoutOptions; - if (option.startsWith('tree')) { - queryLayoutOptions.hideTree = hide; - return true; - } - if (option.startsWith('task count')) { - queryLayoutOptions.hideTaskCount = hide; - return true; - } - if (option.startsWith('backlink')) { - queryLayoutOptions.hideBacklinks = hide; - return true; - } - if (option.startsWith('postpone button')) { - queryLayoutOptions.hidePostponeButton = hide; - return true; - } - if (option.startsWith('edit button')) { - queryLayoutOptions.hideEditButton = hide; - return true; - } - if (option.startsWith('urgency')) { - queryLayoutOptions.hideUrgency = hide; - return true; - } - return false; + return parseQueryShowHideOptions(queryLayoutOptions, option, hide); } /** From d377e38daba919dee52bf989cb0ae4e457700426 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:57:47 +0000 Subject: [PATCH 22/31] refactor: . Move parseQueryShowHideOptions() to QueryLayoutOptions.ts --- src/Layout/QueryLayoutOptions.ts | 28 ++++++++++++++++++++++++++++ src/Query/Query.ts | 30 +----------------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Layout/QueryLayoutOptions.ts b/src/Layout/QueryLayoutOptions.ts index 673dbf1de0..7d3952798a 100644 --- a/src/Layout/QueryLayoutOptions.ts +++ b/src/Layout/QueryLayoutOptions.ts @@ -13,3 +13,31 @@ export class QueryLayoutOptions { shortMode: boolean = false; explainQuery: boolean = false; } + +export function parseQueryShowHideOptions(queryLayoutOptions: QueryLayoutOptions, option: string, hide: boolean) { + if (option.startsWith('tree')) { + queryLayoutOptions.hideTree = hide; + return true; + } + if (option.startsWith('task count')) { + queryLayoutOptions.hideTaskCount = hide; + return true; + } + if (option.startsWith('backlink')) { + queryLayoutOptions.hideBacklinks = hide; + return true; + } + if (option.startsWith('postpone button')) { + queryLayoutOptions.hidePostponeButton = hide; + return true; + } + if (option.startsWith('edit button')) { + queryLayoutOptions.hideEditButton = hide; + return true; + } + if (option.startsWith('urgency')) { + queryLayoutOptions.hideUrgency = hide; + return true; + } + return false; +} diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 075f6d9c7e..6710cef9de 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -1,6 +1,6 @@ import { getSettings } from '../Config/Settings'; import type { IQuery } from '../IQuery'; -import { QueryLayoutOptions } from '../Layout/QueryLayoutOptions'; +import { QueryLayoutOptions, parseQueryShowHideOptions } from '../Layout/QueryLayoutOptions'; import { TaskLayoutComponent, TaskLayoutOptions } from '../Layout/TaskLayoutOptions'; import { errorMessageForException } from '../lib/ExceptionTools'; import { logging } from '../lib/logging'; @@ -20,34 +20,6 @@ import { Sort } from './Sort/Sort'; import type { Sorter } from './Sort/Sorter'; import { Statement } from './Statement'; -function parseQueryShowHideOptions(queryLayoutOptions: QueryLayoutOptions, option: string, hide: boolean) { - if (option.startsWith('tree')) { - queryLayoutOptions.hideTree = hide; - return true; - } - if (option.startsWith('task count')) { - queryLayoutOptions.hideTaskCount = hide; - return true; - } - if (option.startsWith('backlink')) { - queryLayoutOptions.hideBacklinks = hide; - return true; - } - if (option.startsWith('postpone button')) { - queryLayoutOptions.hidePostponeButton = hide; - return true; - } - if (option.startsWith('edit button')) { - queryLayoutOptions.hideEditButton = hide; - return true; - } - if (option.startsWith('urgency')) { - queryLayoutOptions.hideUrgency = hide; - return true; - } - return false; -} - export class Query implements IQuery { /** Note: source is the raw source, before expanding any placeholders */ public readonly source: string; From 602c57ab62857338d295a55483d3e41ceb470b36 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:58:56 +0000 Subject: [PATCH 23/31] jsdoc: Move parseQueryShowHideOptions() docs to where the implementation now is --- src/Layout/QueryLayoutOptions.ts | 7 +++++++ src/Query/Query.ts | 6 ------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Layout/QueryLayoutOptions.ts b/src/Layout/QueryLayoutOptions.ts index 7d3952798a..4d1d13721a 100644 --- a/src/Layout/QueryLayoutOptions.ts +++ b/src/Layout/QueryLayoutOptions.ts @@ -14,6 +14,13 @@ export class QueryLayoutOptions { explainQuery: boolean = false; } +/** + * Parse show/hide options for Query Layout options + * @param queryLayoutOptions + * @param option - must already have been lower-cased + * @param hide - whether the option should be hidden + * @return True if the option was recognised, and false otherwise + */ export function parseQueryShowHideOptions(queryLayoutOptions: QueryLayoutOptions, option: string, hide: boolean) { if (option.startsWith('tree')) { queryLayoutOptions.hideTree = hide; diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 6710cef9de..105b77e422 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -318,12 +318,6 @@ ${statement.explainStatement(' ')} this.setError('do not understand hide/show option', new Statement(line, line)); } - /** - * Parse show/hide options for Query Layout options - * @param option - must already have been lower-cased - * @param hide - whether the option should be hidden - * @return True if the option was recognised, and false otherwise - */ private parseQueryShowHideOptions(option: string, hide: boolean): boolean { const queryLayoutOptions = this._queryLayoutOptions; return parseQueryShowHideOptions(queryLayoutOptions, option, hide); From d29c8cbc00eb58f3412e0dc04eb0f0f1435b3c23 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 08:59:37 +0000 Subject: [PATCH 24/31] refactor: . Inline Query.parseQueryShowHideOptions() --- src/Query/Query.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 105b77e422..df57e62886 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -309,7 +309,7 @@ ${statement.explainStatement(' ')} const hide = hideOptionsMatch[1].toLowerCase() === 'hide'; const option = hideOptionsMatch[2].toLowerCase(); - if (this.parseQueryShowHideOptions(option, hide)) { + if (parseQueryShowHideOptions(this._queryLayoutOptions, option, hide)) { return; } if (this.parseTaskShowHideOptions(option, !hide)) { @@ -317,12 +317,6 @@ ${statement.explainStatement(' ')} } this.setError('do not understand hide/show option', new Statement(line, line)); } - - private parseQueryShowHideOptions(option: string, hide: boolean): boolean { - const queryLayoutOptions = this._queryLayoutOptions; - return parseQueryShowHideOptions(queryLayoutOptions, option, hide); - } - /** * Parse show/hide options for Task layout options * @param option - must already have been lower-cased From 6a06d94765b85a55c5bed5df1342ce0c52854f82 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 09:00:28 +0000 Subject: [PATCH 25/31] refactor: . Extract taskLayoutOptions --- src/Query/Query.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index df57e62886..80e0d983eb 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -324,52 +324,53 @@ ${statement.explainStatement(' ')} * @return True if the option was recognised, and false otherwise */ private parseTaskShowHideOptions(option: string, visible: boolean): boolean { + const taskLayoutOptions = this._taskLayoutOptions; if (option.startsWith('priority')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); return true; } if (option.startsWith('cancelled date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, visible); return true; } if (option.startsWith('created date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, visible); return true; } if (option.startsWith('start date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, visible); return true; } if (option.startsWith('scheduled date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, visible); return true; } if (option.startsWith('due date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, visible); return true; } if (option.startsWith('done date')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, visible); return true; } if (option.startsWith('recurrence rule')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, visible); return true; } if (option.startsWith('tags')) { - this._taskLayoutOptions.setTagsVisibility(visible); + taskLayoutOptions.setTagsVisibility(visible); return true; } if (option.startsWith('id')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, visible); return true; } if (option.startsWith('depends on')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, visible); return true; } if (option.startsWith('on completion')) { - this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, visible); + taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, visible); return true; } return false; From 6a7637b059f0d3a11c0e8870d53b77e4a27c0e08 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 09:01:46 +0000 Subject: [PATCH 26/31] refactor: . Extract parseTaskShowHideOptions() --- src/Query/Query.ts | 102 +++++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 80e0d983eb..975ac13ebd 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -20,6 +20,58 @@ import { Sort } from './Sort/Sort'; import type { Sorter } from './Sort/Sorter'; import { Statement } from './Statement'; +function parseTaskShowHideOptions(option: string, taskLayoutOptions: TaskLayoutOptions, visible: boolean) { + if (option.startsWith('priority')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); + return true; + } + if (option.startsWith('cancelled date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, visible); + return true; + } + if (option.startsWith('created date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, visible); + return true; + } + if (option.startsWith('start date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, visible); + return true; + } + if (option.startsWith('scheduled date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, visible); + return true; + } + if (option.startsWith('due date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, visible); + return true; + } + if (option.startsWith('done date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, visible); + return true; + } + if (option.startsWith('recurrence rule')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, visible); + return true; + } + if (option.startsWith('tags')) { + taskLayoutOptions.setTagsVisibility(visible); + return true; + } + if (option.startsWith('id')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, visible); + return true; + } + if (option.startsWith('depends on')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, visible); + return true; + } + if (option.startsWith('on completion')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, visible); + return true; + } + return false; +} + export class Query implements IQuery { /** Note: source is the raw source, before expanding any placeholders */ public readonly source: string; @@ -325,55 +377,7 @@ ${statement.explainStatement(' ')} */ private parseTaskShowHideOptions(option: string, visible: boolean): boolean { const taskLayoutOptions = this._taskLayoutOptions; - if (option.startsWith('priority')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); - return true; - } - if (option.startsWith('cancelled date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, visible); - return true; - } - if (option.startsWith('created date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, visible); - return true; - } - if (option.startsWith('start date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, visible); - return true; - } - if (option.startsWith('scheduled date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, visible); - return true; - } - if (option.startsWith('due date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, visible); - return true; - } - if (option.startsWith('done date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, visible); - return true; - } - if (option.startsWith('recurrence rule')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, visible); - return true; - } - if (option.startsWith('tags')) { - taskLayoutOptions.setTagsVisibility(visible); - return true; - } - if (option.startsWith('id')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, visible); - return true; - } - if (option.startsWith('depends on')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, visible); - return true; - } - if (option.startsWith('on completion')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, visible); - return true; - } - return false; + return parseTaskShowHideOptions(option, taskLayoutOptions, visible); } private parseFilter(line: string, statement: Statement) { From 26d35e499e55c376705f6be70ffb58017fdf48fe Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 09:02:47 +0000 Subject: [PATCH 27/31] refactor: . Fix parameter order in parseTaskShowHideOptions() --- src/Query/Query.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 975ac13ebd..118423ac5e 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -20,7 +20,7 @@ import { Sort } from './Sort/Sort'; import type { Sorter } from './Sort/Sorter'; import { Statement } from './Statement'; -function parseTaskShowHideOptions(option: string, taskLayoutOptions: TaskLayoutOptions, visible: boolean) { +function parseTaskShowHideOptions(taskLayoutOptions: TaskLayoutOptions, option: string, visible: boolean) { if (option.startsWith('priority')) { taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); return true; @@ -377,7 +377,7 @@ ${statement.explainStatement(' ')} */ private parseTaskShowHideOptions(option: string, visible: boolean): boolean { const taskLayoutOptions = this._taskLayoutOptions; - return parseTaskShowHideOptions(option, taskLayoutOptions, visible); + return parseTaskShowHideOptions(taskLayoutOptions, option, visible); } private parseFilter(line: string, statement: Statement) { From e2224047c733c6356f1e2d3c05078a0121f8082c Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 09:03:40 +0000 Subject: [PATCH 28/31] jsdoc: Move parseTaskShowHideOptions() docs to where the implementation now is --- src/Query/Query.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 118423ac5e..07f5ed9722 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -20,6 +20,13 @@ import { Sort } from './Sort/Sort'; import type { Sorter } from './Sort/Sorter'; import { Statement } from './Statement'; +/** + * Parse show/hide options for Task layout options + * @param taskLayoutOptions + * @param option - must already have been lower-cased + * @param visible - whether the option should be shown + * @return True if the option was recognised, and false otherwise + */ function parseTaskShowHideOptions(taskLayoutOptions: TaskLayoutOptions, option: string, visible: boolean) { if (option.startsWith('priority')) { taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); @@ -369,12 +376,7 @@ ${statement.explainStatement(' ')} } this.setError('do not understand hide/show option', new Statement(line, line)); } - /** - * Parse show/hide options for Task layout options - * @param option - must already have been lower-cased - * @param visible - whether the option should be shown - * @return True if the option was recognised, and false otherwise - */ + private parseTaskShowHideOptions(option: string, visible: boolean): boolean { const taskLayoutOptions = this._taskLayoutOptions; return parseTaskShowHideOptions(taskLayoutOptions, option, visible); From b4a70884f98e299e7ca8c4e964d15fa5bd5a5273 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 09:05:59 +0000 Subject: [PATCH 29/31] jsdoc: Move parseTaskShowHideOptions() TaskLayoutOptions.ts --- src/Layout/TaskLayoutOptions.ts | 59 +++++++++++++++++++++++++++++++ src/Query/Query.ts | 61 +-------------------------------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/src/Layout/TaskLayoutOptions.ts b/src/Layout/TaskLayoutOptions.ts index 793ac643bc..6e18648a60 100644 --- a/src/Layout/TaskLayoutOptions.ts +++ b/src/Layout/TaskLayoutOptions.ts @@ -93,3 +93,62 @@ export class TaskLayoutOptions { this.setTagsVisibility(!this.areTagsShown()); } } + +/** + * Parse show/hide options for Task layout options + * @param taskLayoutOptions + * @param option - must already have been lower-cased + * @param visible - whether the option should be shown + * @return True if the option was recognised, and false otherwise + */ +export function parseTaskShowHideOptions(taskLayoutOptions: TaskLayoutOptions, option: string, visible: boolean) { + if (option.startsWith('priority')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); + return true; + } + if (option.startsWith('cancelled date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, visible); + return true; + } + if (option.startsWith('created date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, visible); + return true; + } + if (option.startsWith('start date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, visible); + return true; + } + if (option.startsWith('scheduled date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, visible); + return true; + } + if (option.startsWith('due date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, visible); + return true; + } + if (option.startsWith('done date')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, visible); + return true; + } + if (option.startsWith('recurrence rule')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, visible); + return true; + } + if (option.startsWith('tags')) { + taskLayoutOptions.setTagsVisibility(visible); + return true; + } + if (option.startsWith('id')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, visible); + return true; + } + if (option.startsWith('depends on')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, visible); + return true; + } + if (option.startsWith('on completion')) { + taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, visible); + return true; + } + return false; +} diff --git a/src/Query/Query.ts b/src/Query/Query.ts index 07f5ed9722..c3bfec78f5 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -1,7 +1,7 @@ import { getSettings } from '../Config/Settings'; import type { IQuery } from '../IQuery'; import { QueryLayoutOptions, parseQueryShowHideOptions } from '../Layout/QueryLayoutOptions'; -import { TaskLayoutComponent, TaskLayoutOptions } from '../Layout/TaskLayoutOptions'; +import { TaskLayoutOptions, parseTaskShowHideOptions } from '../Layout/TaskLayoutOptions'; import { errorMessageForException } from '../lib/ExceptionTools'; import { logging } from '../lib/logging'; import { expandPlaceholders } from '../Scripting/ExpandPlaceholders'; @@ -20,65 +20,6 @@ import { Sort } from './Sort/Sort'; import type { Sorter } from './Sort/Sorter'; import { Statement } from './Statement'; -/** - * Parse show/hide options for Task layout options - * @param taskLayoutOptions - * @param option - must already have been lower-cased - * @param visible - whether the option should be shown - * @return True if the option was recognised, and false otherwise - */ -function parseTaskShowHideOptions(taskLayoutOptions: TaskLayoutOptions, option: string, visible: boolean) { - if (option.startsWith('priority')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.Priority, visible); - return true; - } - if (option.startsWith('cancelled date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.CancelledDate, visible); - return true; - } - if (option.startsWith('created date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.CreatedDate, visible); - return true; - } - if (option.startsWith('start date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.StartDate, visible); - return true; - } - if (option.startsWith('scheduled date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.ScheduledDate, visible); - return true; - } - if (option.startsWith('due date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.DueDate, visible); - return true; - } - if (option.startsWith('done date')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.DoneDate, visible); - return true; - } - if (option.startsWith('recurrence rule')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.RecurrenceRule, visible); - return true; - } - if (option.startsWith('tags')) { - taskLayoutOptions.setTagsVisibility(visible); - return true; - } - if (option.startsWith('id')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.Id, visible); - return true; - } - if (option.startsWith('depends on')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, visible); - return true; - } - if (option.startsWith('on completion')) { - taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, visible); - return true; - } - return false; -} - export class Query implements IQuery { /** Note: source is the raw source, before expanding any placeholders */ public readonly source: string; From 05aed75db724ad942fd01a8ec6805cfd87399fc0 Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 09:07:02 +0000 Subject: [PATCH 30/31] refactor: . Inline Query.parseTaskShowHideOptions() --- src/Query/Query.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Query/Query.ts b/src/Query/Query.ts index c3bfec78f5..996b68426c 100644 --- a/src/Query/Query.ts +++ b/src/Query/Query.ts @@ -312,17 +312,12 @@ ${statement.explainStatement(' ')} if (parseQueryShowHideOptions(this._queryLayoutOptions, option, hide)) { return; } - if (this.parseTaskShowHideOptions(option, !hide)) { + if (parseTaskShowHideOptions(this._taskLayoutOptions, option, !hide)) { return; } this.setError('do not understand hide/show option', new Statement(line, line)); } - private parseTaskShowHideOptions(option: string, visible: boolean): boolean { - const taskLayoutOptions = this._taskLayoutOptions; - return parseTaskShowHideOptions(taskLayoutOptions, option, visible); - } - private parseFilter(line: string, statement: Statement) { const filterOrError = FilterParser.parseFilter(line); if (filterOrError != null) { From 1f6850baf09aaea2d1d9779eb4114011c839069a Mon Sep 17 00:00:00 2001 From: Clare Macrae Date: Sun, 1 Dec 2024 09:10:14 +0000 Subject: [PATCH 31/31] jsdoc: Add links to related functions --- src/Layout/QueryLayoutOptions.ts | 1 + src/Layout/TaskLayoutOptions.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Layout/QueryLayoutOptions.ts b/src/Layout/QueryLayoutOptions.ts index 4d1d13721a..152d3d2f5e 100644 --- a/src/Layout/QueryLayoutOptions.ts +++ b/src/Layout/QueryLayoutOptions.ts @@ -20,6 +20,7 @@ export class QueryLayoutOptions { * @param option - must already have been lower-cased * @param hide - whether the option should be hidden * @return True if the option was recognised, and false otherwise + * @see parseTaskShowHideOptions */ export function parseQueryShowHideOptions(queryLayoutOptions: QueryLayoutOptions, option: string, hide: boolean) { if (option.startsWith('tree')) { diff --git a/src/Layout/TaskLayoutOptions.ts b/src/Layout/TaskLayoutOptions.ts index 6e18648a60..f89fb50bf9 100644 --- a/src/Layout/TaskLayoutOptions.ts +++ b/src/Layout/TaskLayoutOptions.ts @@ -100,6 +100,7 @@ export class TaskLayoutOptions { * @param option - must already have been lower-cased * @param visible - whether the option should be shown * @return True if the option was recognised, and false otherwise + * @see parseQueryShowHideOptions */ export function parseTaskShowHideOptions(taskLayoutOptions: TaskLayoutOptions, option: string, visible: boolean) { if (option.startsWith('priority')) {