fix: 修复 ObsidianReviewBot 指出的代码问

题

fix: CacheData

fix: i18n/index

fix: UI text
This commit is contained in:
lu 2026-04-17 01:28:01 +08:00
parent 7545b34a98
commit 76fd5cdb46
6 changed files with 67 additions and 63 deletions

View file

@ -1,19 +1,11 @@
// eslint.config.mjs - 与 ObsidianReviewBot 检查规范完全一致
// eslint.config.mjs
import tsparser from "@typescript-eslint/parser";
import { defineConfig } from "eslint/config";
import obsidianmd from "eslint-plugin-obsidianmd";
import globals from "globals";
export default defineConfig([
// 忽略文件
{
ignores: ["**/node_modules/", "**/main.js", "**/esbuild.config.mjs"],
},
// 使用 obsidianmd 推荐配置(包含 typescript-eslint recommended + obsidianmd 规范)
...obsidianmd.configs.recommended,
// 补充 obsidianmd 未提供的 globals
...obsidianmd.configs.recommendedWithLocalesEn,
{
files: ["**/*.ts"],
languageOptions: {
@ -21,7 +13,6 @@ export default defineConfig([
parserOptions: { project: "./tsconfig.json" },
globals: {
...globals.browser,
...globals.es2020,
console: "readonly",
window: "readonly",
document: "readonly",
@ -32,4 +23,17 @@ export default defineConfig([
},
},
},
{
rules: {
"obsidianmd/ui/sentence-case-locale-module": [
"warn",
{
// 忽略技术术语和专有名词(按单词匹配,不是完整短语)
ignoreWords: [
],
},
],
},
},
]);

50
main.js
View file

@ -75,11 +75,11 @@ var en = {
title: "Note heatmap settings",
targetField: {
name: "Target field",
desc: "Frontmatter field name for tracking modification dates. Supports single value or list. Field value format: ISO 8601 (e.g., 2026-04-14T10:30:00), YYYY-MM-DD (e.g., 2026-04-14), or Obsidian date object"
desc: "Frontmatter field name for tracking modification dates. Supports single value or list."
},
createdField: {
name: "Created field",
desc: "Frontmatter field name for determining if a note is new. Field value format: ISO 8601, YYYY-MM-DD, or Obsidian date object. Falls back to file creation time if not set"
desc: "Frontmatter field name for determining if a note is new. "
},
targetFolder: {
name: "Target folder",
@ -89,7 +89,7 @@ var en = {
// Settings - Colors
colors: {
title: "Color configuration",
desc: "From left to right: No edits / 1-3 notes / 4-7 notes / 8-12 notes / 13+ notes",
desc: "From left to right: no edits / 1-3 notes / 4-7 notes / 8-12 notes / 13+ notes.",
labels: [
"No edits (0)",
"Light green (1-3)",
@ -111,7 +111,7 @@ var en = {
},
format: {
name: "File format",
desc: "File path format for yearly notes, based on the folder above. Format: YYYY (year). Content in [brackets] is output as-is",
desc: "File path format for yearly notes, based on the folder above.",
placeholder: "YYYY"
}
},
@ -125,8 +125,8 @@ var en = {
},
format: {
name: "File format",
desc: "File path format for daily notes, based on the folder above. Format: YYYY (year), MM (month), DD (day). Content in [brackets] is output as-is",
placeholder: "YYYY-[daily]/YYYY-MM-[daily]/YYYY-MM-DD"
desc: "File path format for daily notes, based on the folder above. ",
placeholder: ""
}
},
monthly: {
@ -139,8 +139,8 @@ var en = {
},
format: {
name: "File format",
desc: "File path format for monthly notes, based on the folder above. Format: YYYY (year), MM (month). Content in [brackets] is output as-is",
placeholder: "YYYY-[monthly]/YYYY-MM"
desc: "File path format for monthly notes, based on the folder above.",
placeholder: ""
}
}
},
@ -149,12 +149,12 @@ var en = {
title: "Git diff feature",
enable: {
name: "Enable Git diff feature",
descAllAvailable: "\u2705 All dependencies installed. Requires: Obsidian Git + Version History Diff",
descMissingObsidianGit: "\u26A0\uFE0F Missing",
descMissingVHD: "\u26A0\uFE0F Missing",
descMissingBoth: "\u26A0\uFE0F Missing both dependencies:",
descAllAvailable: "\u2705 all dependencies installed(Git and version-history-diff).",
descMissingObsidianGit: "\u26A0\uFE0F missing",
descMissingVHD: "\u26A0\uFE0F missing",
descMissingBoth: "\u26A0\uFE0F missing both dependencies:",
pluginObsidianGit: "Obsidian Git",
pluginVHD: "Version History Diff",
pluginVHD: "Plugin version-history-diff",
separator: " + "
}
},
@ -191,14 +191,14 @@ var en = {
},
// Result Panel
resultPanel: {
hint: "\u{1F4A1} Click a square above to view edits for that day",
hint: "\u{1F4A1} click a square above to view edits for that day",
noEdits: "No edits for this day",
noEditsMonth: "No edits for this month",
close: "Close file list",
totalEdits: "{{total}} edits, {{new}} new",
diffButton: "View diff",
vhdButton: "View diff",
searchPlaceholder: "\u{1F50D} Search note names...",
searchPlaceholder: "\u{1F50D} search note names...",
sortBy: {
name: "Name",
activeDays: "Active days",
@ -208,10 +208,10 @@ var en = {
},
// Git Service
git: {
installNotice: "\u{1F4A1} Install Obsidian Git plugin to view detailed diff",
installNotice: "\u{1F4A1} install the Obsidian Git plugin to view detailed diff",
noCommits: "No commits found",
vhdNotInstalled: "Version History Diff plugin is not installed or enabled",
vhdOpenFailed: "Failed to open Version History Diff"
vhdNotInstalled: "Plugin version-history-diff is not installed or enabled",
vhdOpenFailed: "Failed to open version-history-diff plugin."
}
};
@ -258,8 +258,8 @@ var zh = {
},
format: {
name: "\u6587\u4EF6\u683C\u5F0F",
desc: "\u5E74\u5EA6\u7B14\u8BB0\u7684\u6587\u4EF6\u8DEF\u5F84\u683C\u5F0F\uFF0C\u57FA\u4E8E\u4E0A\u8FF0\u6587\u4EF6\u5939\u3002\u683C\u5F0F\u8BF4\u660E\uFF1AYYYY\uFF08\u5E74\uFF09\u3002\u65B9\u62EC\u53F7 [text] \u4E2D\u7684\u5185\u5BB9\u539F\u6837\u8F93\u51FA",
placeholder: "YYYY"
desc: "\u5E74\u5EA6\u7B14\u8BB0\u7684\u6587\u4EF6\u8DEF\u5F84\u683C\u5F0F\uFF0C\u57FA\u4E8E\u4E0A\u8FF0\u6587\u4EF6\u5939\u3002",
placeholder: ""
}
},
daily: {
@ -272,8 +272,8 @@ var zh = {
},
format: {
name: "\u6587\u4EF6\u683C\u5F0F",
desc: "\u6BCF\u65E5\u7B14\u8BB0\u7684\u6587\u4EF6\u8DEF\u5F84\u683C\u5F0F\uFF0C\u57FA\u4E8E\u4E0A\u8FF0\u6587\u4EF6\u5939\u3002\u683C\u5F0F\u8BF4\u660E\uFF1AYYYY\uFF08\u5E74\uFF09\u3001MM\uFF08\u6708\uFF09\u3001DD\uFF08\u65E5\uFF09\u3002\u65B9\u62EC\u53F7 [text] \u4E2D\u7684\u5185\u5BB9\u539F\u6837\u8F93\u51FA",
placeholder: "YYYY-[daily]/YYYY-MM-[daily]/YYYY-MM-DD"
desc: "\u6BCF\u65E5\u7B14\u8BB0\u7684\u6587\u4EF6\u8DEF\u5F84\u683C\u5F0F\uFF0C\u57FA\u4E8E\u4E0A\u8FF0\u6587\u4EF6\u5939\u3002",
placeholder: ""
}
},
monthly: {
@ -286,8 +286,8 @@ var zh = {
},
format: {
name: "\u6587\u4EF6\u683C\u5F0F",
desc: "\u6708\u5EA6\u7B14\u8BB0\u7684\u6587\u4EF6\u8DEF\u5F84\u683C\u5F0F\uFF0C\u57FA\u4E8E\u4E0A\u8FF0\u6587\u4EF6\u5939\u3002\u683C\u5F0F\u8BF4\u660E\uFF1AYYYY\uFF08\u5E74\uFF09\u3001MM\uFF08\u6708\uFF09\u3002\u65B9\u62EC\u53F7 [text] \u4E2D\u7684\u5185\u5BB9\u539F\u6837\u8F93\u51FA",
placeholder: "YYYY-[monthly]/YYYY-MM"
desc: "\u6708\u5EA6\u7B14\u8BB0\u7684\u6587\u4EF6\u8DEF\u5F84\u683C\u5F0F\uFF0C\u57FA\u4E8E\u4E0A\u8FF0\u6587\u4EF6\u5939\u3002",
placeholder: ""
}
}
},
@ -1599,7 +1599,7 @@ var DataCache = class extends import_obsidian3.Component {
* 获取指定年份的数据
*/
getYearData(year) {
return this.cache[year] || {};
return this.cache[String(year)] || {};
}
/**
* 检查缓存是否已初始化

View file

@ -13,7 +13,7 @@ export interface YearData {
}
export interface CacheData {
[year: number]: YearData;
[year: string]: YearData;
}
function parseDateString(val: unknown): string | null {
@ -345,7 +345,7 @@ export class DataCache extends Component {
*
*/
getYearData(year: number): YearData {
return this.cache[year] || {};
return this.cache[String(year)] || {};
}
/**

View file

@ -4,11 +4,11 @@ export const en = {
title: "Note heatmap settings",
targetField: {
name: "Target field",
desc: "Frontmatter field name for tracking modification dates. Supports single value or list. Field value format: ISO 8601 (e.g., 2026-04-14T10:30:00), YYYY-MM-DD (e.g., 2026-04-14), or Obsidian date object",
desc: "Frontmatter field name for tracking modification dates. Supports single value or list.",
},
createdField: {
name: "Created field",
desc: "Frontmatter field name for determining if a note is new. Field value format: ISO 8601, YYYY-MM-DD, or Obsidian date object. Falls back to file creation time if not set",
desc: "Frontmatter field name for determining if a note is new. ",
},
targetFolder: {
name: "Target folder",
@ -19,7 +19,7 @@ export const en = {
// Settings - Colors
colors: {
title: "Color configuration",
desc: "From left to right: No edits / 1-3 notes / 4-7 notes / 8-12 notes / 13+ notes",
desc: "From left to right: no edits / 1-3 notes / 4-7 notes / 8-12 notes / 13+ notes.",
labels: [
"No edits (0)",
"Light green (1-3)",
@ -42,7 +42,7 @@ export const en = {
},
format: {
name: "File format",
desc: "File path format for yearly notes, based on the folder above. Format: YYYY (year). Content in [brackets] is output as-is",
desc: "File path format for yearly notes, based on the folder above.",
placeholder: "YYYY",
},
},
@ -56,8 +56,8 @@ export const en = {
},
format: {
name: "File format",
desc: "File path format for daily notes, based on the folder above. Format: YYYY (year), MM (month), DD (day). Content in [brackets] is output as-is",
placeholder: "YYYY-[daily]/YYYY-MM-[daily]/YYYY-MM-DD",
desc: "File path format for daily notes, based on the folder above. ",
placeholder: "",
},
},
monthly: {
@ -70,8 +70,8 @@ export const en = {
},
format: {
name: "File format",
desc: "File path format for monthly notes, based on the folder above. Format: YYYY (year), MM (month). Content in [brackets] is output as-is",
placeholder: "YYYY-[monthly]/YYYY-MM",
desc: "File path format for monthly notes, based on the folder above.",
placeholder: "",
},
},
},
@ -81,12 +81,12 @@ export const en = {
title: "Git diff feature",
enable: {
name: "Enable Git diff feature",
descAllAvailable: "✅ All dependencies installed. Requires: Obsidian Git + Version History Diff",
descMissingObsidianGit: "⚠️ Missing",
descMissingVHD: "⚠️ Missing",
descMissingBoth: "⚠️ Missing both dependencies:",
descAllAvailable: "✅ all dependencies installed(Git and version-history-diff).",
descMissingObsidianGit: "⚠️ missing",
descMissingVHD: "⚠️ missing",
descMissingBoth: "⚠️ missing both dependencies:",
pluginObsidianGit: "Obsidian Git",
pluginVHD: "Version History Diff",
pluginVHD: "Plugin version-history-diff",
separator: " + ",
},
},
@ -127,14 +127,14 @@ export const en = {
// Result Panel
resultPanel: {
hint: "💡 Click a square above to view edits for that day",
hint: "💡 click a square above to view edits for that day",
noEdits: "No edits for this day",
noEditsMonth: "No edits for this month",
close: "Close file list",
totalEdits: "{{total}} edits, {{new}} new",
diffButton: "View diff",
vhdButton: "View diff",
searchPlaceholder: "🔍 Search note names...",
searchPlaceholder: "🔍 search note names...",
sortBy: {
name: "Name",
activeDays: "Active days",
@ -145,10 +145,10 @@ export const en = {
// Git Service
git: {
installNotice: "💡 Install Obsidian Git plugin to view detailed diff",
installNotice: "💡 install the Obsidian Git plugin to view detailed diff",
noCommits: "No commits found",
vhdNotInstalled: "Version History Diff plugin is not installed or enabled",
vhdOpenFailed: "Failed to open Version History Diff",
vhdNotInstalled: "Plugin version-history-diff is not installed or enabled",
vhdOpenFailed: "Failed to open version-history-diff plugin.",
},
};

View file

@ -53,7 +53,7 @@ export function t(key: string, vars?: Record<string, string | number>): string {
// 变量替换
if (vars) {
return value.replace(/\{\{(\w+)\}\}/g, (match, varName) => {
return vars[varName]?.toString() ?? match;
return vars[varName as keyof typeof vars]?.toString() ?? match;
});
}

View file

@ -44,8 +44,8 @@ export const zh: Translations = {
},
format: {
name: "文件格式",
desc: "年度笔记的文件路径格式,基于上述文件夹。格式说明YYYY。方括号 [text] 中的内容原样输出",
placeholder: "YYYY",
desc: "年度笔记的文件路径格式,基于上述文件夹。",
placeholder: "",
},
},
daily: {
@ -58,8 +58,8 @@ export const zh: Translations = {
},
format: {
name: "文件格式",
desc: "每日笔记的文件路径格式,基于上述文件夹。格式说明YYYY、MM、DD。方括号 [text] 中的内容原样输出",
placeholder: "YYYY-[daily]/YYYY-MM-[daily]/YYYY-MM-DD",
desc: "每日笔记的文件路径格式,基于上述文件夹。",
placeholder: "",
},
},
monthly: {
@ -72,8 +72,8 @@ export const zh: Translations = {
},
format: {
name: "文件格式",
desc: "月度笔记的文件路径格式,基于上述文件夹。格式说明YYYY、MM。方括号 [text] 中的内容原样输出",
placeholder: "YYYY-[monthly]/YYYY-MM",
desc: "月度笔记的文件路径格式,基于上述文件夹。",
placeholder: "",
},
},
},