Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format with Biome #213

Merged
merged 13 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .prettierignore

This file was deleted.

16 changes: 0 additions & 16 deletions .prettierrc.cjs

This file was deleted.

41 changes: 41 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"vcs": { "enabled": false, "clientKind": "git", "useIgnoreFile": false },
"files": { "ignoreUnknown": false, "ignore": ["**/dist/**"] },
"formatter": {
"enabled": true,
"useEditorconfig": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 100,
"attributePosition": "auto",
"bracketSpacing": true,
"ignore": [".github/workflows/**/*.yml", ".changeset/**/*.md", "**/pnpm-lock.yaml"]
},
"organizeImports": { "enabled": true },
"linter": {
"enabled": true,
"rules": { "recommended": true, "suspicious": { "noExplicitAny": "off" } }
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "es5",
"semicolons": "always",
"arrowParentheses": "always",
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto",
"bracketSpacing": true
}
},
"overrides": [
{
"include": ["*.json", "*.toml", "*.yml"],
"formatter": { "indentStyle": "space" }
}
]
}
2 changes: 1 addition & 1 deletion examples/basic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function main() {
s.stop('Installed via pnpm');
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ new Promise((resolve) => {
spin.message(`Loading packages [${progress}/${total}]`); // <===
}, 100);
}).then(() => {
spin.stop(`Done`);
spin.stop('Done');
p.outro('spinner stop...');
});
2 changes: 1 addition & 1 deletion examples/changesets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async function main() {
(pkg) => !major.includes(pkg) && !minor.includes(pkg)
);
if (possiblePackages.length === 0) return;
let note = possiblePackages.join(color.dim(', '));
const note = possiblePackages.join(color.dim(', '));

p.log.step(`These packages will have a ${color.green('patch')} bump.\n${color.dim(note)}`);
return possiblePackages;
Expand Down
18 changes: 7 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@
"type": "module",
"scripts": {
"stub": "pnpm -r run build --stub",
"build": "pnpm run build:core && pnpm run build:prompts",
"build:core": "pnpm --filter @clack/core run build",
"build:prompts": "pnpm --filter @clack/prompts run build",
"start": "pnpm --filter @example/basic run start",
"build": "pnpm --filter \"@clack/*\" run build",
"start": "pnpm run dev",
"dev": "pnpm --filter @example/changesets run start",
"format": "pnpm run /^format:.*/",
"format:code": "prettier -w . --cache",
"format:imports": "organize-imports-cli ./packages/*/tsconfig.json",
"type-check": "tsc",
"format": "biome format --write",
"lint": "biome lint --write --unsafe",
"type-check": "biome lint && tsc",
"test": "pnpm -r run test",
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
"ci:publish": "changeset publish",
"ci:format": "pnpm run format"
"ci:format": "biome ci"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@changesets/cli": "^2.26.2",
"@types/node": "^18.16.0",
"organize-imports-cli": "^0.10.0",
"prettier": "^3.0.2",
"typescript": "^5.2.2",
"unbuild": "^2.0.0"
},
Expand Down
5 changes: 1 addition & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
"url": "https://github.com/natemoo-re/clack/issues"
},
"homepage": "https://github.com/natemoo-re/clack/tree/main/packages/core#readme",
"files": [
"dist",
"CHANGELOG.md"
],
"files": ["dist", "CHANGELOG.md"],
"keywords": [
"ask",
"clack",
Expand Down
1 change: 0 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export { default as SelectKeyPrompt } from './prompts/select-key';
export { default as TextPrompt } from './prompts/text';
export type { ClackState as State } from './types';
export { block, isCancel, setGlobalAliases } from './utils';

4 changes: 2 additions & 2 deletions packages/core/src/prompts/confirm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cursor } from 'sisteransi';
import Prompt, { PromptOptions } from './prompt';
import Prompt, { type PromptOptions } from './prompt';

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

