From 70edc2f49a84eed9fd6731fb0a41da43135eb913 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 14 Aug 2024 09:48:01 +0800 Subject: [PATCH] Setup prettier --- .prettierrc.yaml | 5 +++++ package-lock.json | 17 +++++++++++++++++ package.json | 5 ++++- src/index.ts | 2 +- src/loader.ts | 4 ++-- src/theme/NativeIdealImage.tsx | 10 +++++----- src/types.d.ts | 2 +- 7 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 .prettierrc.yaml diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..8819abe --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,5 @@ +semi: false +singleQuote: true +htmlWhitespaceSensitivity: ignore +useTabs: true +printWidth: 100 diff --git a/package-lock.json b/package-lock.json index 92f615f..3b3a067 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "devDependencies": { "@types/loader-utils": "^2.0.6", "@types/node": "20.x", + "prettier": "^3.3.3", "typescript": "^5.5.4" } }, @@ -13164,6 +13165,22 @@ "postcss": "^8.4.31" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-error": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz", diff --git a/package.json b/package.json index 5232748..cbc60e5 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "devDependencies": { "@types/loader-utils": "^2.0.6", "@types/node": "20.x", + "prettier": "^3.3.3", "typescript": "^5.5.4" }, "dependencies": { @@ -37,6 +38,8 @@ "sharp": "^0.33.4", "webpack": "^5.93.0" }, - "workspaces": ["example"], + "workspaces": [ + "example" + ], "type": "module" } diff --git a/src/index.ts b/src/index.ts index 4e8c746..6d24f7b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,7 +19,7 @@ export type NativeIdealImageOptions = Partial export default function pluginNativeIdealImage( context: LoadContext, - options: NativeIdealImageOptions + options: NativeIdealImageOptions, ): Plugin { return { name: 'docusaurus-plugin-native-ideal-image', diff --git a/src/loader.ts b/src/loader.ts index 32f0416..93be39d 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -143,7 +143,7 @@ export default async function loader(this: LoaderContext, content async function createFiles( context: LoaderContext, image: sharp.Sharp, - options: { formats: SupportedOutputTypes[]; sizes: number[] } + options: { formats: SupportedOutputTypes[]; sizes: number[] }, ) { const formats: OutputDataForFormat[] = [] for (const format of options.formats) { @@ -160,7 +160,7 @@ async function processImage( context: LoaderContext, image: sharp.Sharp, size: number, - format: SupportedOutputTypes + format: SupportedOutputTypes, ) { const resized = image.resize(size) let output: sharp.Sharp diff --git a/src/theme/NativeIdealImage.tsx b/src/theme/NativeIdealImage.tsx index 7d9b5f0..39e6ac5 100644 --- a/src/theme/NativeIdealImage.tsx +++ b/src/theme/NativeIdealImage.tsx @@ -27,7 +27,7 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem const sources = enabled ? data.formats.slice(0, data.formats.length - 1) : undefined const lastFormat = enabled ? data.formats[data.formats.length - 1]! : undefined - const sizesAttr = sizes ?? enabled ? 'auto' : undefined + const sizesAttr = (sizes ?? enabled) ? 'auto' : undefined const isSingleImage = formats[0]?.srcSet.length === 1 const largestImage = formats[0]?.srcSet[formats[0]?.srcSet.length - 1] @@ -61,18 +61,18 @@ export default function NativeIdealImage(props: NativeIdealImageProps): JSX.Elem ))}