Skip to content

Commit a88def2

Browse files
Copilotnilsandrey
andauthored
Fix code quality issues: sentence case, promise handling, deprecated functions, settings headings (#9)
* Fix all code quality issues from ESLint scan * adding an explicit rejection handle * Apply review feedback: fix deps, N label, fatal TextDecoder, catch async onSubmit errors --------- Signed-off-by: Nils <nilsandrey@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nilsandrey <3579285+nilsandrey@users.noreply.github.com>
1 parent a71e49f commit a88def2

8 files changed

Lines changed: 4694 additions & 274 deletions

File tree

eslint.config.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import tsparser from "@typescript-eslint/parser";
2+
import { defineConfig } from "eslint/config";
3+
import obsidianmd from "eslint-plugin-obsidianmd";
4+
import globals from "globals";
5+
6+
export default defineConfig([
7+
...obsidianmd.configs.recommended,
8+
{
9+
files: ["**/*.ts"],
10+
languageOptions: {
11+
parser: tsparser,
12+
parserOptions: { project: "./tsconfig.json" },
13+
globals: {
14+
...globals.browser,
15+
},
16+
},
17+
rules: {
18+
"obsidianmd/ui/sentence-case": [
19+
"error",
20+
{
21+
// Preserve these proper nouns/acronyms that are not in the default list
22+
ignoreWords: ["UTC", "ISO", "Unix", "GUIDs"],
23+
},
24+
],
25+
},
26+
},
27+
]);

main.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,18 +223,18 @@ export default class TextToolsPlugin extends Plugin {
223223

224224
this.addCommand({
225225
id: "join-n-lines",
226-
name: "Join every N lines",
226+
name: "Join every n lines",
227227
editorCallback: (editor) => {
228228
new TwoInputModal(this.app, {
229-
title: "Join every N lines",
230-
label1: "N (lines per group)",
229+
title: "Join every n lines",
230+
label1: "Number of lines per group",
231231
label2: "Glue",
232232
placeholder1: "2",
233233
placeholder2: " ",
234234
onSubmit: (nStr, glue) => {
235235
const n = parseInt(nStr, 10);
236236
if (!n || n < 1) {
237-
new Notice("N must be a positive integer.");
237+
new Notice("Enter a positive integer.");
238238
return;
239239
}
240240
transformSelections(editor, (t) => joinEveryNLines(t, n, glue));
@@ -796,7 +796,9 @@ export default class TextToolsPlugin extends Plugin {
796796
return;
797797
}
798798
this.settings.textSlots[idx] = texts.join("\n");
799-
this.saveSettings();
799+
void this.saveSettings().catch((error) => {
800+
console.error("Text Tools: failed to save settings", error);
801+
});
800802
new Notice(`Text slot ${i} set.`);
801803
},
802804
});
@@ -844,7 +846,7 @@ export default class TextToolsPlugin extends Plugin {
844846
// =========================================================================
845847

846848
async loadSettings() {
847-
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
849+
this.settings = Object.assign({}, DEFAULT_SETTINGS, (await this.loadData()) as Partial<TextToolsSettings>);
848850
}
849851

850852
async saveSettings() {

0 commit comments

Comments
 (0)