Skip to content

Commit cc7f253

Browse files
committed
feat(type-formatting): enhance error detection and add unionSpacing option; fixes #1143
1 parent 81cb787 commit cc7f253

File tree

6 files changed

+258
-116
lines changed

6 files changed

+258
-116
lines changed

.README/rules/type-formatting.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ property-value field. Defaults to the empty string.
5757
Whether to apply the `objectFieldSeparator` when there is only one
5858
property-value object field present. Defaults to `false`.
5959

60+
### `unionSpacing`
61+
62+
Determines the spacing to add to unions (`|`). Defaults to a single space.
63+
6064
|||
6165
|---|---|
6266
|Context|everywhere|
6367
|Tags|``|
6468
|Recommended|false|
6569
|Settings||
66-
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `propertyQuotes`, `separatorForSingleObjectField`, `stringQuotes`|
70+
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `propertyQuotes`, `separatorForSingleObjectField`, `stringQuotes`, `unionSpacing`|
6771

6872
## Failing examples
6973

docs/rules/type-formatting.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ property-value field. Defaults to the empty string.
7979
Whether to apply the `objectFieldSeparator` when there is only one
8080
property-value object field present. Defaults to `false`.
8181

82+
<a name="user-content-type-formatting-options-unionspacing"></a>
83+
<a name="type-formatting-options-unionspacing"></a>
84+
### <code>unionSpacing</code>
85+
86+
Determines the spacing to add to unions (`|`). Defaults to a single space.
87+
8288
|||
8389
|---|---|
8490
|Context|everywhere|
8591
|Tags|``|
8692
|Recommended|false|
8793
|Settings||
88-
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `propertyQuotes`, `separatorForSingleObjectField`, `stringQuotes`|
94+
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `propertyQuotes`, `separatorForSingleObjectField`, `stringQuotes`, `unionSpacing`|
8995

9096
<a name="user-content-type-formatting-failing-examples"></a>
9197
<a name="type-formatting-failing-examples"></a>
@@ -98,32 +104,32 @@ The following patterns are considered problems:
98104
* @param {{a: string; b: number; c: boolean,}} cfg
99105
*/
100106
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldSeparator":"semicolon"}]
101-
// Message: Inconsistent semicolon usage
107+
// Message: Inconsistent semicolon separator usage
102108

103109
/**
104110
* @param {{a: string; b: number; c: boolean,}} cfg
105111
*/
106112
// Settings: {"jsdoc":{"mode":"permissive"}}
107113
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldSeparator":"semicolon"}]
108-
// Message: Inconsistent semicolon usage
114+
// Message: Inconsistent semicolon separator usage
109115

110116
/**
111117
* @param {{a: string; b: number; c: boolean,}} cfg
112118
*/
113119
// "jsdoc/type-formatting": ["error"|"warn", {"enableFixer":false,"objectFieldSeparator":"semicolon"}]
114-
// Message: Inconsistent semicolon usage
120+
// Message: Inconsistent semicolon separator usage
115121

116122
/**
117123
* @param {{a: string, b: number; c: boolean;}} cfg
118124
*/
119125
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldSeparator":"comma"}]
120-
// Message: Inconsistent comma usage
126+
// Message: Inconsistent comma separator usage
121127

122128
/**
123129
* @param {{a: string, b: number; c: boolean,}} cfg
124130
*/
125131
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldIndent":" ","objectFieldSeparator":"linebreak"}]
126-
// Message: Inconsistent linebreak usage
132+
// Message: Inconsistent linebreak separator usage
127133

128134
/**
129135
* @param {{
@@ -133,7 +139,7 @@ The following patterns are considered problems:
133139
* }} cfg
134140
*/
135141
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldIndent":" ","objectFieldSeparator":"linebreak"}]
136-
// Message: Inconsistent linebreak usage
142+
// Message: Inconsistent linebreak separator usage
137143

138144
/**
139145
* @param {'abc'} cfg
@@ -170,21 +176,21 @@ The following patterns are considered problems:
170176
* description
171177
*/
172178
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldIndent":" ","objectFieldSeparator":"semicolon","separatorForSingleObjectField":true}]
173-
// Message: Inconsistent semicolon usage
179+
// Message: Inconsistent semicolon separator usage
174180