constructor(opts: ConfirmOptions) {
super(opts, false);
this.value = opts.initialValue ? true : false;
this.value = !!opts.initialValue;

this.on('value', () => {
this.value = this._value;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/prompts/group-multiselect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Prompt, { PromptOptions } from './prompt';
import Prompt, { type PromptOptions } from './prompt';

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

getGroupItems(group: string): T[] {
return this.options.filter((o) => o.group === group);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/prompts/multi-select.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Prompt, { PromptOptions } from './prompt';
import Prompt, { type PromptOptions } from './prompt';

interface MultiSelectOptions<T extends { value: any }> extends PromptOptions<MultiSelectPrompt<T>> {
options: T[];
Expand All @@ -8,7 +8,7 @@ interface MultiSelectOptions<T extends { value: any }> extends PromptOptions<Mul
}
export default class MultiSelectPrompt<T extends { value: any }> extends Prompt {
options: T[];
cursor: number = 0;
cursor = 0;

private get _value() {
return this.options[this.cursor].value;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/prompts/password.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'picocolors';
import Prompt, { PromptOptions } from './prompt';
import Prompt, { type PromptOptions } from './prompt';

interface PasswordOptions extends PromptOptions<PasswordPrompt> {
mask?: string;
Expand Down
69 changes: 35 additions & 34 deletions packages/core/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stdin, stdout } from 'node:process';
import readline, { type Key, type ReadLine } from 'node:readline';
import { Readable, Writable } from 'node:stream';
import type { Readable, Writable } from 'node:stream';
import { WriteStream } from 'node:tty';
import { cursor, erase } from 'sisteransi';
import wrap from 'wrap-ansi';
Expand All @@ -10,10 +10,10 @@ import { ALIASES, CANCEL_SYMBOL, diffLines, hasAliasKey, KEYS, setRawMode } from
import type { ClackEvents, ClackState, InferSetType } from '../types';

export interface PromptOptions<Self extends Prompt> {
render(this: Omit<Self, 'prompt'>): string | void;
render(this: Omit<Self, 'prompt'>): string | undefined;
placeholder?: string;
initialValue?: any;
validate?: ((value: any) => string | void) | undefined;
validate?: ((value: any) => string | undefined) | undefined;
input?: Readable;
output?: Writable;
debug?: boolean;
Expand All @@ -25,7 +25,7 @@ export default class Prompt {

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

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

this.opts = opts;
Expand Down Expand Up @@ -110,37 +110,37 @@ export default class Prompt {
}

public prompt() {
const sink = new WriteStream(0);
sink._write = (chunk, encoding, done) => {
if (this._track) {
this.value = this.rl.line.replace(/\t/g, '');
this._cursor = this.rl.cursor;
this.emit('value', this.value);
}
done();
};
this.input.pipe(sink);
return new Promise<string | symbol>((resolve, reject) => {
const sink = new WriteStream(0);
sink._write = (chunk, encoding, done) => {
if (this._track) {
this.value = this.rl.line.replace(/\t/g, '');
this._cursor = this.rl.cursor;
this.emit('value', this.value);
}
done();
};
this.input.pipe(sink);

this.rl = readline.createInterface({
input: this.input,
output: sink,
tabSize: 2,
prompt: '',
escapeCodeTimeout: 50,
});
readline.emitKeypressEvents(this.input, this.rl);
this.rl.prompt();
if (this.opts.initialValue !== undefined && this._track) {
this.rl.write(this.opts.initialValue);
}
this.rl = readline.createInterface({
input: this.input,
output: sink,
tabSize: 2,
prompt: '',
escapeCodeTimeout: 50,
});
readline.emitKeypressEvents(this.input, this.rl);
this.rl.prompt();
if (this.opts.initialValue !== undefined && this._track) {
this.rl.write(this.opts.initialValue);
}

this.input.on('keypress', this.onKeypress);
setRawMode(this.input, true);
this.output.on('resize', this.render);
this.input.on('keypress', this.onKeypress);
setRawMode(this.input, true);
this.output.on('resize', this.render);

this.render();
this.render();

return new Promise<string | symbol>((resolve, reject) => {
this.once('submit', () => {
this.output.write(cursor.show);
this.output.off('resize', this.render);
Expand Down Expand Up @@ -193,7 +193,7 @@ export default class Prompt {
}
}

if (hasAliasKey([key?.name, key?.sequence], 'cancel')) {
if (hasAliasKey([char, key?.name, key?.sequence], 'cancel')) {
this.state = 'cancel';
}
if (this.state === 'submit' || this.state === 'cancel') {
Expand Down Expand Up @@ -241,7 +241,8 @@ export default class Prompt {
this.output.write(cursor.move(0, lines.length - diffLine - 1));
return;
// If many lines have changed, rerender everything past the first line
} else if (diff && diff?.length > 1) {
}
if (diff && diff?.length > 1) {
const diffLine = diff[0];
this.output.write(cursor.move(0, diffLine));
this.output.write(erase.down());
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/prompts/select-key.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Prompt, { PromptOptions } from './prompt';
import Prompt, { type PromptOptions } from './prompt';

interface SelectKeyOptions<T extends { value: any }> extends PromptOptions<SelectKeyPrompt<T>> {
options: T[];
}
export default class SelectKeyPrompt<T extends { value: any }> extends Prompt {
options: T[];
cursor: number = 0;
cursor = 0;

constructor(opts: SelectKeyOptions<T>) {
super(opts, false);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/prompts/select.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Prompt, { PromptOptions } from './prompt';
import Prompt, { type PromptOptions } from './prompt';

interface SelectOptions<T extends { value: any }> extends PromptOptions<SelectPrompt<T>> {
options: T[];
initialValue?: T['value'];
}
export default class SelectPrompt<T extends { value: any }> extends Prompt {
options: T[];
cursor: number = 0;
cursor = 0;

private get _value() {
return this.options[this.cursor];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/prompts/text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import color from 'picocolors';
import Prompt, { PromptOptions } from './prompt';
import Prompt, { type PromptOptions } from './prompt';

export interface TextOptions extends PromptOptions<TextPrompt> {
placeholder?: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KEYS } from './utils';
import type { KEYS } from './utils';

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

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type { Readable } from 'node:stream';
import { cursor } from 'sisteransi';
import { hasAliasKey } from './aliases';

const isWindows = globalThis.process.platform.startsWith('win');

export * from './aliases';
export * from './string';

const isWindows = globalThis.process.platform.startsWith('win');

export const CANCEL_SYMBOL = Symbol('clack:cancel');

export function isCancel(value: unknown): value is symbol {
Expand Down
1 change: 0 additions & 1 deletion packages/core/test/mock-writable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Writable } from 'node:stream';
export class MockWritable extends Writable {
public buffer: string[] = [];

// biome-ignore lint/suspicious/noExplicitAny: any is the official type
_write(
chunk: any,
encoding: BufferEncoding,
Expand Down
5 changes: 1 addition & 4 deletions packages/prompts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
"url": "https://github.com/natemoo-re/clack/issues"
},
"homepage": "https://github.com/natemoo-re/clack/tree/main/packages/prompts#readme",
"files": [
"dist",
"CHANGELOG.md"
],
"files": ["dist", "CHANGELOG.md"],
"author": {
"name": "Nate Moore",
"email": "[email protected]",
Expand Down
Loading
Loading