Skip to content

Commit 166c23c

Browse files
authored
Format with Biome (#213)
1 parent 3825c6b commit 166c23c

22 files changed

+259
-250
lines changed

.prettierignore

-3
This file was deleted.

.prettierrc.cjs

-16
This file was deleted.

biome.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
4+
"files": { "ignoreUnknown": false, "ignore": ["**/dist/**"] },
5+
"formatter": {
6+
"enabled": true,
7+
"useEditorconfig": true,
8+
"formatWithErrors": false,
9+
"indentStyle": "tab",
10+
"indentWidth": 2,
11+
"lineEnding": "lf",
12+
"lineWidth": 100,
13+
"attributePosition": "auto",
14+
"bracketSpacing": true,
15+
"ignore": [".github/workflows/**/*.yml", ".changeset/**/*.md", "**/pnpm-lock.yaml"]
16+
},
17+
"organizeImports": { "enabled": true },
18+
"linter": {
19+
"enabled": true,
20+
"rules": { "recommended": true, "suspicious": { "noExplicitAny": "off" } }
21+
},
22+
"javascript": {
23+
"formatter": {
24+
"jsxQuoteStyle": "double",
25+
"quoteProperties": "asNeeded",
26+
"trailingCommas": "es5",
27+
"semicolons": "always",
28+
"arrowParentheses": "always",
29+
"bracketSameLine": false,
30+
"quoteStyle": "single",
31+
"attributePosition": "auto",
32+
"bracketSpacing": true
33+
}
34+
},
35+
"overrides": [
36+
{
37+
"include": ["*.json", "*.toml", "*.yml"],
38+
"formatter": { "indentStyle": "space" }
39+
}
40+
]
41+
}

examples/basic/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async function main() {
8282
s.stop('Installed via pnpm');
8383
}
8484

85-
let nextSteps = `cd ${project.path} \n${project.install ? '' : 'pnpm install\n'}pnpm dev`;
85+
const nextSteps = `cd ${project.path} \n${project.install ? '' : 'pnpm install\n'}pnpm dev`;
8686

8787
p.note(nextSteps, 'Next steps.');
8888

examples/basic/spinner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ new Promise((resolve) => {
1717
spin.message(`Loading packages [${progress}/${total}]`); // <===
1818
}, 100);
1919
}).then(() => {
20-
spin.stop(`Done`);
20+
spin.stop('Done');
2121
p.outro('spinner stop...');
2222
});

examples/changesets/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function main() {
5959
(pkg) => !major.includes(pkg) && !minor.includes(pkg)
6060
);
6161
if (possiblePackages.length === 0) return;
62-
let note = possiblePackages.join(color.dim(', '));
62+
const note = possiblePackages.join(color.dim(', '));
6363

6464
p.log.step(`These packages will have a ${color.green('patch')} bump.\n${color.dim(note)}`);
6565
return possiblePackages;

package.json

+7-11
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,21 @@
44
"type": "module",
55
"scripts": {
66
"stub": "pnpm -r run build --stub",
7-
"build": "pnpm run build:core && pnpm run build:prompts",
8-
"build:core": "pnpm --filter @clack/core run build",
9-
"build:prompts": "pnpm --filter @clack/prompts run build",
10-
"start": "pnpm --filter @example/basic run start",
7+
"build": "pnpm --filter \"@clack/*\" run build",
8+
"start": "pnpm run dev",
119
"dev": "pnpm --filter @example/changesets run start",
12-
"format": "pnpm run /^format:.*/",
13-
"format:code": "prettier -w . --cache",
14-
"format:imports": "organize-imports-cli ./packages/*/tsconfig.json",
15-
"type-check": "tsc",
10+
"format": "biome format --write",
11+
"lint": "biome lint --write --unsafe",
12+
"type-check": "biome lint && tsc",
1613
"test": "pnpm -r run test",
1714
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
1815
"ci:publish": "changeset publish",
19-
"ci:format": "pnpm run format"
16+
"ci:format": "biome ci"
2017
},
2118
"devDependencies": {
19+
"@biomejs/biome": "1.9.4",
2220
"@changesets/cli": "^2.26.2",
2321
"@types/node": "^18.16.0",
24-
"organize-imports-cli": "^0.10.0",
25-
"prettier": "^3.0.2",
2622
"typescript": "^5.2.2",
2723
"unbuild": "^2.0.0"
2824
},

packages/core/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
"url": "https://github.com/natemoo-re/clack/issues"
2323
},
2424
"homepage": "https://github.com/natemoo-re/clack/tree/main/packages/core#readme",
25-
"files": [
26-
"dist",
27-
"CHANGELOG.md"
28-
],
25+
"files": ["dist", "CHANGELOG.md"],
2926
"keywords": [
3027
"ask",
3128
"clack",

packages/core/src/prompts/confirm.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cursor } from 'sisteransi';
2-
import Prompt, { PromptOptions } from './prompt';
2+
import Prompt, { type PromptOptions } from './prompt';
33

