Skip to content

Commit 9b8c653

Browse files
committed
feat: allow specification of tag groups and lines between (and before and after) them and removal of whitespace within them; fixes #782
BREAKING CHANGE: `tagSequence` array of string tags argument must be specified instead as array of `{tags: []}` objects, with each object representing groups which can gain optional whitespace between them; if none are needed, just put all tags into the array of a single `{tags: []}`
1 parent 9e96b75 commit 9b8c653

File tree

6 files changed

+2338
-195
lines changed

6 files changed

+2338
-195
lines changed

.README/rules/sort-tags.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,48 @@ Sorts tags by a specified sequence according to tag name.
44

55
(Default order originally inspired by [`@homer0/prettier-plugin-jsdoc`](https://github.com/homer0/packages/tree/main/packages/public/prettier-plugin-jsdoc).)
66

7+
Optionally allows adding line breaks between tag groups and/or between tags
8+
within a tag group.
9+
10+
Please note: unless you are disabling reporting of line breaks, this rule
11+
should not be used with the default "never" or "always" options of
12+
`tag-lines` (a rule enabled by default with the recommended config) as
13+
that rule adds its own line breaks after tags and may interfere with any
14+
line break setting this rule will attempt to do when not disabled.
15+
16+
You may, however, safely set the "any" option in that rule along with
17+
`startLines` and/or `endLines`.
18+
719
#### Options
820

921
##### `tagSequence`
1022

11-
An array of tag names indicating the preferred sequence for sorting tags.
23+
An array of tag group objects indicating the preferred sequence for sorting tags.
24+
25+
Each item in the array should be an object with a `tags` property set to an array
26+
of tag names.
1227

1328
Tag names earlier in the list will be arranged first. The relative position of
1429
tags of the same name will not be changed.
1530

16-
Tags not in the list will be sorted alphabetically at the end (or in place of
17-
the pseudo-tag `-other` placed within `tagSequence`) if `alphabetizeExtras` is
18-
enabled and in their order of appearance otherwise (so if you want all your
19-
tags alphabetized, supply an empty array with `alphabetizeExtras` enabled).
31+
Earlier groups will also be arranged before later groups, but with the added
32+
feature that additional line breaks may be added between (or before or after)
33+
such groups (depending on the setting of `linesBetween`).
34+
35+
Tag names not in the list will be grouped together at the end. The pseudo-tag
36+
`-other` can be used to place them anywhere else if desired. The tags will be
37+
placed in their order of appearance, or alphabetized if `alphabetizeExtras`
38+
is enabled, see more below about that option.
2039

21-
Defaults to the array below.
40+
Defaults to the array below (noting that it is just a single tag group with
41+
no lines between groups by default).
2242

2343
Please note that this order is still experimental, so if you want to retain
2444
a fixed order that doesn't change into the future, supply your own
2545
`tagSequence`.
2646

2747
```js
28-
[
48+
[{tags: [
2949
// Brief descriptions
3050
'summary',
3151
'typeSummary',
@@ -178,7 +198,7 @@ a fixed order that doesn't change into the future, supply your own
178198
'since',
179199
'deprecated',
180200
'todo',
181-
];
201+
]}];
182202
```
183203

184204
##### `alphabetizeExtras`
@@ -187,12 +207,34 @@ Defaults to `false`. Alphabetizes any items not within `tagSequence` after any
187207
items within `tagSequence` (or in place of the special `-other` pseudo-tag)
188208
are sorted.
189209

210+
If you want all your tags alphabetized, you can supply an empty array for
211+
`tagSequence` along with setting this option to `true`.
212+
213+
##### `linesBetween`
214+
215+
Indicates the number of lines to be added between tag groups. Defaults to 1.
216+
Do not set to 0 or 2+ if you are using `tag-lines` and `"always"` and do not
217+
set to 1+ if you are using `tag-lines` and `"never"`.
218+
219+
##### `reportTagGroupSpacing`
220+
221+
Whether to enable reporting and fixing of line breaks between tag groups
222+
as set by `linesBetween`. Defaults to `true`. Note that the very last tag
223+
will not have spacing applied regardless. For adding line breaks there, you
224+
may wish to use the `endLines` option of the `tag-lines` rule.
225+
226+
##### `reportIntraTagGroupSpacing`
227+
228+
Whether to enable reporting and fixing of line breaks within tags of a given
229+
tag group. Defaults to `true` which will remove any line breaks at the end of
230+
such tags. Do not use with `true` if you are using `tag-lines` and `always`.
231+
190232
|||
191233
|---|---|
192234
|Context|everywhere|
193235
|Tags|any|
194236
|Recommended|false|
195237
|Settings||
196-
|Options|`tagSequence`, `alphabetizeExtras`|
238+
|Options|`tagSequence`, `alphabetizeExtras`, `linesBetween`, `reportTagGroupSpacing`, `reportIntraTagGroupSpacing`|
197239

198240
<!-- assertions sortTags -->

0 commit comments

Comments
 (0)