diff --git a/README.md b/README.md index 9777cc3..7de42b9 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ Depending on how are you creating your own config file, you may choose to instal - `devDependencies` (`-D`, `--save-dev`). - `peerDependencies` (`--save-peer`). -- `dependecies`. +- `dependencies`. @@ -90,6 +90,18 @@ Compatibility with Shell Script for Bash or sh. npm add -D prettier-plugin-sh ``` +### Multiline preset (`sh`) + +Multiline elements for some languages. + +#### Required plugins: + +- [prettier-plugin-multiline-arrays](https://github.com/electrovir/prettier-plugin-multiline-arrays) + +```sh +npm add -D prettier-plugin-multiline-arrays +``` + ## Usage ### Simple usage @@ -150,7 +162,11 @@ import { getMergedOverrideFor, } from '@elegantech/prettier-multi-config/presets'; -const selectedPresets = ['base', 'php', 'sh']; +const selectedPresets = [ + 'base', + 'php', + 'sh', +]; /** @type {import("prettier").Config} */ const config = { diff --git a/package-lock.json b/package-lock.json index 24db368..7ea70bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "is-ci": "^3.0.1", "lint-staged": "^15.0.0", "prettier": "^3.0.3", + "prettier-plugin-multiline-arrays": "^3.0.0", "prettier-plugin-organize-imports": "^3.2.3", "prettier-plugin-pkg": "^0.18.0", "prettier-plugin-sh": "^0.13.1", @@ -46,6 +47,7 @@ }, "optionalDependencies": { "@prettier/plugin-php": ">= 0.20.1", + "prettier-plugin-multiline-arrays": "^3.0.0", "prettier-plugin-organize-imports": "^3.2.3", "prettier-plugin-pkg": ">= 0.18.0", "prettier-plugin-sh": ">= 0.13.1" @@ -93,6 +95,28 @@ "node": ">=6.0.0" } }, + "node_modules/@augment-vir/common": { + "version": "21.3.6", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-21.3.6.tgz", + "integrity": "sha512-4mXYHGBrLk2M7AVjXxT5qp+gCbGS77/xqRZLZDlZiTxRdrjGcRfHVWUOYjdu2GC8aqQ34qbtiSNSnl+fCY3byA==", + "dev": true, + "dependencies": { + "browser-or-node": "^2.1.1", + "type-fest": "^4.4.0" + } + }, + "node_modules/@augment-vir/common/node_modules/type-fest": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.5.0.tgz", + "integrity": "sha512-diLQivFzddJl4ylL3jxSkEc39Tpw7o1QeEHIPxVwryDK2lpB7Nqhzhuo6v5/Ls08Z0yPSAhsyAWlv1/H0ciNmw==", + "dev": true, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@babel/code-frame": { "version": "7.22.13", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", @@ -2822,6 +2846,12 @@ "node": ">=8" } }, + "node_modules/browser-or-node": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-2.1.1.tgz", + "integrity": "sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==", + "dev": true + }, "node_modules/browserslist": { "version": "4.21.10", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.10.tgz", @@ -10686,6 +10716,19 @@ "resolved": "examples/shareable-typescript", "link": true }, + "node_modules/prettier-plugin-multiline-arrays": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/prettier-plugin-multiline-arrays/-/prettier-plugin-multiline-arrays-3.0.0.tgz", + "integrity": "sha512-qEfctOpCfnTztyLRoVkKvYpOLeTiG1Sq29Guk9zMs5YeZeoRZXO6JDdWj9OJyswJHmIrOEuPCmpdS7yxkyIatw==", + "dev": true, + "dependencies": { + "@augment-vir/common": "^21.3.6", + "proxy-vir": "^0.0.1" + }, + "peerDependencies": { + "prettier": "^3.0.0" + } + }, "node_modules/prettier-plugin-organize-imports": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-3.2.3.tgz", @@ -10790,6 +10833,36 @@ "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==", "dev": true }, + "node_modules/proxy-vir": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/proxy-vir/-/proxy-vir-0.0.1.tgz", + "integrity": "sha512-K3sv2I9kigOqt17hMhvWjSiwx90hpxxD3rN+meVQhrGKoxhVbt82ulkm3i1KlenVIMS1KFskt/vltMlGHVQrMw==", + "dev": true, + "dependencies": { + "@augment-vir/common": "^13.3.0" + } + }, + "node_modules/proxy-vir/node_modules/@augment-vir/common": { + "version": "13.5.0", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-13.5.0.tgz", + "integrity": "sha512-kOnAOShZTaOJ8glYyi2K3hfiYV5zQyjpfc4jmHm5lySAFNMpOjKA7pZxpl8n3RCIHAt+nFP64vuxtSI6jSWOZw==", + "dev": true, + "dependencies": { + "type-fest": "^3.8.0" + } + }, + "node_modules/proxy-vir/node_modules/type-fest": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz", + "integrity": "sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==", + "dev": true, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", @@ -13408,6 +13481,24 @@ "@jridgewell/trace-mapping": "^0.3.9" } }, + "@augment-vir/common": { + "version": "21.3.6", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-21.3.6.tgz", + "integrity": "sha512-4mXYHGBrLk2M7AVjXxT5qp+gCbGS77/xqRZLZDlZiTxRdrjGcRfHVWUOYjdu2GC8aqQ34qbtiSNSnl+fCY3byA==", + "dev": true, + "requires": { + "browser-or-node": "^2.1.1", + "type-fest": "^4.4.0" + }, + "dependencies": { + "type-fest": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.5.0.tgz", + "integrity": "sha512-diLQivFzddJl4ylL3jxSkEc39Tpw7o1QeEHIPxVwryDK2lpB7Nqhzhuo6v5/Ls08Z0yPSAhsyAWlv1/H0ciNmw==", + "dev": true + } + } + }, "@babel/code-frame": { "version": "7.22.13", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", @@ -15260,6 +15351,12 @@ "fill-range": "^7.0.1" } }, + "browser-or-node": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-2.1.1.tgz", + "integrity": "sha512-8CVjaLJGuSKMVTxJ2DpBl5XnlNDiT4cQFeuCJJrvJmts9YrTZDizTX7PjC2s6W4x+MBGZeEY6dGMrF04/6Hgqg==", + "dev": true + }, "browserslist": { "version": "4.21.10", "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.21.10.tgz", @@ -20656,6 +20753,16 @@ "unbuild": "*" } }, + "prettier-plugin-multiline-arrays": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/prettier-plugin-multiline-arrays/-/prettier-plugin-multiline-arrays-3.0.0.tgz", + "integrity": "sha512-qEfctOpCfnTztyLRoVkKvYpOLeTiG1Sq29Guk9zMs5YeZeoRZXO6JDdWj9OJyswJHmIrOEuPCmpdS7yxkyIatw==", + "dev": true, + "requires": { + "@augment-vir/common": "^21.3.6", + "proxy-vir": "^0.0.1" + } + }, "prettier-plugin-organize-imports": { "version": "3.2.3", "resolved": "https://registry.npmjs.org/prettier-plugin-organize-imports/-/prettier-plugin-organize-imports-3.2.3.tgz", @@ -20717,6 +20824,32 @@ "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==", "dev": true }, + "proxy-vir": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/proxy-vir/-/proxy-vir-0.0.1.tgz", + "integrity": "sha512-K3sv2I9kigOqt17hMhvWjSiwx90hpxxD3rN+meVQhrGKoxhVbt82ulkm3i1KlenVIMS1KFskt/vltMlGHVQrMw==", + "dev": true, + "requires": { + "@augment-vir/common": "^13.3.0" + }, + "dependencies": { + "@augment-vir/common": { + "version": "13.5.0", + "resolved": "https://registry.npmjs.org/@augment-vir/common/-/common-13.5.0.tgz", + "integrity": "sha512-kOnAOShZTaOJ8glYyi2K3hfiYV5zQyjpfc4jmHm5lySAFNMpOjKA7pZxpl8n3RCIHAt+nFP64vuxtSI6jSWOZw==", + "dev": true, + "requires": { + "type-fest": "^3.8.0" + } + }, + "type-fest": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz", + "integrity": "sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==", + "dev": true + } + } + }, "punycode": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", diff --git a/package.json b/package.json index 97286ae..cd51fa1 100644 --- a/package.json +++ b/package.json @@ -50,17 +50,17 @@ ], "scripts": { "build": "unbuild", - "build:internal": "unbuild internal", "build:watch": "watch 'npm run build' src", "fix:eslint": "eslint . --fix", "fix:style": "prettier --write .", + "internal:build": "unbuild internal", "internal:promote-prettier": "node scripts/promote-prettier-config.mjs", "lint:all": "concurrently -t --success=all --timings \"npm:lint:*(!all)\"", "lint:eslint": "eslint .", "lint:prettier-config": "npx prettier --check --no-error-on-unmatched-pattern --log-level=silent test", "lint:style": "prettier --check .", "lint:ts": "tsc --noEmit -p tsconfig.main.json && tsc --noEmit -p tsconfig.configs.json && tsc --noEmit -p tsconfig.internal.json && tsc --noEmit -p tsconfig.test.json", - "postbuild:internal": "npm run internal:promote-prettier", + "postinternal:build": "npm run internal:promote-prettier", "postinternal:promote-prettier": "prettier --write ./.prettierrc.json", "prepack": "npm run build", "prepare": "is-ci || husky install", @@ -76,6 +76,7 @@ }, "optionalDependencies": { "@prettier/plugin-php": ">= 0.20.1", + "prettier-plugin-multiline-arrays": "^3.0.0", "prettier-plugin-organize-imports": "^3.2.3", "prettier-plugin-pkg": ">= 0.18.0", "prettier-plugin-sh": ">= 0.13.1" @@ -98,6 +99,7 @@ "is-ci": "^3.0.1", "lint-staged": "^15.0.0", "prettier": "^3.0.3", + "prettier-plugin-multiline-arrays": "^3.0.0", "prettier-plugin-organize-imports": "^3.2.3", "prettier-plugin-pkg": "^0.18.0", "prettier-plugin-sh": "^0.13.1", diff --git a/src/presets/index.ts b/src/presets/index.ts index c8274f5..07c05a4 100644 --- a/src/presets/index.ts +++ b/src/presets/index.ts @@ -2,13 +2,19 @@ import { IOptionsWithoutPlugins, IPrettierOverride, PresetPlugins } from '~/cont import { IMergeOverrideMultipleOptions, isNotEmpty, mergeOverrideMultiple } from '~/helpers'; import { preset as base } from './base'; +import { preset as multiline } from './multiline'; import { preset as php } from './php'; import { preset as sh } from './sh'; /** * List of available presets. */ -export const AVAILABLE_PRESETS = ['base', 'php', 'sh'] as const; +export const AVAILABLE_PRESETS = [ + 'base', + 'php', + 'sh', + 'multiline', +] as const; export type PresetName = (typeof AVAILABLE_PRESETS)[number]; @@ -31,6 +37,7 @@ export const PRESETS_MAP = { base, php, sh, + multiline, } as const; export type PresetMap = typeof PRESETS_MAP; diff --git a/src/presets/multiline.ts b/src/presets/multiline.ts new file mode 100644 index 0000000..79d87ed --- /dev/null +++ b/src/presets/multiline.ts @@ -0,0 +1,47 @@ +import { IOptionsWithoutPlugins, IPrettierPreset } from '~/contracts'; + +/** + * @link https://github.com/electrovir/prettier-plugin-multiline-arrays?tab=readme-ov-file#options + */ +export interface IMultilineOptions extends IOptionsWithoutPlugins { + /** + * This should be set to a single number which controls when arrays wrap. + * If an array has more elements than the number specified here, it will be forced to wrap. + * This option defaults to -1, which indicates that no automatic wrapping will take place. + * + * @default -1 + */ + multilineArraysWrapThreshold?: number; + + /** + * This should be set to a string which contains a space separated list of numbers. These numbers allow + * fine grained control over how many elements appear in each line. The pattern will repeat if an array + * has more elements than the pattern. + * + * @default '1' + */ + multilineArraysLinePattern?: string; +} + +// TODO: Include multiline array plugin when compatible with Prettier 3 +// (https://github.com/electrovir/prettier-plugin-multiline-arrays/issues/26) + +/** + * Preset for multiline elements. + * + * @link https://github.com/electrovir/prettier-plugin-multiline-arrays + */ +export const preset: IPrettierPreset = { + globalOptions: { + multilineArraysWrapThreshold: 1, + }, + + plugins: [ + // + 'prettier-plugin-multiline-arrays', + ], + + overrideConfigs: [ + // TODO: Add configs for language + ], +};