Skip to content

Commit

Permalink
feat(presets): add multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
nelson6e65 committed Oct 23, 2023
1 parent 1915f05 commit c60b871
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 5 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

<!-- TODO: Add documentation about other types of installation -->

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
133 changes: 133 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand All @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -31,6 +37,7 @@ export const PRESETS_MAP = {
base,
php,
sh,
multiline,
} as const;

export type PresetMap = typeof PRESETS_MAP;
Expand Down
47 changes: 47 additions & 0 deletions src/presets/multiline.ts
Original file line number Diff line number Diff line change
@@ -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<IMultilineOptions> = {
globalOptions: {
multilineArraysWrapThreshold: 1,
},

plugins: [
//
'prettier-plugin-multiline-arrays',
],

overrideConfigs: [
// TODO: Add configs for language
],
};

0 comments on commit c60b871

Please # to comment.