Skip to content

Commit e3f5833

Browse files
authored
chore: update oxfmt config (#32)
* wip * Update oxfmtrc.json * chore: update oxfmt config * chore: extract publint into a separate command * add changeset
1 parent 677b2e0 commit e3f5833

22 files changed

Lines changed: 268 additions & 249 deletions

.changeset/silly-foxes-protect.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@bomb.sh/tools": minor
3+
---
4+
5+
Updatess `oxfmt` config:
6+
7+
- Sets `"singleQuote"` option to `true`
8+
- Adds `"*.json", "*.md", "*.yml", "*.jsonc"` to `"ignorePatterns"` option
9+
10+
Updates `format` command to include all files by default instead of the `./src` directory
11+
12+
Extracts `publint` from the `lint` command into a separate command

oxfmtrc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"useTabs": true
2+
"$schema": "./node_modules/oxfmt/configuration_schema.json",
3+
"useTabs": true,
4+
"singleQuote": true,
5+
"ignorePatterns": ["*.json", "*.md", "*.yml", "*.jsonc"]
36
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"format": "pnpm run bsh format",
5858
"init": "pnpm run bsh init",
5959
"lint": "pnpm run bsh lint",
60+
"publint": "pnpm run bsh publint",
6061
"test": "pnpm run bsh test"
6162
},
6263
"dependencies": {

rules/plugin.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ const plugin = {
6363
const src = context.sourceCode.text;
6464
let idx = node.start - 1;
6565
// Walk backwards past whitespace
66-
while (idx >= 0 && (src[idx] === ' ' || src[idx] === '\t' || src[idx] === '\n' || src[idx] === '\r')) {
66+
while (
67+
idx >= 0 &&
68+
(src[idx] === ' ' || src[idx] === '\t' || src[idx] === '\n' || src[idx] === '\r')
69+
) {
6770
idx--;
6871
}
6972
// Check if preceding non-whitespace ends with */
@@ -82,8 +85,7 @@ const plugin = {
8285
const parent = node.parent;
8386
if (!parent) return false;
8487
return (
85-
parent.type === 'ExportNamedDeclaration' ||
86-
parent.type === 'ExportDefaultDeclaration'
88+
parent.type === 'ExportNamedDeclaration' || parent.type === 'ExportDefaultDeclaration'
8789
);
8890
}
8991

@@ -124,8 +126,7 @@ const plugin = {
124126
const parent = node.parent;
125127
if (!parent) return false;
126128
return (
127-
parent.type === 'ExportNamedDeclaration' ||
128-
parent.type === 'ExportDefaultDeclaration'
129+
parent.type === 'ExportNamedDeclaration' || parent.type === 'ExportDefaultDeclaration'
129130
);
130131
}
131132

src/bin.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#!/usr/bin/env node
2-
import { argv } from "node:process";
3-
import { build } from "./commands/build.ts";
4-
import { dev } from "./commands/dev.ts";
5-
import { format } from "./commands/format.ts";
6-
import { init } from "./commands/init.ts";
7-
import { lint } from "./commands/lint.ts";
8-
import { test } from "./commands/test.ts";
2+
import { argv } from 'node:process';
3+
import { build } from './commands/build.ts';
4+
import { dev } from './commands/dev.ts';
5+
import { format } from './commands/format.ts';
6+
import { init } from './commands/init.ts';
7+
import { lint } from './commands/lint.ts';
8+
import { publintCommand as publint } from './commands/publint.ts';
9+
import { test } from './commands/test.ts';
910

10-
const commands = { build, dev, format, init, lint, test };
11+
const commands = { build, dev, format, init, lint, publint, test };
1112

1213
async function main() {
1314
const [command, ...args] = argv.slice(2);
1415

1516
if (!command) {
16-
console.log(`No command provided. Available commands: ${Object.keys(commands).join(", ")}\n`);
17+
console.log(`No command provided. Available commands: ${Object.keys(commands).join(', ')}\n`);
1718
return;
1819
}
1920

2021
const run = commands[command as keyof typeof commands];
2122
if (!run) {
2223
console.log(
23-
`Unknown command: ${command}. Available commands: ${Object.keys(commands).join(", ")}`,
24+
`Unknown command: ${command}. Available commands: ${Object.keys(commands).join(', ')}`,
2425
);
2526
return;
2627
}

src/commands/build.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { parse } from "@bomb.sh/args";
2-
import { build as tsdown } from "tsdown";
3-
import type { CommandContext } from "../context.ts";
1+
import { parse } from '@bomb.sh/args';
2+
import { build as tsdown } from 'tsdown';
3+
import type { CommandContext } from '../context.ts';
44

55
export async function build(ctx: CommandContext) {
66
const args = parse(ctx.args, {
7-
boolean: ["bundle", "dts", "minify"],
7+
boolean: ['bundle', 'dts', 'minify'],
88
});
99

10-
const entry = args._.length > 0 ? args._.map(String) : ["src/**/*.ts", "!src/**/*.test.ts"];
10+
const entry = args._.length > 0 ? args._.map(String) : ['src/**/*.ts', '!src/**/*.test.ts'];
1111

1212
await tsdown({
1313
config: false,
1414
entry,
15-
format: "esm",
15+
format: 'esm',
1616
sourcemap: true,
1717
clean: true,
1818
unbundle: !args.bundle,

src/commands/dev.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { x } from "tinyexec";
2-
import type { CommandContext } from "../context.ts";
1+
import { x } from 'tinyexec';
2+
import type { CommandContext } from '../context.ts';
33

44
// standardized `dev` command, shells out to `node --strip-types`
55
export async function dev(ctx: CommandContext) {
66
const { args } = ctx;
7-
const [file = "./src/index.ts", ...rest] = args;
7+
const [file = './src/index.ts', ...rest] = args;
88
// console.clear();
99
console.log(
10-
`node --experimental-transform-types --disable-warning=ExperimentalWarning ${args.join(" ")}`,
10+
`node --experimental-transform-types --disable-warning=ExperimentalWarning ${args.join(' ')}`,
1111
);
12-
const stdio = x("node", [
13-
"--experimental-transform-types",
14-
"--no-warnings",
15-
"--watch-path=./src/",
12+
const stdio = x('node', [
13+
'--experimental-transform-types',
14+
'--no-warnings',
15+
'--watch-path=./src/',
1616
file,
1717
...rest,
1818
]);
19-
console.log("Starting dev server...");
20-
console.log("Press Ctrl+C to stop the server.");
19+
console.log('Starting dev server...');
20+
console.log('Press Ctrl+C to stop the server.');
2121

2222
for await (const line of stdio) {
23-
if (line.startsWith("Restarting")) {
23+
if (line.startsWith('Restarting')) {
2424
console.log(line);
2525
continue;
2626
}
27-
if (line.startsWith("Completed")) {
27+
if (line.startsWith('Completed')) {
2828
console.log();
2929
continue;
3030
}

src/commands/format.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { fileURLToPath } from "node:url";
2-
import { x } from "tinyexec";
3-
import type { CommandContext } from "../context.ts";
4-
import { local } from "../utils.ts";
1+
import { fileURLToPath } from 'node:url';
2+
import { x } from 'tinyexec';
3+
import type { CommandContext } from '../context.ts';
4+
import { local } from '../utils.ts';
55

6-
const config = fileURLToPath(new URL("../../oxfmtrc.json", import.meta.url));
6+
const config = fileURLToPath(new URL('../../oxfmtrc.json', import.meta.url));
77

88
export async function format(ctx: CommandContext) {
9-
const stdio = x(local("oxfmt"), ["-c", config, "./src", ...ctx.args]);
9+
const stdio = x(local('oxfmt'), ['-c', config, ...ctx.args]);
1010

1111
for await (const line of stdio) {
1212
console.log(line);

src/commands/init.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { readFile, writeFile } from "node:fs/promises";
2-
import { cwd } from "node:process";
3-
import { pathToFileURL } from "node:url";
4-
import { x } from "tinyexec";
5-
import type { CommandContext } from "../context.ts";
1+
import { readFile, writeFile } from 'node:fs/promises';
2+
import { cwd } from 'node:process';
3+
import { pathToFileURL } from 'node:url';
4+
import { x } from 'tinyexec';
5+
import type { CommandContext } from '../context.ts';
66

77
export async function init(ctx: CommandContext) {
8-
const [_name = "."] = ctx.args;
8+
const [_name = '.'] = ctx.args;
99
const cwdUrl = pathToFileURL(`${cwd()}/`);
1010
const name =
11-
_name === "." ? new URL("../", cwdUrl).pathname.split("/").filter(Boolean).pop()! : _name;
12-
const dest = new URL("./.temp/", cwdUrl);
13-
for await (const line of x("pnpx", ["giget@latest", "gh:bombshell-dev/template", name])) {
11+
_name === '.' ? new URL('../', cwdUrl).pathname.split('/').filter(Boolean).pop()! : _name;
12+
const dest = new URL('./.temp/', cwdUrl);
13+
for await (const line of x('pnpx', ['giget@latest', 'gh:bombshell-dev/template', name])) {
1414
console.log(line);
1515
}
1616

1717
const promises: Promise<void>[] = [];
18-
for (const file of ["package.json", "README.md"]) {
18+
for (const file of ['package.json', 'README.md']) {
1919
promises.push(
2020
postprocess(new URL(file, dest), (contents) => {
21-
return contents.replaceAll("$name", name);
21+
return contents.replaceAll('$name', name);
2222
}),
2323
);
2424
}
@@ -29,8 +29,8 @@ async function postprocess(
2929
file: URL,
3030
transform: (contents: string) => string | undefined | Promise<string | undefined>,
3131
) {
32-
const contents = await readFile(file, { encoding: "utf8" });
32+
const contents = await readFile(file, { encoding: 'utf8' });
3333
const result = await transform(contents);
3434
if (!result) return;
35-
await writeFile(file, result, { encoding: "utf8" });
35+
await writeFile(file, result, { encoding: 'utf8' });
3636
}

src/commands/lint.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
2-
import { createFixture } from "../test-utils/index.ts";
3-
import { runOxlint, runKnip } from "./lint.ts";
4-
import { fileURLToPath } from "node:url";
1+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
2+
import { createFixture } from '../test-utils/index.ts';
3+
import { runOxlint, runKnip } from './lint.ts';
4+
import { fileURLToPath } from 'node:url';
55

6-
describe("lint command", () => {
6+
describe('lint command', () => {
77
let originalCwd: string;
88
let fixture: Awaited<ReturnType<typeof createFixture>>;
99

@@ -16,57 +16,57 @@ describe("lint command", () => {
1616
if (fixture) await fixture.cleanup();
1717
});
1818

19-
describe("runOxlint", () => {
20-
it("detects violations in bad code", async () => {
19+
describe('runOxlint', () => {
20+
it('detects violations in bad code', async () => {
2121
fixture = await createFixture({
2222
src: {
23-
"index.ts": "var x = 1;",
23+
'index.ts': 'var x = 1;',
2424
},
2525
});
2626
process.chdir(fileURLToPath(fixture.root));
2727

28-
const violations = await runOxlint(["./src"]);
28+
const violations = await runOxlint(['./src']);
2929

3030
expect(violations).not.toEqual([]);
3131
expect(violations).toMatchSnapshot();
3232
});
3333

34-
it("returns empty array for clean code", async () => {
34+
it('returns empty array for clean code', async () => {
3535
fixture = await createFixture({
3636
src: {
37-
"index.ts": `
37+
'index.ts': `
3838
export const x = 1;
3939
`,
4040
},
4141
});
4242
process.chdir(fileURLToPath(fixture.root));
4343

44-
const violations = await runOxlint(["./src"]);
44+
const violations = await runOxlint(['./src']);
4545

4646
expect(violations).toEqual([]);
4747
});
4848
});
4949

50-
describe("runKnip", () => {
51-
it("detects unused exports and unused files", async () => {
50+
describe('runKnip', () => {
51+
it('detects unused exports and unused files', async () => {
5252
fixture = await createFixture({
53-
"package.json": {
54-
name: "test-pkg",
55-
version: "1.0.0",
56-
type: "module",
57-
exports: "./src/index.ts",
53+
'package.json': {
54+
name: 'test-pkg',
55+
version: '1.0.0',
56+
type: 'module',
57+
exports: './src/index.ts',
5858
},
5959
src: {
60-
"index.ts": `
60+
'index.ts': `
6161
import { used } from "./used";
6262
console.log(used);
6363
export const value = 42;
6464
`,
65-
"used.ts": `
65+
'used.ts': `
6666
export const used = "used";
6767
export const unusedExport = "unusedExport";
6868
`,
69-
"unused-file.ts": `
69+
'unused-file.ts': `
7070
export const unused = "unused";
7171
`,
7272
},

0 commit comments

Comments
 (0)