175181
/** @param {{a: string, b: number; c: boolean,}} cfg */
176182
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldIndent":" ","objectFieldSeparator":"linebreak"}]
177-
// Message: Inconsistent linebreak usage
183+
// Message: Inconsistent linebreak separator usage
178184

179185
/**
180186
* @param {{a: string, b: number; c: boolean,}} cfg */
181187
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldIndent":" ","objectFieldSeparator":"linebreak"}]
182-
// Message: Inconsistent linebreak usage
188+
// Message: Inconsistent linebreak separator usage
183189

184190
/** @param {{a: string, b: number; c: boolean,}} cfg
185191
*/
186192
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldIndent":" ","objectFieldSeparator":"linebreak"}]
187-
// Message: Inconsistent linebreak usage
193+
// Message: Inconsistent linebreak separator usage
188194

189195
/**
190196
* @param {{
@@ -194,7 +200,27 @@ The following patterns are considered problems:
194200
* description
195201
*/
196202
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldIndent":" ","objectFieldSeparator":"semicolon-and-linebreak"}]
197-
// Message: Inconsistent semicolon-and-linebreak usage
203+
// Message: Inconsistent semicolon-and-linebreak separator usage
204+
205+
/**
206+
* @param {ab | cd} cfg
207+
*/
208+
// "jsdoc/type-formatting": ["error"|"warn", {"unionSpacing":""}]
209+
// Message: Inconsistent "" union spacing usage
210+
211+
/**
212+
* @param {ab|cd} cfg
213+
*/
214+
// "jsdoc/type-formatting": ["error"|"warn", {"unionSpacing":" "}]
215+
// Message: Inconsistent " " union spacing usage
216+
217+
/**
218+
* Due to jsdoc-type-pratt-parser representing the separator at the
219+
* object level, the exact error will not be reported.
220+
* @param {{a: string, b: number; c: boolean,}} cfg
221+
*/
222+
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldSeparator":"comma"}]
223+
// Message: There was an error with type formatting
198224
````
199225

200226

@@ -226,13 +252,6 @@ The following patterns are not considered problems:
226252
*/
227253
// "jsdoc/type-formatting": ["error"|"warn", {"genericDot":true}]
228254

229-
/**
230-
* Due to jsdoc-type-pratt-parser representing the separator at the
231-
* object level, this will not be reported.
232-
* @param {{a: string, b: number; c: boolean,}} cfg
233-
*/
234-
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldSeparator":"comma"}]
235-
236255
/**
237256
* @param {A<} badParam
238257
*/
@@ -251,6 +270,16 @@ The following patterns are not considered problems:
251270
*/
252271
// "jsdoc/type-formatting": ["error"|"warn", {"propertyQuotes":null}]
253272

273+
/**
274+
* @param {ab | cd} cfg
275+
*/
276+
// "jsdoc/type-formatting": ["error"|"warn", {"unionSpacing":" "}]
277+
278+
/**
279+
* @param {ab|cd} cfg
280+
*/
281+
// "jsdoc/type-formatting": ["error"|"warn", {"unionSpacing":""}]
282+
254283
/**
255284
* @param cfg
256285
*/

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"url": "http://gajus.com"
66
},
77
"dependencies": {
8-
"@es-joy/jsdoccomment": "~0.57.0",
8+
"@es-joy/jsdoccomment": "~0.58.0",
99
"are-docs-informative": "^0.0.2",
1010
"comment-parser": "1.4.1",
1111
"debug": "^4.4.1",
@@ -56,15 +56,15 @@
5656
"glob": "^11.0.3",
5757
"globals": "^16.4.0",
5858
"husky": "^9.1.7",
59-
"jsdoc-type-pratt-parser": "^5.2.0",
59+
"jsdoc-type-pratt-parser": "^5.4.0",
6060
"json-schema": "^0.4.0",
6161
"json-schema-to-typescript": "^15.0.4",
6262
"lint-staged": "^16.1.6",
6363
"mocha": "^11.7.2",
6464
"open-editor": "^5.1.0",
6565
"replace": "^1.2.2",
6666
"rimraf": "^6.0.1",
67-
"semantic-release": "^24.2.7",
67+
"semantic-release": "^24.2.8",
6868
"typescript": "5.9.2",
6969
"typescript-eslint": "^8.43.0"
7070
},

0 commit comments

Comments
 (0)