From f0cf22e142b9d4c2b4049fb3a824e5bdfef0e2d9 Mon Sep 17 00:00:00 2001 From: MP281X Date: Fri, 10 May 2024 21:23:25 +0200 Subject: [PATCH] fix prettier --- package.json | 8 ++++++-- src/lib/execCmd.ts | 2 +- src/lib/findGlob.ts | 2 +- src/lib/findProjects.ts | 6 +++--- src/lib/logger.ts | 8 ++++---- src/lib/parseConfig.ts | 4 ++-- src/prettier.ts | 3 ++- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index e6f7563..8a9f17f 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,14 @@ { "type": "module", - "version": "1.1.19", + "version": "1.1.20", "name": "@mp281x/shared-config", "publishConfig": { "registry": "https://npm.pkg.github.com/@mp281x" }, - "scripts": { "dev": "tsup-node --watch", "check": "./dist/task-runner.js --check --test" }, + "scripts": { + "dev": "tsup-node --watch", + "fix": "./dist/task-runner.js --fix", + "check": "./dist/task-runner.js --check --test" + }, "files": ["./dist/*", "./src/tsconfig.json"], "bin": { "task-runner": "./dist/task-runner.js" }, diff --git a/src/lib/execCmd.ts b/src/lib/execCmd.ts index d213bc2..ebbf534 100644 --- a/src/lib/execCmd.ts +++ b/src/lib/execCmd.ts @@ -28,7 +28,7 @@ export const execCmd = async ({ title, cmd, customCmd, mode, cwd }: ExecCmd) => output.stderr.on('data', (msg: Buffer) => void log.error(title, msg)) - output.on('exit', (exitCode) => { + output.on('exit', exitCode => { if (exitCode === 0 || exitCode === null) return resolve() if (process.argv[2] === 'dev') return resolve() diff --git a/src/lib/findGlob.ts b/src/lib/findGlob.ts index 5a4cd33..a39586c 100644 --- a/src/lib/findGlob.ts +++ b/src/lib/findGlob.ts @@ -12,7 +12,7 @@ const gitIgnore = parseConfig(`${process.cwd()}/.gitignore`) ?? [] export const findGlob: typeof fs.globSync = (glob, options) => fs.globSync(glob, { cwd: options?.cwd ?? process.cwd(), - exclude: (path) => options?.exclude?.(path) || gitIgnore.includes(path) + exclude: path => options?.exclude?.(path) || gitIgnore.includes(path) }) if (import.meta.vitest) { diff --git a/src/lib/findProjects.ts b/src/lib/findProjects.ts index 5582543..e04a02f 100644 --- a/src/lib/findProjects.ts +++ b/src/lib/findProjects.ts @@ -13,13 +13,13 @@ const getWorkspaceProjects = (dir: string) => { type PNPMWorkspace = { packages?: string[] } globs.push(...(parseConfig(`${dir}/pnpm-workspace.yaml`)?.packages ?? [])) - return globs.flatMap((glob) => findGlob(glob, { cwd: dir })).filter((path) => fs.existsSync(`${dir}/${path}/package.json`)) + return globs.flatMap(glob => findGlob(glob, { cwd: dir })).filter(path => fs.existsSync(`${dir}/${path}/package.json`)) } export type Project = { cwd: string; name: string; scripts: string[]; lspPlugin: boolean; type: 'node' | 'svelte' } // find all the projects in a the monorepo/repo export const findProjects = (dir: string = process.cwd()): Project[] => { - const projects = getWorkspaceProjects(dir).flatMap((project) => findProjects(project)) + const projects = getWorkspaceProjects(dir).flatMap(project => findProjects(project)) if (projects.length > 0) return projects if (!fs.existsSync(`${dir}/package.json`)) return [] @@ -32,7 +32,7 @@ export const findProjects = (dir: string = process.cwd()): Project[] => { type TSConfig = { compilerOptions?: { plugins?: { name: string }[] } } const { compilerOptions } = parseConfig(`${dir}/tsconfig.json`) ?? {} - const lspPlugin = compilerOptions?.plugins?.find((x) => x.name === 'lsp-plugin') !== undefined + const lspPlugin = compilerOptions?.plugins?.find(x => x.name === 'lsp-plugin') !== undefined return [ { diff --git a/src/lib/logger.ts b/src/lib/logger.ts index fa5a982..cff0216 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -124,18 +124,18 @@ const parseVitestOutput = (input: string): { name: string; errors: string[] }[] } const vitestData = JSON.parse(input) as VitestJSON if (vitestData.success) return [] - return vitestData.testResults.flatMap((testFile) => { + return vitestData.testResults.flatMap(testFile => { const filePath = testFile.name.replace(process.cwd(), '').split('/').slice(3).join('/') return testFile.assertionResults - .filter((test) => test.status === 'failed') - .map((test) => ({ + .filter(test => test.status === 'failed') + .map(test => ({ name: `\x1b[91m[${filePath} -> "${test.title}"]\x1b[0m`, // split on lines and on new error errors: test.failureMessages .join('\n') .split('\n') - .filter((logMsg) => logMsg.trim() !== '') + .filter(logMsg => logMsg.trim() !== '') })) }) } diff --git a/src/lib/parseConfig.ts b/src/lib/parseConfig.ts index b62f582..e7d8977 100644 --- a/src/lib/parseConfig.ts +++ b/src/lib/parseConfig.ts @@ -15,8 +15,8 @@ export const parseConfig = (path: string): Res | undefined => { .readFileSync(path) .toString() .split('\n') - .map((line) => line.split('#').shift()?.trim()) - .filter((line) => line !== '' && line !== undefined) as string[] + .map(line => line.split('#').shift()?.trim()) + .filter(line => line !== '' && line !== undefined) as string[] } // @ts-expect-error diff --git a/src/prettier.ts b/src/prettier.ts index d6186c2..3529ddd 100644 --- a/src/prettier.ts +++ b/src/prettier.ts @@ -6,8 +6,9 @@ export default { printWidth: 150, singleQuote: true, trailingComma: 'none', - arrowParens: 'always', + arrowParens: 'avoid', quoteProps: 'consistent', + experimentalTernaries: true, overrides: [{ files: '*.json', options: { parser: 'jsonc' } }], plugins: ['prettier-plugin-svelte', 'prettier-plugin-astro', 'prettier-plugin-tailwindcss'] } satisfies Config