Skip to content

Commit c9cdd58

Browse files
committed
refactor: . Fix Task/Task.ts > Scripting/TasksDate.ts cyclic dependency
1 parent 06f478e commit c9cdd58

File tree

14 files changed

+92
-87
lines changed

14 files changed

+92
-87
lines changed

circular-deps.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
Processed 151 files (7.5s) (16 warnings)
1+
Processed 152 files (1s) (16 warnings)
22

33
1) Config/Settings.ts > Suggestor/Suggestor.ts
44
2) Task/Task.ts > Config/Settings.ts > Suggestor/Suggestor.ts
55
3) Task/Task.ts > Config/Settings.ts > Suggestor/Suggestor.ts > TaskSerializer/DefaultTaskSerializer.ts
66
4) Task/Task.ts > Config/Settings.ts > TaskSerializer/DataviewTaskSerializer.ts
7-
5) Task/Task.ts > Scripting/TasksDate.ts
8-
6) Task/Task.ts > Task/DateFallback.ts
9-
7) Task/Task.ts > Task/Urgency.ts
10-
8) Task/Task.ts > lib/LogTasksHelper.ts
11-
9) Query/Query.ts > Query/Explain/Explainer.ts
12-
10) Query/FilterParser.ts > Query/Filter/BooleanField.ts
13-
11) Statuses/StatusRegistryReport.ts > Statuses/StatusSettingsReport.ts
14-
12) main.ts > Config/SettingsTab.ts
15-
13) Obsidian/Cache.ts > Obsidian/TasksEvents.ts
16-
14) main.ts > Renderer/QueryRenderer.ts
7+
5) Task/Task.ts > Task/DateFallback.ts
8+
6) Task/Task.ts > Task/Urgency.ts
9+
7) Task/Task.ts > lib/LogTasksHelper.ts
10+
8) Query/Query.ts > Query/Explain/Explainer.ts
11+
9) Query/FilterParser.ts > Query/Filter/BooleanField.ts
12+
10) Statuses/StatusRegistryReport.ts > Statuses/StatusSettingsReport.ts
13+
11) main.ts > Config/SettingsTab.ts
14+
12) Obsidian/Cache.ts > Obsidian/TasksEvents.ts
15+
13) main.ts > Renderer/QueryRenderer.ts
1716

src/Commands/CreateOrEditTaskParser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Status } from '../Statuses/Status';
2-
import { Task, TaskRegularExpressions } from '../Task/Task';
2+
import { Task } from '../Task/Task';
33
import { DateFallback } from '../Task/DateFallback';
44
import { StatusRegistry } from '../Statuses/StatusRegistry';
55
import { TaskLocation } from '../Task/TaskLocation';
66
import { getSettings } from '../Config/Settings';
77
import { GlobalFilter } from '../Config/GlobalFilter';
88
import { Priority } from '../Task/Priority';
9+
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
910

1011
function getDefaultCreatedDate() {
1112
const { setCreatedDate } = getSettings();

src/Commands/ToggleDone.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Editor, type EditorPosition, type MarkdownFileInfo, MarkdownView } from 'obsidian';
22
import { StatusRegistry } from '../Statuses/StatusRegistry';
33

4-
import { Task, TaskRegularExpressions } from '../Task/Task';
4+
import { Task } from '../Task/Task';
55
import { TaskLocation } from '../Task/TaskLocation';
6+
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
67

