Skip to content

Commit d78dcaa

Browse files
committed
refactor: Remove Link.filenameContainingLink - pathContainingLink is now used instead
1 parent c466705 commit d78dcaa

File tree

4 files changed

+5
-16
lines changed

4 files changed

+5
-16
lines changed

src/Scripting/TasksFile.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,14 @@ export class TasksFile {
6161
* Return an array of {@link Link} in the file's properties/frontmatter.
6262
*/
6363
get outlinksInProperties(): Link[] {
64-
return (
65-
this.cachedMetadata.frontmatterLinks?.map(
66-
(link) => new Link(link, this.filenameWithoutExtension, this.path),
67-
) ?? []
68-
);
64+
return this.cachedMetadata.frontmatterLinks?.map((link) => new Link(link, this.path)) ?? [];
6965
}
7066

7167
/**
7268
* Return an array of {@link Link} in the body of the file.
7369
*/
7470
get outlinksInBody(): Link[] {
75-
return (
76-
this.cachedMetadata?.links?.map((link) => new Link(link, this.filenameWithoutExtension, this.path)) ?? []
77-
);
71+
return this.cachedMetadata?.links?.map((link) => new Link(link, this.path)) ?? [];
7872
}
7973

8074
/**

src/Task/Link.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,14 @@ import type { Reference } from 'obsidian';
22

33
export class Link {
44
private readonly rawLink: Reference;
5-
// @ts-expect-error: TS6133: filenameContainingLink is declared but its value is never read.
6-
private readonly filenameContainingLink: string;
75
private readonly pathContainingLink: string;
86

97
/**
108
* @param {Reference} rawLink - The raw link from Obsidian cache.
11-
* @param {string} filenameContainingLink - The name of the file where this link is located.
129
* @param {string} pathContainingLink - The path of the file where this link is located.
1310
*/
14-
constructor(rawLink: Reference, filenameContainingLink: string, pathContainingLink: string) {
11+
constructor(rawLink: Reference, pathContainingLink: string) {
1512
this.rawLink = rawLink;
16-
this.filenameContainingLink = filenameContainingLink;
1713
this.pathContainingLink = pathContainingLink;
1814
}
1915

src/Task/ListItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class ListItem {
210210
public get outlinks(): Link[] {
211211
return this.rawLinksInFileBody
212212
.filter((link) => link.position.start.line === this.lineNumber)
213-
.map((link) => new Link(link, this.file.filenameWithoutExtension, this.file.path));
213+
.map((link) => new Link(link, this.file.path));
214214
}
215215

216216
/**

tests/Task/Link.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Link } from '../../src/Task/Link';
2-
import { TasksFile } from '../../src/Scripting/TasksFile';
32

43
import links_everywhere from '../Obsidian/__test_data__/links_everywhere.json';
54
import internal_heading_links from '../Obsidian/__test_data__/internal_heading_links.json';
@@ -13,7 +12,7 @@ import type { SimulatedFile } from '../Obsidian/SimulatedFile';
1312

1413
function getLink(data: any, index: number) {
1514
const rawLink = data.cachedMetadata.links[index];
16-
return new Link(rawLink, new TasksFile(data.filePath).filenameWithoutExtension, data.filePath);
15+
return new Link(rawLink, data.filePath);
1716
}
1817

1918
describe('linkClass', () => {

0 commit comments

Comments
 (0)