You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: []}`
Copy file name to clipboardExpand all lines: .README/rules/sort-tags.md
+51-9Lines changed: 51 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,48 @@ Sorts tags by a specified sequence according to tag name.
4
4
5
5
(Default order originally inspired by [`@homer0/prettier-plugin-jsdoc`](https://github.com/homer0/packages/tree/main/packages/public/prettier-plugin-jsdoc).)
6
6
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
+
7
19
#### Options
8
20
9
21
##### `tagSequence`
10
22
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.
12
27
13
28
Tag names earlier in the list will be arranged first. The relative position of
14
29
tags of the same name will not be changed.
15
30
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.
20
39
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).
22
42
23
43
Please note that this order is still experimental, so if you want to retain
24
44
a fixed order that doesn't change into the future, supply your own
25
45
`tagSequence`.
26
46
27
47
```js
28
-
[
48
+
[{tags: [
29
49
// Brief descriptions
30
50
'summary',
31
51
'typeSummary',
@@ -178,7 +198,7 @@ a fixed order that doesn't change into the future, supply your own
178
198
'since',
179
199
'deprecated',
180
200
'todo',
181
-
];
201
+
]}];
182
202
```
183
203
184
204
##### `alphabetizeExtras`
@@ -187,12 +207,34 @@ Defaults to `false`. Alphabetizes any items not within `tagSequence` after any
187
207
items within `tagSequence` (or in place of the special `-other` pseudo-tag)
188
208
are sorted.
189
209
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`.
0 commit comments