78
export const toggleDone = (checking: boolean, editor: Editor, view: MarkdownView | MarkdownFileInfo) => {
89
if (checking) {

src/Renderer/TaskLineRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { replaceTaskWithTasks } from '../Obsidian/File';
66
import type { TaskLayoutComponent, TaskLayoutOptions } from '../Layout/TaskLayoutOptions';
77
import type { QueryLayoutOptions } from '../Layout/QueryLayoutOptions';
88
import type { Task } from '../Task/Task';
9-
import * as taskModule from '../Task/Task';
109
import { StatusMenu } from '../ui/Menus/StatusMenu';
1110
import { StatusRegistry } from '../Statuses/StatusRegistry';
11+
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
1212
import { TaskFieldRenderer } from './TaskFieldRenderer';
1313

1414
/**
@@ -309,7 +309,7 @@ export class TaskLineRenderer {
309309
}
310310

311311
function toTooltipDate({ signifier, date }: { signifier: string; date: Moment }): string {
312-
return `${signifier} ${date.format(taskModule.TaskRegularExpressions.dateFormat)} (${date.from(
312+
return `${signifier} ${date.format(TaskRegularExpressions.dateFormat)} (${date.from(
313313
window.moment().startOf('day'),
314314
)})`;
315315
}

src/Scripting/TasksDate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { DurationInputArg2, Moment, unitOfTime } from 'moment';
22
import { Notice } from 'obsidian';
3-
import { TaskRegularExpressions } from '../Task/Task';
43
import { PropertyCategory } from '../lib/PropertyCategory';
4+
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
55

66
/**
77
* TasksDate encapsulates a date, for simplifying the JavaScript expressions users need to

src/Suggestor/Suggestor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { DateParser } from '../Query/DateParser';
33
import { doAutocomplete } from '../lib/DateAbbreviations';
44
import { Recurrence } from '../Task/Recurrence';
55
import type { DefaultTaskSerializerSymbols } from '../TaskSerializer/DefaultTaskSerializer';
6-
import { Task, TaskRegularExpressions } from '../Task/Task';
6+
import { Task } from '../Task/Task';
77
import { GlobalFilter } from '../Config/GlobalFilter';
8+
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
89
import type { SuggestInfo, SuggestionBuilder } from '.';
910

1011
/**

src/Task/Task.ts

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,7 @@ import { Urgency } from './Urgency';
1515
import type { Recurrence } from './Recurrence';
1616
import type { TaskLocation } from './TaskLocation';
1717
import type { Priority } from './Priority';
18-
19-
export class TaskRegularExpressions {
20-
public static readonly dateFormat = 'YYYY-MM-DD';
21-
public static readonly dateTimeFormat = 'YYYY-MM-DD HH:mm';
22-
23-
// Matches indentation before a list marker (including > for potentially nested blockquotes or Obsidian callouts)
24-
public static readonly indentationRegex = /^([\s\t>]*)/;
25-
26-
// Matches - * and + list markers, or numbered list markers (eg 1.)
27-
public static readonly listMarkerRegex = /([-*+]|[0-9]+\.)/;
28-
29-
// Matches a checkbox and saves the status character inside
30-
public static readonly checkboxRegex = /\[(.)\]/u;
31-
32-
// Matches the rest of the task after the checkbox.
33-
public static readonly afterCheckboxRegex = / *(.*)/u;
34-
35-
// Main regex for parsing a line. It matches the following:
36-
// - Indentation
37-
// - List marker
38-
// - Status character
39-
// - Rest of task after checkbox markdown
40-
// See Task.extractTaskComponents() for abstraction around this regular expression.
41-
// That is private for now, but could be made public in future if needed.
42-
public static readonly taskRegex = new RegExp(
43-
TaskRegularExpressions.indentationRegex.source +
44-
TaskRegularExpressions.listMarkerRegex.source +
45-
' +' +
46-
TaskRegularExpressions.checkboxRegex.source +
47-
TaskRegularExpressions.afterCheckboxRegex.source,
48-
'u',
49-
);
50-
51-
// Used with the "Create or Edit Task" command to parse indentation and status if present
52-
public static readonly nonTaskRegex = new RegExp(
53-
TaskRegularExpressions.indentationRegex.source +
54-
TaskRegularExpressions.listMarkerRegex.source +
55-
'? *(' +
56-
TaskRegularExpressions.checkboxRegex.source +
57-
')?' +
58-
TaskRegularExpressions.afterCheckboxRegex.source,
59-
'u',
60-
);
61-
62-
// Used with "Toggle Done" command to detect a list item that can get a checkbox added to it.
63-
public static readonly listItemRegex = new RegExp(
64-
TaskRegularExpressions.indentationRegex.source + TaskRegularExpressions.listMarkerRegex.source,
65-
);
66-
67-
// Match on block link at end.
68-
public static readonly blockLinkRegex = / \^[a-zA-Z0-9-]+$/u;
69-
70-
// Regex to match all hash tags, basically hash followed by anything but the characters in the negation.
71-
// To ensure URLs are not caught it is looking of beginning of string tag and any
72-
// tag that has a space in front of it. Any # that has a character in front
73-
// of it will be ignored.
74-
// EXAMPLE:
75-
// description: '#dog #car http://www/ddd#ere #house'
76-
// matches: #dog, #car, #house
77-
// MAINTENANCE NOTE:
78-
// If hashTags is modified, please update 'Recognising Tags' in Tags.md in the docs.
79-
public static readonly hashTags = /(^|\s)#[^ !@#$%^&*(),.?":{}|<>]+/g;
80-
public static readonly hashTagsFromEnd = new RegExp(this.hashTags.source + '$');
81-
}
18+
import { TaskRegularExpressions } from './TaskRegularExpressions';
8219

8320
/**
8421
* Storage for the task line, broken down in to sections.

src/Task/TaskRegularExpressions.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
export class TaskRegularExpressions {
2+
public static readonly dateFormat = 'YYYY-MM-DD';
3+
public static readonly dateTimeFormat = 'YYYY-MM-DD HH:mm';
4+
5+
// Matches indentation before a list marker (including > for potentially nested blockquotes or Obsidian callouts)
6+
public static readonly indentationRegex = /^([\s\t>]*)/;
7+
8+
// Matches - * and + list markers, or numbered list markers (eg 1.)
9+
public static readonly listMarkerRegex = /([-*+]|[0-9]+\.)/;
10+
11+
// Matches a checkbox and saves the status character inside
12+
public static readonly checkboxRegex = /\[(.)\]/u;
13+
14+
// Matches the rest of the task after the checkbox.
15+
public static readonly afterCheckboxRegex = / *(.*)/u;
16+
17+
// Main regex for parsing a line. It matches the following:
18+
// - Indentation
19+
// - List marker
20+
// - Status character
21+
// - Rest of task after checkbox markdown
22+
// See Task.extractTaskComponents() for abstraction around this regular expression.
23+
// That is private for now, but could be made public in future if needed.
24+
public static readonly taskRegex = new RegExp(
25+
TaskRegularExpressions.indentationRegex.source +
26+
TaskRegularExpressions.listMarkerRegex.source +
27+
' +' +
28+
TaskRegularExpressions.checkboxRegex.source +
29+
TaskRegularExpressions.afterCheckboxRegex.source,
30+
'u',
31+
);
32+
33+
// Used with the "Create or Edit Task" command to parse indentation and status if present
34+
public static readonly nonTaskRegex = new RegExp(
35+
TaskRegularExpressions.indentationRegex.source +
36+
TaskRegularExpressions.listMarkerRegex.source +
37+
'? *(' +
38+
TaskRegularExpressions.checkboxRegex.source +
39+
')?' +
40+
TaskRegularExpressions.afterCheckboxRegex.source,
41+
'u',
42+
);
43+
44+
// Used with "Toggle Done" command to detect a list item that can get a checkbox added to it.
45+
public static readonly listItemRegex = new RegExp(
46+
TaskRegularExpressions.indentationRegex.source + TaskRegularExpressions.listMarkerRegex.source,
47+
);
48+
49+
// Match on block link at end.
50+
public static readonly blockLinkRegex = / \^[a-zA-Z0-9-]+$/u;
51+
52+
// Regex to match all hash tags, basically hash followed by anything but the characters in the negation.
53+
// To ensure URLs are not caught it is looking of beginning of string tag and any
54+
// tag that has a space in front of it. Any # that has a character in front
55+
// of it will be ignored.
56+
// EXAMPLE:
57+
// description: '#dog #car http://www/ddd#ere #house'
58+
// matches: #dog, #car, #house
59+
// MAINTENANCE NOTE:
60+
// If hashTags is modified, please update 'Recognising Tags' in Tags.md in the docs.
61+
public static readonly hashTags = /(^|\s)#[^ !@#$%^&*(),.?":{}|<>]+/g;
62+
public static readonly hashTagsFromEnd = new RegExp(this.hashTags.source + '$');
63+
}

src/TaskSerializer/DefaultTaskSerializer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { Moment } from 'moment';
22
import { type TaskLayoutComponent, TaskLayoutOptions } from '../Layout/TaskLayoutOptions';
33
import { Recurrence } from '../Task/Recurrence';
4-
import { Task, TaskRegularExpressions } from '../Task/Task';
4+
import { Task } from '../Task/Task';
55
import { Priority } from '../Task/Priority';
6+
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
67
import type { TaskDetails, TaskSerializer } from '.';
78

89
/* Interface describing the symbols that {@link DefaultTaskSerializer}

tests/CustomMatchers/CustomMatchersForTaskSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { diff } from 'jest-diff';
22
import type { MatcherFunction } from 'expect';
33
import moment from 'moment';
44
import type { TaskDetails } from '../../src/TaskSerializer';
5-
import { TaskRegularExpressions } from '../../src/Task/Task';
65
import { Recurrence } from '../../src/Task/Recurrence';
76
import { Priority } from '../../src/Task/Priority';
7+
import { TaskRegularExpressions } from '../../src/Task/TaskRegularExpressions';
88

99
declare global {
1010
namespace jest {

0 commit comments

Comments
 (0)