Skip to content

Commit

Permalink
[patch] fix messed up line endings without trailing commas
Browse files Browse the repository at this point in the history
GitHub: fixes #41
  • Loading branch information
electrovir committed Dec 15, 2024
1 parent e7ee199 commit fe7725b
Show file tree
Hide file tree
Showing 24 changed files with 666 additions and 576 deletions.
42 changes: 11 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Add this config to your prettierrc file:
<!-- example-link: src/readme-examples/prettier-options.example.ts -->

```TypeScript
module.exports = {
export default {
plugins: [
'prettier-plugin-multiline-arrays',
],
Expand All @@ -26,18 +26,18 @@ The order of your plugins array is very important, so if you have other plugins

This plugin provides two new options for your Prettier config:

- **`multilineArraysWrapThreshold`**: 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. Example JSON: `"multilineArraysWrapThreshold": 3,`. To override this option for an individual array, precede the array with a comment like so: `// prettier-multiline-arrays-next-threshold: 4`.
- **`multilineArraysLinePattern`**: 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. See the `Examples` section for how this works. This defaults to just `1`, which indicates all array lines have just a single element. Example: `"multilineArraysLinePattern": "2 1"`, which means the first line will have 2 elements, the second will have 1, the third will have 2, the fourth will have 1, and so on. If set, _this option overrides Prettier's default wrapping; multiple elements on one line will not be wrapped even if they don't fit within the column count._ To override this option for an array, precede the array with a comment like so: `// prettier-multiline-arrays-next-line-pattern: 2 1`.
- **`multilineArraysWrapThreshold`**: 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. Example JSON: `"multilineArraysWrapThreshold": 3,`. To override this option for an individual array, precede the array with a comment like so: `// prettier-multiline-arrays-next-threshold: 4`.
- **`multilineArraysLinePattern`**: 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. See the `Examples` section for how this works. This defaults to just `1`, which indicates all array lines have just a single element. Example: `"multilineArraysLinePattern": "2 1"`, which means the first line will have 2 elements, the second will have 1, the third will have 2, the fourth will have 1, and so on. If set, _this option overrides Prettier's default wrapping; multiple elements on one line will not be wrapped even if they don't fit within the column count._ To override this option for an array, precede the array with a comment like so: `// prettier-multiline-arrays-next-line-pattern: 2 1`.

## Comment overrides

- Add a comment starting with `prettier-multiline-arrays-next-threshold:` followed by a single number to control `multilineArraysWrapThreshold` for an array on the next line.
- Add a comment starting with `prettier-multiline-arrays-next-line-pattern:` followed by a pattern of numbers to control `multilineArraysLinePattern` for an array on the next line.
- Add a comment starting with `prettier-multiline-arrays-next-threshold:` followed by a single number to control `multilineArraysWrapThreshold` for an array on the next line.
- Add a comment starting with `prettier-multiline-arrays-next-line-pattern:` followed by a pattern of numbers to control `multilineArraysLinePattern` for an array on the next line.

To set a comment override for all arrays in a file following the comment, change `next` to `set`. Like so:

- `prettier-multiline-arrays-set-threshold: 5`
- `prettier-multiline-arrays-set-line-pattern: 2 1 3`
- `prettier-multiline-arrays-set-threshold: 5`
- `prettier-multiline-arrays-set-line-pattern: 2 1 3`

To later undo a `set` comment, use `prettier-multiline-arrays-reset`, which resets the options to whatever you have set in prettierrc, or the default values.

Expand All @@ -52,7 +52,7 @@ The precedence of forcing wrapping goes as follows:

## Examples

- Not formatted:
- Not formatted:

<!-- example-link: src/readme-examples/not-formatted.example.ts -->

Expand All @@ -65,27 +65,7 @@ The precedence of forcing wrapping goes as follows:
'a', 'b', 'c', 'd', 'e'] // note the leading new line which forces a wrap
```

- Removing the `prettier-ignore` comments leads to formatting like this (with the default options):

<!-- example-link: src/readme-examples/formatted.example.ts -->

```TypeScript
export const myArray = [
'a',
'b',
'c',
]; // note the trailing comma which forces a wrap
export const myCustomArray = [
'a',
'b',
'c',
'd',
'e',
]; // note the leading new line which forces a wrap
```

- Use comment overrides to affect wrapping:
- Use comment overrides to affect wrapping:

<!-- example-link: src/readme-examples/formatted-with-comments.example.ts -->

Expand Down Expand Up @@ -126,5 +106,5 @@ Tested to be compatible with the following plugins. It is likely compatible with

### Debugging

- Set the `MULTILINE_DEBUG` environment variable to something truthy before formatting to get extra debug output when formatting.
- To debug in browser dev tools, run `npm run test:debug` and open Chrome's dev tools.
- Set the `MULTILINE_DEBUG` environment variable to something truthy before formatting to get extra debug output when formatting.
- To debug in browser dev tools, run `npm run test:debug` and open Chrome's dev tools.
19 changes: 0 additions & 19 deletions configs/c8.config.json

This file was deleted.

6 changes: 6 additions & 0 deletions configs/dep-cruiser.config.cts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const baseConfig = defineConfig({
'no-orphans': {
from: [
'src/index.ts',
'.example.ts',
],
},
'no-duplicate-dep-types': {
to: [
'prettier',
],
},
},
Expand Down
17 changes: 17 additions & 0 deletions configs/typedoc.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {baseTypedocConfig} from '@virmator/docs/configs/typedoc.config.base';
import {join, resolve} from 'path';
import type {TypeDocOptions} from 'typedoc';

const repoRoot = resolve(import.meta.dirname, '..');
const indexTsFile = join(repoRoot, 'src', 'index.ts');

export const typeDocConfig: Partial<TypeDocOptions> = {
...baseTypedocConfig,
out: join(repoRoot, 'docs-dist'),
entryPoints: [
indexTsFile,
],
intentionallyNotExported: [],
requiredToBeDocumented: [],
emit: 'none',
};
Loading

0 comments on commit fe7725b

Please sign in to comment.