From c832e0a98888b8d326265e9980010130e0c29c62 Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Thu, 5 Dec 2024 10:35:22 +0800 Subject: [PATCH] chore: update biome lint config --- biome.json | 10 ++------- src/aliases.ts | 2 +- src/extension.ts | 51 +++++++++++++++++++++++---------------------- src/path.ts | 2 +- src/utils.ts | 6 +++--- tests/utils.spec.ts | 2 +- 6 files changed, 34 insertions(+), 39 deletions(-) diff --git a/biome.json b/biome.json index 2c05c6e..2ec1e98 100644 --- a/biome.json +++ b/biome.json @@ -19,7 +19,7 @@ "lineWidth": 120, "attributePosition": "auto", "bracketSpacing": true, - "ignore": ["pnpm-lock.yaml", "node_modules", ".vscode", "l10n", "package*.json"] + "ignore": ["pnpm-lock.yaml", ".vscode", "l10n", "package*.json"] }, "organizeImports": { "enabled": true @@ -27,13 +27,7 @@ "linter": { "enabled": true, "rules": { - "recommended": false, - "style": { - "useBlockStatements": "warn" - }, - "suspicious": { - "noDoubleEquals": "warn" - } + "recommended": true }, "ignore": ["dist"] }, diff --git a/src/aliases.ts b/src/aliases.ts index 46c9345..becd5a3 100644 --- a/src/aliases.ts +++ b/src/aliases.ts @@ -2,7 +2,7 @@ import { exec } from 'node:child_process'; import fs from 'node:fs'; import { isEmpty } from 'rattail'; import storePath from './path'; -import { Alias } from './types'; +import type { Alias } from './types'; import { isSameAlias, resolveAlias } from './utils'; function reloadStoreFile() { diff --git a/src/extension.ts b/src/extension.ts index c5b4938..0d35774 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -5,7 +5,7 @@ import * as vscode from 'vscode'; import { appendAliasToStoreFile, deleteAliases, getAliases, renameAliases } from './aliases'; import { SYSTEM_ALIAS } from './constants'; import storePath from './path'; -import { Alias } from './types'; +import type { Alias } from './types'; import { formatUnaliasCommand, isSameAlias, normalizeAliasesToArray, resolveAlias } from './utils'; function setTooltip(frequency = 0) { @@ -107,11 +107,12 @@ function executeCommandInTerminal(command: string) { } class AliasView implements vscode.TreeDataProvider { - private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter< - AliasItem | undefined | null | void + private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter< + AliasItem | undefined | null | undefined >(); - readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + readonly onDidChangeTreeData: vscode.Event = + this._onDidChangeTreeData.event; globalState: vscode.Memento; @@ -139,15 +140,15 @@ class AliasView implements vscode.TreeDataProvider { return; } - this.globalState.keys().forEach((groupName) => { + for (const groupName of this.globalState.keys()) { const aliases = normalizeAliasesToArray(this.globalState.get(groupName)); - const sameAlias = aliases.find((aliasItem) => isSameAlias(alias.data!, aliasItem)); + const sameAlias = aliases.find((aliasItem) => isSameAlias(alias.data as Alias, aliasItem)); if (sameAlias) { sameAlias.description = description; this.globalState.update(groupName, aliases); } - }); + } this.refresh(); } @@ -208,9 +209,9 @@ class AliasView implements vscode.TreeDataProvider { deleteAliases(); // remove all aliases under every groups - this.globalState.keys().forEach((group) => { - this.globalState.update(group, []); - }); + for (const groupName of this.globalState.keys()) { + this.globalState.update(groupName, []); + } this.refresh(); } @@ -224,13 +225,13 @@ class AliasView implements vscode.TreeDataProvider { deleteAliases(alias.data); // remove all aliases under every groups - this.globalState.keys().forEach((groupName) => { + for (const groupName of this.globalState.keys()) { const aliases = normalizeAliasesToArray(this.globalState.get(groupName)).filter( - (aliasItem) => !isSameAlias(alias.data!, aliasItem), + (aliasItem) => !isSameAlias(alias.data as Alias, aliasItem), ); this.globalState.update(groupName, aliases); - }); + } executeCommandInTerminal(formatUnaliasCommand([alias.data])); @@ -260,15 +261,15 @@ class AliasView implements vscode.TreeDataProvider { renameAliases(alias.data, command); // rename one alias under every groups - this.globalState.keys().forEach((groupName) => { + for (const groupName of this.globalState.keys()) { const aliases = normalizeAliasesToArray(this.globalState.get(groupName)); - const sameAlias = aliases.find((aliasItem) => isSameAlias(alias.data!, aliasItem)); + const sameAlias = aliases.find((aliasItem) => isSameAlias(alias.data as Alias, aliasItem)); if (sameAlias) { sameAlias.command = command; this.globalState.update(groupName, aliases); } - }); + } executeCommandInTerminal(`alias ${alias.data.aliasName}='${command}'`); this.refresh(); @@ -280,7 +281,7 @@ class AliasView implements vscode.TreeDataProvider { } const systemAliases = normalizeAliasesToArray(this.globalState.get(alias.group)); - const runAlias = systemAliases.find((systemAlias) => isSameAlias(alias.data!, systemAlias)); + const runAlias = systemAliases.find((systemAlias) => isSameAlias(alias.data as Alias, systemAlias)); if (runAlias) { runAlias.frequency = (runAlias.frequency ?? 0) + 1; this.globalState.update(alias.group, systemAliases); @@ -323,7 +324,7 @@ class AliasView implements vscode.TreeDataProvider { } const aliases = normalizeAliasesToArray(this.globalState.get(alias.group)).filter( - (aliasItem) => !isSameAlias(alias.data!, aliasItem), + (aliasItem) => !isSameAlias(alias.data as Alias, aliasItem), ); this.globalState.update(alias.group, aliases); @@ -447,19 +448,19 @@ class AliasView implements vscode.TreeDataProvider { getChildren(element?: AliasItem): Thenable { if (element) { return Promise.resolve(element.children); - } else { - return Promise.resolve(this.getAliasTree()); } + + return Promise.resolve(this.getAliasTree()); } private getAliasTree(): AliasItem[] { const aliasTree = this.globalState.keys().reduce((aliases: AliasItem[], key: string) => { const children = normalizeAliasesToArray(this.globalState.get(key)).map((alias) => { const { aliasName, command, description = '' } = alias; - return new AliasItem(`${aliasName} = '${command}'`, [], alias, true, key, description); + return new AliasItem(`${aliasName} = '${command}'`, alias, key, description, [], true); }); - aliases.push(new AliasItem(key, children, undefined, false, key, '')); + aliases.push(new AliasItem(key, undefined, key, '', children, false)); return aliases; }, []); @@ -468,17 +469,17 @@ class AliasView implements vscode.TreeDataProvider { } class AliasItem extends vscode.TreeItem { contextValue = 'alias_child'; - description: string = ''; + description = ''; data: Alias | undefined = undefined; groupName: string; constructor( public readonly label: string, - public readonly children: AliasItem[] = [], public readonly alias: Alias | undefined, - public readonly isLeafNode: boolean = true, public readonly group: string, public readonly remark: string, + public readonly children: AliasItem[] = [], + public readonly isLeafNode: boolean = true, ) { super( label, diff --git a/src/path.ts b/src/path.ts index 9f8c542..9e4d5b9 100644 --- a/src/path.ts +++ b/src/path.ts @@ -1,5 +1,5 @@ class StorePath { - private _path: string = ''; + private _path = ''; get path() { return this._path; diff --git a/src/utils.ts b/src/utils.ts index 8f1f238..ba754ed 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,5 +1,5 @@ import { isArray } from 'rattail'; -import { Alias } from './types'; +import type { Alias } from './types'; /** * Check alias name or command is valid @@ -90,7 +90,7 @@ export function resolveAlias(value: string): Omit