Skip to content

Commit 84a1d31

Browse files
committed
test: complete coverage
1 parent 5852fd9 commit 84a1d31

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

docs/rules/type-formatting.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ The following patterns are considered problems:
188188
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldQuote":"double"}]
189189
// Message: Inconsistent object field quotes double
190190

191+
/**
192+
* @param {{"a": string}} cfg
193+
*/
194+
// Message: Inconsistent object field quotes null
195+
191196
/**
192197
* @param {ab.cd.ef} cfg
193198
*/
@@ -242,10 +247,12 @@ The following patterns are considered problems:
242247
// Message: Inconsistent "" union spacing usage
243248

244249
/**
250+
* Due to jsdoc-type-pratt-parser not consuming whitespace, the exact
251+
* error will not be reported.
245252
* @param {ab|cd} cfg
246253
*/
247254
// "jsdoc/type-formatting": ["error"|"warn", {"unionSpacing":" "}]
248-
// Message: Inconsistent " " union spacing usage
255+
// Message: There was an error with type formatting
249256

250257
/**
251258
* Due to jsdoc-type-pratt-parser representing the separator at the
@@ -266,6 +273,12 @@ The following patterns are considered problems:
266273
*/
267274
// "jsdoc/type-formatting": ["error"|"warn", {"typeBracketSpacing":""}]
268275
// Message: Must have no initial spacing
276+
277+
/**
278+
* @param {ab."cd".ef} cfg
279+
*/
280+
// "jsdoc/type-formatting": ["error"|"warn", {"propertyQuotes":null}]
281+
// Message: Inconsistent null property quotes usage
269282
````
270283

271284

src/rules/typeFormatting.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ export default iterateJsdoc(({
231231
case 'JsdocTypeObject': {
232232
const typeNode = /** @type {import('jsdoc-type-pratt-parser').ObjectResult} */ (nde);
233233
if (
234+
/* c8 ignore next -- Guard */
234235
(typeNode.meta.separator ?? 'comma') !== objectFieldSeparator ||
235236
(typeNode.meta.separatorForSingleObjectField ?? false) !== separatorForSingleObjectField ||
236237
(typeNode.meta.propertyIndent ?? '') !== objectFieldIndent ||
@@ -285,7 +286,8 @@ export default iterateJsdoc(({
285286

286287
case 'JsdocTypeUnion': {
287288
const typeNode = /** @type {import('jsdoc-type-pratt-parser').UnionResult} */ (nde);
288-
if (typeNode.meta?.spacing !== unionSpacing) {
289+
/* c8 ignore next -- Guard */
290+
if ((typeNode.meta?.spacing ?? ' ') !== unionSpacing) {
289291
typeNode.meta = {
290292
spacing: unionSpacing,
291293
};

test/rules/assertions/typeFormatting.js

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ export default {
269269
*/
270270
`,
271271
},
272+
{
273+
code: `
274+
/**
275+
* @param {{"a": string}} cfg
276+
*/
277+
`,
278+
errors: [
279+
{
280+
line: 3,
281+
message: 'Inconsistent object field quotes null',
282+
},
283+
],
284+
output: `
285+
/**
286+
* @param {{a: string}} cfg
287+
*/
288+
`,
289+
},
272290
{
273291
code: `
274292
/**
@@ -490,13 +508,15 @@ export default {
490508
{
491509
code: `
492510
/**
511+
* Due to jsdoc-type-pratt-parser not consuming whitespace, the exact
512+
* error will not be reported.
493513
* @param {ab|cd} cfg
494514
*/
495515
`,
496516
errors: [
497517
{
498-
line: 3,
499-
message: 'Inconsistent " " union spacing usage',
518+
line: 5,
519+
message: 'There was an error with type formatting',
500520
},
501521
],
502522
options: [
@@ -506,10 +526,34 @@ export default {
506526
],
507527
output: `
508528
/**
529+
* Due to jsdoc-type-pratt-parser not consuming whitespace, the exact
530+
* error will not be reported.
509531
* @param {ab | cd} cfg
510532
*/
511533
`,
512534
},
535+
{
536+
code: `
537+
/**
538+
* Due to jsdoc-type-pratt-parser not consuming whitespace, the exact
539+
* error will not be reported.
540+
* @param {ab|cd} cfg
541+
*/
542+
`,
543+
errors: [
544+
{
545+
line: 5,
546+
message: 'There was an error with type formatting',
547+
},
548+
],
549+
ignoreReadme: true,
550+
options: [
551+
{
552+
enableFixer: false,
553+
unionSpacing: ' ',
554+
},
555+
],
556+
},
513557
{
514558
code: `
515559
/**
@@ -583,6 +627,29 @@ export default {
583627
*/
584628
`,
585629
},
630+
{
631+
code: `
632+
/**
633+
* @param {ab."cd".ef} cfg
634+
*/
635+
`,
636+
errors: [
637+
{
638+
line: 3,
639+
message: 'Inconsistent null property quotes usage',
640+
},
641+
],
642+
options: [
643+
{
644+
propertyQuotes: null,
645+
},
646+
],
647+
output: `
648+
/**
649+
* @param {ab.cd.ef} cfg
650+
*/
651+
`,
652+
},
586653
],
587654
valid: [
588655
{

0 commit comments

Comments
 (0)