Skip to content

Commit d482b4d

Browse files
committed
chore: apply prettier formatting to tools and cache
Consistent code formatting across tool modules
1 parent 131add2 commit d482b4d

7 files changed

Lines changed: 487 additions & 518 deletions

File tree

generated/ogp.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,4 @@
224224
"description": "Menu bar calendar for macOS - MVVM | RxSwift | AppKit | SwiftUI - pakerwreah/Calendr",
225225
"image": "https://opengraph.githubassets.com/5ed67afc1ce5ec4c5301fc7a02d43bf32e6c60974c29b7d9ee7bf9d7620d1d80/pakerwreah/Calendr"
226226
}
227-
}
227+
}

tools/rehype-code-copy-button/index.test.ts

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,12 @@ describe("rehype-code-copy-button", () => {
3636

3737
// preに子要素としてbuttonが追加されているか
3838
const buttonChild = preElement.children.find(
39-
(child): child is Element =>
40-
child.type === "element" && child.tagName === "button"
39+
(child): child is Element => child.type === "element" && child.tagName === "button"
4140
);
4241

4342
expect(buttonChild).toBeDefined();
4443
expect(buttonChild?.properties?.className).toContain("copy-button");
45-
expect(buttonChild?.properties?.["aria-label"]).toBe(
46-
"コードをクリップボードにコピー"
47-
);
44+
expect(buttonChild?.properties?.["aria-label"]).toBe("コードをクリップボードにコピー");
4845

4946
// ボタンのテキストがCopyであること
5047
const buttonText = buttonChild?.children[0] as Text;
@@ -61,8 +58,7 @@ describe("rehype-code-copy-button", () => {
6158

6259
const preElement = tree.children[0] as Element;
6360
const buttonChild = preElement.children.find(
64-
(child): child is Element =>
65-
child.type === "element" && child.tagName === "button"
61+
(child): child is Element => child.type === "element" && child.tagName === "button"
6662
);
6763

6864
expect(buttonChild?.properties?.className).toContain("custom-copy-btn");
@@ -88,8 +84,7 @@ describe("rehype-code-copy-button", () => {
8884

8985
const preElement = tree.children[0] as Element;
9086
const buttonChild = preElement.children.find(
91-
(child): child is Element =>
92-
child.type === "element" && child.tagName === "button"
87+
(child): child is Element => child.type === "element" && child.tagName === "button"
9388
);
9489

9590
expect(buttonChild).toBeUndefined();
@@ -120,8 +115,7 @@ describe("rehype-code-copy-button", () => {
120115

121116
const divElement = tree.children[0] as Element;
122117
const buttonChild = divElement.children.find(
123-
(child): child is Element =>
124-
child.type === "element" && child.tagName === "button"
118+
(child): child is Element => child.type === "element" && child.tagName === "button"
125119
);
126120

127121
expect(buttonChild).toBeUndefined();
@@ -153,8 +147,7 @@ describe("rehype-code-copy-button", () => {
153147
const preElement = tree.children[0] as Element;
154148
// ボタンが追加されていないことを確認(子要素はcodeのみ)
155149
const buttonChildren = preElement.children.filter(
156-
(child): child is Element =>
157-
child.type === "element" && child.tagName === "button"
150+
(child): child is Element => child.type === "element" && child.tagName === "button"
158151
);
159152

160153
expect(buttonChildren.length).toBe(0);
@@ -186,8 +179,7 @@ describe("rehype-code-copy-button", () => {
186179

187180
const preElement = tree.children[0] as Element;
188181
const buttonChild = preElement.children.find(
189-
(child): child is Element =>
190-
child.type === "element" && child.tagName === "button"
182+
(child): child is Element => child.type === "element" && child.tagName === "button"
191183
);
192184

193185
expect(buttonChild?.properties?.["data-copy-text"]).toBe("コピー");

tools/rehype-line-numbers/index.ts

Lines changed: 60 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,71 +19,75 @@ export default function rehypeLineNumbers(options: Options = {}) {
1919
} = options;
2020

2121
return (tree: Root) => {
22-
visit(tree, "element", (node: Element, index: number | undefined, parent: Parent | undefined) => {
23-
// pre > code のパターンを探す(バグ修正: 元のコードは条件式が間違っていた)
24-
if (
25-
node.tagName !== "pre" ||
26-
node.children?.[0]?.type !== "element" ||
27-
(node.children[0] as Element).tagName !== "code"
28-
) {
29-
return;
30-
}
22+
visit(
23+
tree,
24+
"element",
25+
(node: Element, index: number | undefined, parent: Parent | undefined) => {
26+
// pre > code のパターンを探す(バグ修正: 元のコードは条件式が間違っていた)
27+
if (
28+
node.tagName !== "pre" ||
29+
node.children?.[0]?.type !== "element" ||
30+
(node.children[0] as Element).tagName !== "code"
31+
) {
32+
return;
33+
}
3134

32-
const codeNode = node.children[0] as Element;
35+
const codeNode = node.children[0] as Element;
3336

34-
// hast-util-to-stringを使用して安全にテキストを抽出
35-
const code = toString(codeNode);
36-
// 空の行を保持しながら分割
37-
const lines = code.split(/\r?\n/);
38-
const startNumber = startFrom1 ? 1 : 0;
37+
// hast-util-to-stringを使用して安全にテキストを抽出
38+
const code = toString(codeNode);
39+
// 空の行を保持しながら分割
40+
const lines = code.split(/\r?\n/);
41+
const startNumber = startFrom1 ? 1 : 0;
3942

40-
// 行番号要素の作成
41-
const lineNumbers: Element = {
42-
type: "element",
43-
tagName: "div",
44-
properties: {
45-
className: [className],
46-
},
47-
children: lines.map((_, i) => ({
48-
type: "element" as const,
49-
tagName: "span",
43+
// 行番号要素の作成
44+
const lineNumbers: Element = {
45+
type: "element",
46+
tagName: "div",
5047
properties: {
51-
className: [`${className}-item`],
52-
"data-line-number": startNumber + i,
48+
className: [className],
5349
},
54-
children: [
55-
{
56-
type: "text" as const,
57-
value: String(startNumber + i),
50+
children: lines.map((_, i) => ({
51+
type: "element" as const,
52+
tagName: "span",
53+
properties: {
54+
className: [`${className}-item`],
55+
"data-line-number": startNumber + i,
5856
},
59-
],
60-
})),
61-
};
57+
children: [
58+
{
59+
type: "text" as const,
60+
value: String(startNumber + i),
61+
},
62+
],
63+
})),
64+
};
6265

63-
// コードコンテンツをdiv要素でラップ
64-
const codeWrapper: Element = {
65-
type: "element",
66-
tagName: "div",
67-
properties: {
68-
className: ["code-content"],
69-
},
70-
children: [node],
71-
};
66+
// コードコンテンツをdiv要素でラップ
67+
const codeWrapper: Element = {
68+
type: "element",
69+
tagName: "div",
70+
properties: {
71+
className: ["code-content"],
72+
},
73+
children: [node],
74+
};
7275

73-
// メインラッパーの作成
74-
const wrapper: Element = {
75-
type: "element",
76-
tagName: "div",
77-
properties: {
78-
className: [wrapperClassName],
79-
},
80-
children: [lineNumbers, codeWrapper],
81-
};
76+
// メインラッパーの作成
77+
const wrapper: Element = {
78+
type: "element",
79+
tagName: "div",
80+
properties: {
81+
className: [wrapperClassName],
82+
},
83+
children: [lineNumbers, codeWrapper],
84+
};
8285

83-
// 親ノードの子要素を更新
84-
if (parent && typeof index === "number") {
85-
parent.children[index] = wrapper;
86+
// 親ノードの子要素を更新
87+
if (parent && typeof index === "number") {
88+
parent.children[index] = wrapper;
89+
}
8690
}
87-
});
91+
);
8892
};
8993
}

tools/remark-aside/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default function remarkAside() {
7979
const type = typeMatch[1];
8080

8181
// Process children to extract content
82-
const contentChildren: (MdastText | typeof paragraphNode.children[0])[] = [];
82+
const contentChildren: (MdastText | (typeof paragraphNode.children)[0])[] = [];
8383

8484
// Special case: single text node containing the entire aside
8585
if (paragraphNode.children.length === 1 && paragraphNode.children[0].type === "text") {

tools/remark-git-dates/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("remark-git-dates", () => {
3434

3535
expect(result).toEqual(new Date("2023-01-21"));
3636
expect(childProcess.execSync).toHaveBeenCalledWith(
37-
expect.stringContaining("git log --follow --diff-filter=A"),
37+
expect.stringContaining("git log --follow --diff-filter=A")
3838
);
3939
});
4040
});
@@ -47,7 +47,7 @@ describe("remark-git-dates", () => {
4747

4848
expect(result).toEqual(new Date("2024-02-21"));
4949
expect(childProcess.execSync).toHaveBeenCalledWith(
50-
expect.stringContaining("git log -1 --pretty"),
50+
expect.stringContaining("git log -1 --pretty")
5151
);
5252
});
5353
});
@@ -93,7 +93,7 @@ describe("remark-git-dates", () => {
9393
expect(file.data.astro.frontmatter.pubDate).toEqual(existingDate);
9494
// Git command should not be called for creation date
9595
expect(childProcess.execSync).not.toHaveBeenCalledWith(
96-
expect.stringContaining("--diff-filter=A"),
96+
expect.stringContaining("--diff-filter=A")
9797
);
9898
});
9999
});

tools/remark-linkcard/index.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ describe("remark-linkcard", () => {
3636
});
3737

3838
it("should decode " and '", () => {
39-
expect(decodeHtmlEntities('say "hello" and 'world'')).toBe(
40-
'say "hello" and \'world\''
39+
expect(decodeHtmlEntities("say "hello" and 'world'")).toBe(
40+
"say \"hello\" and 'world'"
4141
);
4242
});
4343

@@ -419,7 +419,7 @@ describe("remark-linkcard", () => {
419419
it("should escape HTML in data attributes", () => {
420420
const metadata = { ...baseMetadata, title: 'Test "quoted" title' };
421421
const html = generateHeadlessHtml(metadata, "link-card");
422-
expect(html).toContain("data-title=\"Test "quoted" title\"");
422+
expect(html).toContain('data-title="Test "quoted" title"');
423423
});
424424
});
425425

@@ -457,7 +457,7 @@ describe("remark-linkcard", () => {
457457
});
458458

459459
it("should escape HTML in URL", () => {
460-
const html = generateFallbackLinkHtml('https://example.com/path?q=<script>');
460+
const html = generateFallbackLinkHtml("https://example.com/path?q=<script>");
461461
expect(html).toContain("&lt;script&gt;");
462462
});
463463
});

0 commit comments

Comments
 (0)