UNPKG

@envsa/prettier-config

Version:
154 lines (153 loc) 4.52 kB
import { deepmerge } from 'deepmerge-ts'; import { sortOrder as sortPackageJsonSortOrder } from 'sort-package-json'; /** * Merge custom keys into the `sort-package-json` `order` array. Where * duplicated, delete existing and prioritize new keys. */ function customizeSortOrder(keys, newKeys) { // If new keys are in keys, remove them const filteredKeys = keys.filter((key) => !newKeys.includes(key)); // Append new keys to the end return [...filteredKeys, ...newKeys]; } const sharedPrettierConfig = { arrowParens: 'always', bracketSpacing: true, overrides: [ { files: ['*.md', '*.mdx', '*.yml', '*.yaml'], options: { useTabs: false, }, }, { files: '*.json5', options: { parser: 'json5', quoteProps: 'preserve', singleQuote: false, trailingComma: 'none', }, }, { files: '*.php', options: { phpVersion: '8.2', printWidth: 80, parser: 'php', tabWidth: 4, trailingCommaPHP: true, }, }, { files: '*.{yml,yaml}', options: { singleQuote: false, tabWidth: 4, }, }, { files: ['*rc', '*ignore', '*.sh', '*.zsh', '*.bash', '*.fish'], options: { parser: 'sh', plugins: ['prettier-plugin-sh'], }, }, { files: '*.svelte', options: { parser: 'svelte', plugins: ['prettier-plugin-svelte'], }, }, { files: ['*.twig', '*.html.twig'], options: { parser: 'twig', twigSingleQuote: false, twigMultiTags: [ 'cache,endcache', 'css,endcss', 'js,endjs', 'namespace,endnamespace', 'nav,endnav', 'ifchildren,endifchildren', 'script,endscript', 'switch,case,default,endswitch', 'tag,endtag', ], twigTestExpressions: [ 'string', 'boolean', 'array', 'callable', 'countable', 'float', 'instance of', 'integer', 'missing', 'numeric', 'object', 'resource', 'scalar', ], }, }, // Make this match eslint 'json-package/order-properties' // https://github.com/matzkoh/prettier-plugin-packagejson/issues/188 // This must stay in sync with packages/eslint-config/src/configs/json.ts { files: 'package.json', options: { packageSortOrder: customizeSortOrder(sortPackageJsonSortOrder, [ 'cspell', 'knip', 'mdat', 'prettier', 'remarkConfig', 'stylelint', ]), }, }, { files: ['*.js', '*.mjs', '*.cjs'], options: { parser: 'babel', }, }, { files: ['*.ts', '*.mts', '*.cts'], options: { parser: 'typescript', }, }, ], plugins: [ '@zackad/prettier-plugin-twig', '@prettier/plugin-php', '@prettier/plugin-xml', 'prettier-plugin-packagejson', 'prettier-plugin-tailwindcss', ], printWidth: 100, semi: true, singleQuote: true, tabWidth: 2, trailingComma: 'all', useTabs: false, }; /** * **\@Kitschpatrol's Shared Prettier Configuration** * @see [@envsa/prettier-config](https://github.com/envsa/shared-config/tree/main/packages/prettier-config) * @see [@envsa/shared-config](https://github.com/envsa/shared-config) * @example * ```js * export default prettierConfig({ * printWidth: 120, * }) * ``` */ export function prettierConfig(config) { return deepmerge(sharedPrettierConfig, config); } export default sharedPrettierConfig;