Skip to content

Commit 187d321

Browse files
committed
Improve code format
1 parent 0df33ff commit 187d321

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

src/SettingTab.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ export class TodoistContextBridgeSettingTab extends PluginSettingTab {
155155
.setDesc(
156156
createFragment((frag) => {
157157
frag.appendText(
158-
"Remove dataview metadata fields from task text. Separate keys with commas. "
158+
"Remove dataview metadata fields from task text. Separate keys with commas. ",
159159
);
160160
frag.createEl("br");
161161
frag.createEl("br");
162162
frag.appendText(
163-
"Example: To remove fields like [created::2024-01-01] and [c::#tag], use: "
163+
"Example: To remove fields like [created::2024-01-01] and [c::#tag], use: ",
164164
);
165165
frag.createEl("code", {
166166
text: "created, c",
@@ -185,23 +185,26 @@ export class TodoistContextBridgeSettingTab extends PluginSettingTab {
185185
.setDesc(
186186
createFragment((frag) => {
187187
frag.appendText(
188-
"Remove timestamps with optional prefixes from task text. Separate patterns with commas. "
188+
"Remove timestamps with optional prefixes from task text. Separate patterns with commas. ",
189189
);
190190
frag.createEl("br");
191191
frag.createEl("br");
192192
frag.appendText(
193-
"Example: To remove timestamps like '📝 2024-01-01T10:30' and '❎ 2024-01-01T10:30', use: "
193+
"Example: To remove timestamps like '📝 2024-01-01T10:30' and '❎ 2024-01-01T10:30', use: ",
194194
);
195195
frag.createEl("code", {
196196
text: "[📝 ]YYYY-MM-DDTHH:mm, [❎ ]YYYY-MM-DDTHH:mm",
197197
});
198198
}),
199199
)
200200
.addTextArea((text) => {
201-
text.setPlaceholder("Enter Moment.js patterns, separated by commas")
201+
text.setPlaceholder(
202+
"Enter Moment.js patterns, separated by commas",
203+
)
202204
.setValue(this.plugin.settings.momentFormatCleanupPatterns)
203205
.onChange(async (value) => {
204-
this.plugin.settings.momentFormatCleanupPatterns = value;
206+
this.plugin.settings.momentFormatCleanupPatterns =
207+
value;
205208
await this.plugin.saveSettings();
206209
});
207210
text.inputEl.rows = 4;

src/TextParsing.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,31 +67,40 @@ export class TextParsing {
6767

6868
// Remove dataview cleanup keys if defined
6969
if (this.settings.dataviewCleanupKeys) {
70-
const keys = this.settings.dataviewCleanupKeys.split(",").map(key => key.trim());
70+
const keys = this.settings.dataviewCleanupKeys
71+
.split(",")
72+
.map((key) => key.trim());
7173
for (const key of keys) {
7274
if (key) {
7375
// Match any value after the key (including dates, text, tags, etc.)
7476
// Allow spaces around key, ::, and value
7577
// Allow tags (#) in both key and value
76-
const keyPattern = new RegExp(`\\[\\s*(?:#)?${key}(?:#[^\\s:\\]]+)*\\s*::\\s*([^\\]]*)\\s*\\]`, "g");
78+
const keyPattern = new RegExp(
79+
`\\[\\s*(?:#)?${key}(?:#[^\\s:\\]]+)*\\s*::\\s*([^\\]]*)\\s*\\]`,
80+
"g",
81+
);
7782
text = text.replace(keyPattern, "");
7883
}
7984
}
8085
}
8186

8287
// Remove Moment.js format patterns if defined
8388
if (this.settings.momentFormatCleanupPatterns) {
84-
const patterns = this.settings.momentFormatCleanupPatterns.split(",").map(pattern => pattern.trim());
89+
const patterns = this.settings.momentFormatCleanupPatterns
90+
.split(",")
91+
.map((pattern) => pattern.trim());
8592
for (const pattern of patterns) {
8693
if (pattern) {
8794
try {
8895
// Extract the prefix (text and emojis in brackets) and the Moment.js format
8996
const prefixMatch = pattern.match(/^\[(.*?)\]/);
9097
const prefix = prefixMatch ? prefixMatch[1] : "";
91-
const momentFormat = prefixMatch ? pattern.slice(prefixMatch[0].length) : pattern;
98+
const momentFormat = prefixMatch
99+
? pattern.slice(prefixMatch[0].length)
100+
: pattern;
92101

93102
// Convert Moment.js format to regex pattern
94-
let regexPattern = momentFormat
103+
const regexPattern = momentFormat
95104
.replace(/YYYY/g, "\\d{4}")
96105
.replace(/MM/g, "\\d{2}")
97106
.replace(/DD/g, "\\d{2}")
@@ -101,13 +110,16 @@ export class TextParsing {
101110
.replace(/T/g, "T");
102111

103112
// Create the full pattern with optional prefix
104-
const fullPattern = prefix ?
105-
new RegExp(`${prefix}\\s*${regexPattern}`, "g") :
106-
new RegExp(regexPattern, "g");
113+
const fullPattern = prefix
114+
? new RegExp(`${prefix}\\s*${regexPattern}`, "g")
115+
: new RegExp(regexPattern, "g");
107116

108117
text = text.replace(fullPattern, "");
109118
} catch (e) {
110-
console.warn(`Invalid Moment.js format pattern: ${pattern}`, e);
119+
console.warn(
120+
`Invalid Moment.js format pattern: ${pattern}`,
121+
e,
122+
);
111123
}
112124
}
113125
}

0 commit comments

Comments
 (0)