From efc069748315c6f6e9e89e1543a4f8475d98ccd7 Mon Sep 17 00:00:00 2001 From: Teffen Ellis Date: Wed, 26 Mar 2025 17:18:08 +0100 Subject: [PATCH] core: Flesh out Prettier config package. --- packages/prettier-config/LICENSE.txt | 18 +++++++++ packages/prettier-config/README.md | 5 +++ packages/prettier-config/config.js | 51 ++++++++++++++++++++++++++ packages/prettier-config/format.js | 19 ++++++++++ packages/prettier-config/index.js | 6 +++ packages/prettier-config/package.json | 27 ++++++++++++++ packages/prettier-config/tsconfig.json | 7 ++++ 7 files changed, 133 insertions(+) create mode 100644 packages/prettier-config/LICENSE.txt create mode 100644 packages/prettier-config/README.md create mode 100644 packages/prettier-config/config.js create mode 100644 packages/prettier-config/format.js create mode 100644 packages/prettier-config/index.js create mode 100644 packages/prettier-config/package.json create mode 100644 packages/prettier-config/tsconfig.json diff --git a/packages/prettier-config/LICENSE.txt b/packages/prettier-config/LICENSE.txt new file mode 100644 index 0000000000..33b9c1516e --- /dev/null +++ b/packages/prettier-config/LICENSE.txt @@ -0,0 +1,18 @@ +The MIT License (MIT) + +Copyright (c) 2025 Authentik Security, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/prettier-config/README.md b/packages/prettier-config/README.md new file mode 100644 index 0000000000..f4a2077469 --- /dev/null +++ b/packages/prettier-config/README.md @@ -0,0 +1,5 @@ +# `@goauthentik/prettier-config` + +This package contains the Prettier configuration used by authentik. +While it is possible to use this configuration outside of our projects, +you may find that it is not as useful as other popular configurations. diff --git a/packages/prettier-config/config.js b/packages/prettier-config/config.js new file mode 100644 index 0000000000..f81664755a --- /dev/null +++ b/packages/prettier-config/config.js @@ -0,0 +1,51 @@ +/** + * authentik Prettier configuration. + * + * @type {import("prettier").Config} + * @internal + */ +export const AuthentikPrettierConfig = { + arrowParens: "always", + bracketSpacing: true, + embeddedLanguageFormatting: "auto", + htmlWhitespaceSensitivity: "css", + insertPragma: false, + jsxSingleQuote: false, + printWidth: 100, + proseWrap: "preserve", + quoteProps: "consistent", + requirePragma: false, + semi: true, + singleQuote: false, + tabWidth: 4, + trailingComma: "all", + useTabs: false, + vueIndentScriptAndStyle: false, + plugins: ["prettier-plugin-packagejson", "@trivago/prettier-plugin-sort-imports"], + importOrder: ["^(@?)lit(.*)$", "\\.css$", "^@goauthentik/api$", "^[./]"], + importOrderSeparation: true, + importOrderSortSpecifiers: true, + importOrderParserPlugins: ["typescript", "jsx", "classProperties", "decorators-legacy"], + overrides: [ + { + files: "tsconfig.json", + options: { + trailingComma: "none", + }, + }, + { + files: "package.json", + options: { + packageSortOrder: [ + // --- + "name", + "version", + "description", + "scripts", + "devDependencies", + "dependencies", + ], + }, + }, + ], +}; diff --git a/packages/prettier-config/format.js b/packages/prettier-config/format.js new file mode 100644 index 0000000000..42cb1eb687 --- /dev/null +++ b/packages/prettier-config/format.js @@ -0,0 +1,19 @@ +import { format } from "prettier"; +import { AuthentikPrettierConfig } from "./config.js"; + +/** + * Format using Prettier. + * + * Defaults to using the TypeScript parser. + * + * @category Formatting + * @param {string} fileContents The contents of the file to format. + * + * @returns {Promise} The formatted file contents. + */ +export function formatWithPrettier(fileContents) { + return format(fileContents, { + ...AuthentikPrettierConfig, + parser: "typescript", + }); +} diff --git a/packages/prettier-config/index.js b/packages/prettier-config/index.js new file mode 100644 index 0000000000..8a6bd459c8 --- /dev/null +++ b/packages/prettier-config/index.js @@ -0,0 +1,6 @@ +import { AuthentikPrettierConfig } from "./config.js"; + +export * from "./config.js"; +export * from "./format.js"; + +export default AuthentikPrettierConfig; diff --git a/packages/prettier-config/package.json b/packages/prettier-config/package.json new file mode 100644 index 0000000000..5567156690 --- /dev/null +++ b/packages/prettier-config/package.json @@ -0,0 +1,27 @@ +{ + "name": "@goauthentik/prettier-config", + "version": "1.0.0", + "description": "authentik's Prettier config", + "type": "module", + "license": "MIT", + "exports": { + "./package.json": "./package.json", + ".": { + "import": "./index.js", + "types": "./out/index.d.ts" + } + }, + "types": "./out/index.d.ts", + "peerDependencies": { + "@trivago/prettier-plugin-sort-imports": "^4.3.0", + "prettier-plugin-organize-imports": "^4.1.0", + "prettier": "^3.5.3", + "prettier-plugin-packagejson": "^2.5.10" + }, + "engines": { + "node": ">=20.11" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/prettier-config/tsconfig.json b/packages/prettier-config/tsconfig.json new file mode 100644 index 0000000000..af0ccaac72 --- /dev/null +++ b/packages/prettier-config/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "@goauthentik/tsconfig", + "compilerOptions": { + "checkJs": true, + "emitDeclarationOnly": true + } +}