44
interface ConfirmOptions extends PromptOptions<ConfirmPrompt> {
55
active: string;
@@ -17,7 +17,7 @@ export default class ConfirmPrompt extends Prompt {
1717

1818
constructor(opts: ConfirmOptions) {
1919
super(opts, false);
20-
this.value = opts.initialValue ? true : false;
20+
this.value = !!opts.initialValue;
2121

2222
this.on('value', () => {
2323
this.value = this._value;

packages/core/src/prompts/group-multiselect.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Prompt, { PromptOptions } from './prompt';
1+
import Prompt, { type PromptOptions } from './prompt';
22

33
interface GroupMultiSelectOptions<T extends { value: any }>
44
extends PromptOptions<GroupMultiSelectPrompt<T>> {
@@ -9,7 +9,7 @@ interface GroupMultiSelectOptions<T extends { value: any }>
99
}
1010
export default class GroupMultiSelectPrompt<T extends { value: any }> extends Prompt {
1111
options: (T & { group: string | boolean })[];
12-
cursor: number = 0;
12+
cursor = 0;
1313

1414
getGroupItems(group: string): T[] {
1515
return this.options.filter((o) => o.group === group);

packages/core/src/prompts/multi-select.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Prompt, { PromptOptions } from './prompt';
1+
import Prompt, { type PromptOptions } from './prompt';
22

33
interface MultiSelectOptions<T extends { value: any }> extends PromptOptions<MultiSelectPrompt<T>> {
44
options: T[];
@@ -8,7 +8,7 @@ interface MultiSelectOptions<T extends { value: any }> extends PromptOptions<Mul
88
}
99
export default class MultiSelectPrompt<T extends { value: any }> extends Prompt {
1010
options: T[];
11-
cursor: number = 0;
11+
cursor = 0;
1212

1313
private get _value() {
1414
return this.options[this.cursor].value;

packages/core/src/prompts/password.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import color from 'picocolors';
2-
import Prompt, { PromptOptions } from './prompt';
2+
import Prompt, { type PromptOptions } from './prompt';
33

44
interface PasswordOptions extends PromptOptions<PasswordPrompt> {
55
mask?: string;

packages/core/src/prompts/prompt.ts

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { stdin, stdout } from 'node:process';
22
import readline, { type Key, type ReadLine } from 'node:readline';
3-
import { Readable, Writable } from 'node:stream';
3+
import type { Readable, Writable } from 'node:stream';
44
import { WriteStream } from 'node:tty';
55
import { cursor, erase } from 'sisteransi';
66
import wrap from 'wrap-ansi';
@@ -10,10 +10,10 @@ import { ALIASES, CANCEL_SYMBOL, diffLines, hasAliasKey, KEYS, setRawMode } from
1010
import type { ClackEvents, ClackState, InferSetType } from '../types';
1111

1212
export interface PromptOptions<Self extends Prompt> {
13-
render(this: Omit<Self, 'prompt'>): string | void;
13+
render(this: Omit<Self, 'prompt'>): string | undefined;
1414
placeholder?: string;
1515
initialValue?: any;
16-
validate?: ((value: any) => string | void) | undefined;
16+
validate?: ((value: any) => string | undefined) | undefined;
1717
input?: Readable;
1818
output?: Writable;
1919
debug?: boolean;
@@ -25,7 +25,7 @@ export default class Prompt {
2525

2626
private rl!: ReadLine;
2727
private opts: Omit<PromptOptions<Prompt>, 'render' | 'input' | 'output'>;
28-
private _render: (context: Omit<Prompt, 'prompt'>) => string | void;
28+
private _render: (context: Omit<Prompt, 'prompt'>) => string | undefined;
2929
private _track = false;
3030
private _prevFrame = '';
3131
private _subscribers = new Map<string, { cb: (...args: any) => any; once?: boolean }[]>();
@@ -35,7 +35,7 @@ export default class Prompt {
3535
public error = '';
3636
public value: any;
3737

38-
constructor(options: PromptOptions<Prompt>, trackValue: boolean = true) {
38+
constructor(options: PromptOptions<Prompt>, trackValue = true) {
3939
const { input = stdin, output = stdout, render, ...opts } = options;
4040

4141
this.opts = opts;
@@ -110,37 +110,37 @@ export default class Prompt {
110110
}
111111

112112
public prompt() {
113-
const sink = new WriteStream(0);
114-
sink._write = (chunk, encoding, done) => {
115-
if (this._track) {
116-
this.value = this.rl.line.replace(/\t/g, '');
117-
this._cursor = this.rl.cursor;
118-
this.emit('value', this.value);
119-
}
120-
done();
121-
};
122-
this.input.pipe(sink);
113+
return new Promise<string | symbol>((resolve, reject) => {
114+
const sink = new WriteStream(0);
115+
sink._write = (chunk, encoding, done) => {
116+
if (this._track) {
117+
this.value = this.rl.line.replace(/\t/g, '');
118+
this._cursor = this.rl.cursor;
119+
this.emit('value', this.value);
120+
}
121+
done();
122+
};
123+
this.input.pipe(sink);
123124

124-
this.rl = readline.createInterface({
125-
input: this.input,
126-
output: sink,
127-
tabSize: 2,
128-
prompt: '',
129-
escapeCodeTimeout: 50,
130-
});
131-
readline.emitKeypressEvents(this.input, this.rl);
132-
this.rl.prompt();
133-
if (this.opts.initialValue !== undefined && this._track) {
134-
this.rl.write(this.opts.initialValue);
135-
}
125+
this.rl = readline.createInterface({
126+
input: this.input,
127+
output: sink,
128+
tabSize: 2,
129+
prompt: '',
130+
escapeCodeTimeout: 50,
131+
});
132+
readline.emitKeypressEvents(this.input, this.rl);
133+
this.rl.prompt();
134+
if (this.opts.initialValue !== undefined && this._track) {
135+
this.rl.write(this.opts.initialValue);
136+
}
136137

137-
this.input.on('keypress', this.onKeypress);
138-
setRawMode(this.input, true);
139-
this.output.on('resize', this.render);
138+
this.input.on('keypress', this.onKeypress);
139+
setRawMode(this.input, true);
140+
this.output.on('resize', this.render);
140141

141-
this.render();
142+
this.render();
142143

143-
return new Promise<string | symbol>((resolve, reject) => {
144144
this.once('submit', () => {
145145
this.output.write(cursor.show);
146146
this.output.off('resize', this.render);
@@ -193,7 +193,7 @@ export default class Prompt {
193193
}
194194
}
195195

196-
if (hasAliasKey([key?.name, key?.sequence], 'cancel')) {
196+
if (hasAliasKey([char, key?.name, key?.sequence], 'cancel')) {
197197
this.state = 'cancel';
198198
}
199199
if (this.state === 'submit' || this.state === 'cancel') {
@@ -241,7 +241,8 @@ export default class Prompt {
241241
this.output.write(cursor.move(0, lines.length - diffLine - 1));
242242
return;
243243
// If many lines have changed, rerender everything past the first line
244-
} else if (diff && diff?.length > 1) {
244+
}
245+
if (diff && diff?.length > 1) {
245246
const diffLine = diff[0];
246247
this.output.write(cursor.move(0, diffLine));
247248
this.output.write(erase.down());

packages/core/src/prompts/select-key.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import Prompt, { PromptOptions } from './prompt';
1+
import Prompt, { type PromptOptions } from './prompt';
22

33
interface SelectKeyOptions<T extends { value: any }> extends PromptOptions<SelectKeyPrompt<T>> {
44
options: T[];
55
}
66
export default class SelectKeyPrompt<T extends { value: any }> extends Prompt {
77
options: T[];
8-
cursor: number = 0;
8+
cursor = 0;
99

1010
constructor(opts: SelectKeyOptions<T>) {
1111
super(opts, false);

packages/core/src/prompts/select.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import Prompt, { PromptOptions } from './prompt';
1+
import Prompt, { type PromptOptions } from './prompt';
22

33
interface SelectOptions<T extends { value: any }> extends PromptOptions<SelectPrompt<T>> {
44
options: T[];
55
initialValue?: T['value'];
66
}
77
export default class SelectPrompt<T extends { value: any }> extends Prompt {
88
options: T[];
9-
cursor: number = 0;
9+
cursor = 0;
1010

1111
private get _value() {
1212
return this.options[this.cursor];

packages/core/src/prompts/text.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import color from 'picocolors';
2-
import Prompt, { PromptOptions } from './prompt';
2+
import Prompt, { type PromptOptions } from './prompt';
33

44
export interface TextOptions extends PromptOptions<TextPrompt> {
55
placeholder?: string;

packages/core/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { KEYS } from './utils';
1+
import type { KEYS } from './utils';
22

33
export type InferSetType<T> = T extends Set<infer U> ? U : never;
44

packages/core/src/utils/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import type { Readable } from 'node:stream';
55
import { cursor } from 'sisteransi';
66
import { hasAliasKey } from './aliases';
77

8-
const isWindows = globalThis.process.platform.startsWith('win');
9-
108
export * from './aliases';
119
export * from './string';
1210

11+
const isWindows = globalThis.process.platform.startsWith('win');
12+
1313
export const CANCEL_SYMBOL = Symbol('clack:cancel');
1414

1515
export function isCancel(value: unknown): value is symbol {

packages/core/test/mock-writable.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Writable } from 'node:stream';
33
export class MockWritable extends Writable {
44
public buffer: string[] = [];
55

6-
// biome-ignore lint/suspicious/noExplicitAny: any is the official type
76
_write(
87
chunk: any,
98
encoding: BufferEncoding,

packages/prompts/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222
"url": "https://github.com/natemoo-re/clack/issues"
2323
},
2424
"homepage": "https://github.com/natemoo-re/clack/tree/main/packages/prompts#readme",
25-
"files": [
26-
"dist",
27-
"CHANGELOG.md"
28-
],
25+
"files": ["dist", "CHANGELOG.md"],
2926
"author": {
3027
"name": "Nate Moore",
3128
"email": "[email protected]",

0 commit comments

Comments
 (0)