Skip to content

Commit e65dd75

Browse files
authored
Merge pull request #2612 from obsidian-tasks-group/reduce-cyclic-deps
refactor: Reduce cyclic dependencies in src/
2 parents ce5eed5 + d334f6b commit e65dd75

39 files changed

+163
-131
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ yarn-error.log
2121

2222
# Code analysis output files
2323
/circular-deps.png
24-
/circular-deps.txt
24+
#/circular-deps.txt
2525

2626
# approval test files
2727
*.received.*

circular-deps.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Processed 152 files (995ms) (16 warnings)
2+
3+
1) Config/Settings.ts > Suggestor/Suggestor.ts
4+
2) Task/Task.ts > Config/Settings.ts > Suggestor/Suggestor.ts
5+
3) Task/Task.ts > Config/Settings.ts > Suggestor/Suggestor.ts > TaskSerializer/DefaultTaskSerializer.ts
6+
4) Task/Task.ts > Config/Settings.ts > TaskSerializer/DataviewTaskSerializer.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) main.ts > Config/SettingsTab.ts
13+
11) Obsidian/Cache.ts > Obsidian/TasksEvents.ts
14+
12) main.ts > Renderer/QueryRenderer.ts
15+

src/Commands/CreateOrEditTaskParser.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Status } from '../Statuses/Status';
2-
import { Priority, 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';
8+
import { Priority } from '../Task/Priority';
9+
import { TaskRegularExpressions } from '../Task/TaskRegularExpressions';
810

911
function getDefaultCreatedDate() {
1012
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/Query/Filter/PriorityField.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { Priority, Task } from '../../Task/Task';
1+
import type { Task } from '../../Task/Task';
22
import { Explanation } from '../Explain/Explanation';
33
import type { Comparator } from '../Sort/Sorter';
44
import type { GrouperFunction } from '../Group/Grouper';
5+
import { Priority } from '../../Task/Priority';
56
import { Field } from './Field';
67
import { Filter } from './Filter';
78
import { FilterOrErrorMessage } from './FilterOrErrorMessage';

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/Statuses/StatusRegistryReport.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,3 @@ ${settingsTable}
4747
These are the settings actually used by Tasks.
4848
${mermaidText}`;
4949
}
50-
51-
export function getPrintableSymbol(symbol: string) {
52-
// Do not put backticks around an empty symbol, as the two backticks are rendered
53-
// by Obsidian as ordinary characters and the meaning is unclear.
54-
// Better to just display nothing in this situation.
55-
if (symbol === '') {
56-
return symbol;
57-
}
58-
const result = symbol !== ' ' ? symbol : 'space';
59-
return '`' + result + '`';
60-
}

src/Statuses/StatusSettingsReport.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import { StatusSettings } from '../Config/StatusSettings';
22
import { MarkdownTable } from '../lib/MarkdownTable';
33
import type { StatusConfiguration } from './StatusConfiguration';
4-
import { getPrintableSymbol } from './StatusRegistryReport';
5-
import { Status } from './Status';
64
import { StatusType } from './StatusConfiguration';
5+
import { Status } from './Status';
76

87
function getFirstIndex(statusConfigurations: StatusConfiguration[], wantedSymbol: string) {
98
return statusConfigurations.findIndex((s) => s.symbol === wantedSymbol);
109
}
1110

11+
export function getPrintableSymbol(symbol: string) {
12+
// Do not put backticks around an empty symbol, as the two backticks are rendered
13+
// by Obsidian as ordinary characters and the meaning is unclear.
14+
// Better to just display nothing in this situation.
15+
if (symbol === '') {
16+
return symbol;
17+
}
18+
const result = symbol !== ' ' ? symbol : 'space';
19+
return '`' + result + '`';
20+
}
21+
1222
function checkIfConventionalType(status: StatusConfiguration, problems: string[]) {
1323
// Check if conventional type is being used:
1424
const conventionalType = Status.getTypeForUnknownSymbol(status.symbol);

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/Priority.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* When sorting, make sure low always comes after none. This way any tasks with low will be below any exiting
3+
* tasks that have no priority which would be the default.
4+
*
5+
* Values can be converted to strings with:
6+
* - {@link priorityNameUsingNone} in {@link PriorityTools}
7+
* - {@link priorityNameUsingNormal} in {@link PriorityTools}
8+
*
9+
* @export
10+
* @enum {number}
11+
*/
12+
export enum Priority {
13+
Highest = '0',
14+
High = '1',
15+
Medium = '2',
16+
None = '3',
17+
Low = '4',
18+
Lowest = '5',
19+
}

src/Task/Task.ts

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

10220
/**
10321
* 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/DataviewTaskSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TaskLayoutComponent } from '../Layout/TaskLayoutOptions';
22
import type { Task } from '../Task/Task';
3-
import { Priority } from '../Task/Task';
3+
import { Priority } from '../Task/Priority';
44
import { DefaultTaskSerializer } from './DefaultTaskSerializer';
55

66
/**

src/TaskSerializer/DefaultTaskSerializer.ts

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

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

src/lib/PriorityTools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Priority } from '../Task/Task';
1+
import { Priority } from '../Task/Priority';
22

33
export class PriorityTools {
44
/**

src/ui/EditInstructions/PriorityInstructions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { Priority, Task } from '../../Task/Task';
1+
import { Task } from '../../Task/Task';
22
import { PriorityTools } from '../../lib/PriorityTools';
3+
import { Priority } from '../../Task/Priority';
34
import type { TaskEditingInstruction } from './TaskEditingInstruction';
45

56
/**

src/ui/EditTask.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
import { getSettings, TASK_FORMATS } from '../Config/Settings';
66
import { GlobalFilter } from '../Config/GlobalFilter';
77
import { Status } from '../Statuses/Status';
8-
import { Priority, Task } from '../Task/Task';
8+
import { Task } from '../Task/Task';
99
import { doAutocomplete } from '../lib/DateAbbreviations';
1010
import { TasksDate } from '../Scripting/TasksDate';
1111
import { addDependencyToParent, ensureTaskHasId, generateUniqueId, removeDependency } from "../Task/TaskDependency";
1212
import { replaceTaskWithTasks } from "../Obsidian/File";
1313
import type { EditableTask } from "./EditableTask";
1414
import Dependency from "./Dependency.svelte";
15+
import { Priority } from '../Task/Priority';
1516
1617
// These exported variables are passed in as props by TaskModal.onOpen():
1718
export let task: Task;

tests/Commands/CreateOrEditTaskParser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
*/
44
import moment from 'moment';
55
import { resetSettings, updateSettings } from '../../src/Config/Settings';
6-
import { Priority } from '../../src/Task/Task';
76
import { taskFromLine } from '../../src/Commands/CreateOrEditTaskParser';
87
import { GlobalFilter } from '../../src/Config/GlobalFilter';
8+
import { Priority } from '../../src/Task/Priority';
99

1010
window.moment = moment;
1111

tests/CustomMatchers/CustomMatchersForTaskSerializer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +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 { Priority, TaskRegularExpressions } from '../../src/Task/Task';
65
import { Recurrence } from '../../src/Task/Recurrence';
6+
import { Priority } from '../../src/Task/Priority';
7+
import { TaskRegularExpressions } from '../../src/Task/TaskRegularExpressions';
78

89
declare global {
910
namespace jest {

tests/DocumentationSamples/UrgencyDocs/DocsSamplesForUrgency.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import moment from 'moment';
77
import { verifyMarkdownForDocs } from '../../TestingTools/VerifyMarkdown';
88
import { TaskBuilder } from '../../TestingTools/TaskBuilder';
99
import { Urgency } from '../../../src/Task/Urgency';
10-
import { Priority } from '../../../src/Task/Task';
10+
11+
import { Priority } from '../../../src/Task/Priority';
1112

1213
window.moment = moment;
1314

0 commit comments

Comments
 (0)