Skip to content

Commit 22918c7

Browse files
committed
BREAKING CHANGE: change <> to no longer apply to SomeType.<> but instead to now support SomeType<>
feat: pseudo-type `[]` to catch parent array types of form `string[]`, `number[]`, etc. feat: support `.<>` as separate type fix: ensure working with nested type arrays/objects fix: ensure fixer preserves angle-bracket-dot or square bracket notation for arrays/objects chore: Update husky, semantic-release devDeps; add `typescript` devDep for `type-fest` peer dep. (used indirectly by husky and semantic-release) Breaking change through `jsdoctypeparser` update.
1 parent 9b5dfa4 commit 22918c7

File tree

8 files changed

+1656
-159
lines changed

8 files changed

+1656
-159
lines changed

.README/README.md

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,37 @@ but restricted to `@param`. These settings are now deprecated.
226226
- `settings.jsdoc.preferredTypes` An option map to indicate preferred
227227
or forbidden types (if default types are indicated here, these will
228228
have precedence over the default recommendations for `check-types`).
229-
The keys of this map are the types to be replaced (or forbidden) and
230-
can include the "ANY" type, `*`.
229+
The keys of this map are the types to be replaced (or forbidden).
230+
These keys may include:
231+
1. The "ANY" type, `*`
232+
1. The pseudo-type `[]` which we use to denote the parent (array)
233+
types used in the syntax `string[]`, `number[]`, etc.
234+
1. The pseudo-type `.<>` (or `.`) to represent the format `Array.<value>`
235+
or `Object.<key, value>`
236+
1. The pseudo-type `<>` to represent the format `Array<value>` or
237+
`Object<key, value>`
238+
1. A plain string type, e.g., `MyType`
239+
1. A plain string type followed by one of the above pseudo-types (except
240+
for `[]` which is always assumed to be an `Array`), e.g., `Array.`, or
241+
`SpecialObject<>`.
242+
243+
If a bare pseudo-type is used, it will match all parent types of that form.
244+
If a pseudo-type prefixed with a type name is used, it will only match
245+
parent types of that form and type name.
246+
231247
The values can be:
232248
- `false` to forbid the type
233249
- a string to indicate the type that should be preferred in its place
234-
(and which `fix` mode can replace)
250+
(and which `fix` mode can replace); this can be one of the formats
251+
of the keys described above. Note that the format will not be changed
252+
unless you use a pseudo-type in the replacement (e.g.,
253+
`'Array.<>': 'MyArray'` will change `Array.<string>` to `MyArray.<string>`,
254+
preserving the dot; to get rid of the dot, you must use the pseudo-type:
255+
`'Array.<>': 'MyArray<>'` which will change `Array.<string>` to
256+
`MyArray<string>`). If you use a bare pseudo-type in the replacement,
257+
e.g., `'MyArray.<>': '<>'`, the type will be converted to the format
258+
of the pseudo-type without changing the type name, i.e., `MyArray.<string>`
259+
will become `MyArray<string>` but `Array.<string>` will not be modified.
235260
- an object with the key `message` to provide a specific error message
236261
when encountering the discouraged type and, if a type is to be preferred
237262
in its place, the key `replacement` to indicate the type that should be
@@ -247,9 +272,9 @@ If `no-undefined-types` has the option key `preferredTypesDefined` set to
247272
map will be assumed to be defined.
248273

249274
See the option of `check-types`, `unifyParentAndChildTypeChecks`, for
250-
how the keys of `preferredTypes` may have `<>` appended and its bearing
251-
on whether types are checked as parents/children only (e.g., to match `Array`
252-
if the type is `Array` vs. `Array.<string>`).
275+
how the keys of `preferredTypes` may have `<>` or `.<>` (or just `.`)
276+
appended and its bearing on whether types are checked as parents/children
277+
only (e.g., to match `Array` if the type is `Array` vs. `Array.<string>`).
253278

254279
### Settings to Configure `valid-types`
255280

.README/rules/check-types.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,25 @@ RegExp
2525
- with the key `noDefaults` to insist that only the supplied option type
2626
map is to be used, and that the default preferences (such as "string"
2727
over "String") will not be enforced.
28-
- with the key `unifyParentAndChildTypeChecks` to treat
29-
`settings.jsdoc.preferredTypes` keys the same whether they are of the form
30-
`SomeType` or `SomeType<>`. If this is `false` or unset, the former
31-
will only apply to types which are not parent types/unions whereas the
32-
latter will only apply for parent types/unions.
28+
- with the key `unifyParentAndChildTypeChecks` which will treat
29+
`settings.jsdoc.preferredTypes` keys such as `SomeType` as matching
30+
not only child types such as an unadorned `SomeType` but also
31+
`SomeType<aChildType>`, `SomeType.<aChildType>`, or if `SomeType` is
32+
`Array` (or `[]`), it will match `aChildType[]`. If this is `false` or
33+
unset, the former format will only apply to types which are not parent
34+
types/unions whereas the latter formats will only apply for parent
35+
types/unions. The special types `[]`, `.<>` (or `.`), and `<>`
36+
act only as parent types (and will not match a bare child type such as
37+
`Array` even when unified, though, as mentioned, `Array` will match
38+
say `string[]` or `Array.<string>` when unified). The special type
39+
`*` is only a child type. Note that there is no detection of parent
40+
and child type together, e.g., you cannot specify preferences for
41+
`string[]` specifically as distinct from say `number[]`, but you can
42+
target both with `[]` or the child types `number` or `string`.
3343

3444
See also the documentation on `settings.jsdoc.preferredTypes` which impacts
3545
the behavior of `check-types`.
3646

37-
38-
3947
#### Why not capital case everything?
4048

4149
Why are `boolean`, `number` and `string` exempt from starting with a capital letter? Let's take `string` as an example. In Javascript, everything is an object. The string Object has prototypes for string functions such as `.toUpperCase()`.

0 commit comments

Comments
 (0)