Skip to content

Commit

Permalink
chore: update biome lint config
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Dec 5, 2024
1 parent 3fa30f5 commit c832e0a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 39 deletions.
10 changes: 2 additions & 8 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,15 @@
"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
},
"linter": {
"enabled": true,
"rules": {
"recommended": false,
"style": {
"useBlockStatements": "warn"
},
"suspicious": {
"noDoubleEquals": "warn"
}
"recommended": true
},
"ignore": ["dist"]
},
Expand Down
2 changes: 1 addition & 1 deletion src/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
51 changes: 26 additions & 25 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -107,11 +107,12 @@ function executeCommandInTerminal(command: string) {
}

class AliasView implements vscode.TreeDataProvider<AliasItem> {
private _onDidChangeTreeData: vscode.EventEmitter<AliasItem | undefined | null | void> = new vscode.EventEmitter<
AliasItem | undefined | null | void
private _onDidChangeTreeData: vscode.EventEmitter<AliasItem | undefined | null | undefined> = new vscode.EventEmitter<
AliasItem | undefined | null | undefined
>();

readonly onDidChangeTreeData: vscode.Event<AliasItem | undefined | null | void> = this._onDidChangeTreeData.event;
readonly onDidChangeTreeData: vscode.Event<AliasItem | undefined | null | undefined> =
this._onDidChangeTreeData.event;

globalState: vscode.Memento;

Expand Down Expand Up @@ -139,15 +140,15 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
return;
}

this.globalState.keys().forEach((groupName) => {
for (const groupName of this.globalState.keys()) {
const aliases = normalizeAliasesToArray<Alias>(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();
}
Expand Down Expand Up @@ -208,9 +209,9 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
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();
}
Expand All @@ -224,13 +225,13 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
deleteAliases(alias.data);

// remove all aliases under every groups
this.globalState.keys().forEach((groupName) => {
for (const groupName of this.globalState.keys()) {
const aliases = normalizeAliasesToArray<Alias>(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]));

Expand Down Expand Up @@ -260,15 +261,15 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
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<Alias>(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();
Expand All @@ -280,7 +281,7 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
}

const systemAliases = normalizeAliasesToArray<Alias>(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);
Expand Down Expand Up @@ -323,7 +324,7 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
}

const aliases = normalizeAliasesToArray<Alias>(this.globalState.get(alias.group)).filter(
(aliasItem) => !isSameAlias(alias.data!, aliasItem),
(aliasItem) => !isSameAlias(alias.data as Alias, aliasItem),
);

this.globalState.update(alias.group, aliases);
Expand Down Expand Up @@ -447,19 +448,19 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
getChildren(element?: AliasItem): Thenable<AliasItem[]> {
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<Alias>(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;
}, []);

Expand All @@ -468,17 +469,17 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
}
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,
Expand Down
2 changes: 1 addition & 1 deletion src/path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class StorePath {
private _path: string = '';
private _path = '';

get path() {
return this._path;
Expand Down
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isArray } from 'rattail';
import { Alias } from './types';
import type { Alias } from './types';

/**
* Check alias name or command is valid
Expand Down Expand Up @@ -90,7 +90,7 @@ export function resolveAlias(value: string): Omit<Alias, 'frequency' | 'descript
let command = '';
let hasEqual = false;

for (let char of formatValue) {
for (const char of formatValue) {
if (char === '=') {
hasEqual = true;
continue;
Expand Down Expand Up @@ -144,6 +144,6 @@ export function normalizeAliasesToArray<T>(value: T[] | undefined) {
*/
export function formatUnaliasCommand(aliases: Alias[]) {
return aliases.reduce((acc, alias) => {
return (acc += ` ${alias.aliasName}`);
return `${acc} ${alias.aliasName}`;
}, 'unalias');
}
2 changes: 1 addition & 1 deletion tests/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { Alias } from '../src/types';
import type { Alias } from '../src/types';
import { formatUnaliasCommand, isSameAlias, normalizeAliasesToArray, resolveAlias } from '../src/utils';

const alias = {
Expand Down

0 comments on commit c832e0a

Please sign in to comment.