Skip to content

Commit a361dc9

Browse files
committed
feat(type-formatting): add spacing for functions/classes and method quotes
1 parent ecf3a4a commit a361dc9

File tree

5 files changed

+881
-21
lines changed

5 files changed

+881
-21
lines changed

.README/rules/type-formatting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Currently offers the following options for formatting types.
1818
|Tags|`param`, `property`, `returns`, `this`, `throws`, `type`, `typedef`, `yields`|
1919
|Recommended|false|
2020
|Settings|`mode`|
21-
|Options|`arrayBrackets`, `enableFixer`, `genericAndTupleElementSpacing`, `genericDot`, `keyValuePostColonSpacing`, `keyValuePostKeySpacing`, `keyValuePostOptionalSpacing`, `keyValuePostVariadicSpacing`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `parameterDefaultValueSpacing`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|
21+
|Options|`arrayBrackets`, `arrowFunctionPostReturnMarkerSpacing`, `arrowFunctionPreReturnMarkerSpacing`, `enableFixer`, `functionOrClassParameterSpacing`, `functionOrClassPostGenericSpacing`, `functionOrClassPostReturnMarkerSpacing`, `functionOrClassPreReturnMarkerSpacing`, `functionOrClassTypeParameterSpacing`, `genericAndTupleElementSpacing`, `genericDot`, `keyValuePostColonSpacing`, `keyValuePostKeySpacing`, `keyValuePostOptionalSpacing`, `keyValuePostVariadicSpacing`, `methodQuotes`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `parameterDefaultValueSpacing`, `postMethodNameSpacing`, `postNewSpacing`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|
2222

2323
## Failing examples
2424

docs/rules/type-formatting.md

Lines changed: 193 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,59 @@ A single options object has the following properties.
2222

2323
Determines how array generics are represented. Set to `angle` for the style `Array<type>` or `square` for the style `type[]`. Defaults to "square".
2424

25+
<a name="user-content-type-formatting-options-arrowfunctionpostreturnmarkerspacing"></a>
26+
<a name="type-formatting-options-arrowfunctionpostreturnmarkerspacing"></a>
27+
### <code>arrowFunctionPostReturnMarkerSpacing</code>
28+
29+
The space character (if any) to use after return markers (`=>`). Defaults to " ".
30+
31+
<a name="user-content-type-formatting-options-arrowfunctionprereturnmarkerspacing"></a>
32+
<a name="type-formatting-options-arrowfunctionprereturnmarkerspacing"></a>
33+
### <code>arrowFunctionPreReturnMarkerSpacing</code>
34+
35+
The space character (if any) to use before return markers (`=>`). Defaults to " ".
36+
2537
<a name="user-content-type-formatting-options-enablefixer"></a>
2638
<a name="type-formatting-options-enablefixer"></a>
2739
### <code>enableFixer</code>
2840

2941
Whether to enable the fixer. Defaults to `true`.
3042

43+
<a name="user-content-type-formatting-options-functionorclassparameterspacing"></a>
44+
<a name="type-formatting-options-functionorclassparameterspacing"></a>
45+
### <code>functionOrClassParameterSpacing</code>
46+
47+
The space character (if any) to use between function or class parameters. Defaults to " ".
48+
49+
<a name="user-content-type-formatting-options-functionorclasspostgenericspacing"></a>
50+
<a name="type-formatting-options-functionorclasspostgenericspacing"></a>
51+
### <code>functionOrClassPostGenericSpacing</code>
52+
53+
The space character (if any) to use after a generic expression in a function or class. Defaults to "".
54+
55+
<a name="user-content-type-formatting-options-functionorclasspostreturnmarkerspacing"></a>
56+
<a name="type-formatting-options-functionorclasspostreturnmarkerspacing"></a>
57+
### <code>functionOrClassPostReturnMarkerSpacing</code>
58+
59+
The space character (if any) to use after return markers (`:`). Defaults to "".
60+
61+
<a name="user-content-type-formatting-options-functionorclassprereturnmarkerspacing"></a>
62+
<a name="type-formatting-options-functionorclassprereturnmarkerspacing"></a>
63+
### <code>functionOrClassPreReturnMarkerSpacing</code>
64+
65+
The space character (if any) to use before return markers (`:`). Defaults to "".
66+
67+
<a name="user-content-type-formatting-options-functionorclasstypeparameterspacing"></a>
68+
<a name="type-formatting-options-functionorclasstypeparameterspacing"></a>
69+
### <code>functionOrClassTypeParameterSpacing</code>
70+
71+
The space character (if any) to use between type parameters in a function or class. Defaults to " ".
72+
3173
<a name="user-content-type-formatting-options-genericandtupleelementspacing"></a>
3274
<a name="type-formatting-options-genericandtupleelementspacing"></a>
3375
### <code>genericAndTupleElementSpacing</code>
3476

35-
The space character (if any) to use between elements in generics and tuples
77+
The space character (if any) to use between elements in generics and tuples. Defaults to " ".
3678

3779
<a name="user-content-type-formatting-options-genericdot"></a>
3880
<a name="type-formatting-options-genericdot"></a>
@@ -44,25 +86,31 @@ Boolean value of whether to use a dot before the angled brackets of a generic (e
4486
<a name="type-formatting-options-keyvaluepostcolonspacing"></a>
4587
### <code>keyValuePostColonSpacing</code>
4688

47-
The amount of spacing (if any) after the colon of a key-value or object-field pair
89+
The amount of spacing (if any) after the colon of a key-value or object-field pair. Defaults to " ".
4890

4991
<a name="user-content-type-formatting-options-keyvaluepostkeyspacing"></a>
5092
<a name="type-formatting-options-keyvaluepostkeyspacing"></a>
5193
### <code>keyValuePostKeySpacing</code>
5294

53-
The amount of spacing (if any) immediately after keys in a key-value or object-field pair
95+
The amount of spacing (if any) immediately after keys in a key-value or object-field pair. Defaults to "".
5496

5597
<a name="user-content-type-formatting-options-keyvaluepostoptionalspacing"></a>
5698
<a name="type-formatting-options-keyvaluepostoptionalspacing"></a>
5799
### <code>keyValuePostOptionalSpacing</code>
58100

59-
The amount of spacing (if any) after the optional operator (`?`) in a key-value or object-field pair
101+
The amount of spacing (if any) after the optional operator (`?`) in a key-value or object-field pair. Defaults to "".
60102

61103
<a name="user-content-type-formatting-options-keyvaluepostvariadicspacing"></a>
62104
<a name="type-formatting-options-keyvaluepostvariadicspacing"></a>
63105
### <code>keyValuePostVariadicSpacing</code>
64106

65-
The amount of spacing (if any) after a variadic operator (`...`) in a key-value pair
107+
The amount of spacing (if any) after a variadic operator (`...`) in a key-value pair. Defaults to "".
108+
109+
<a name="user-content-type-formatting-options-methodquotes"></a>
110+
<a name="type-formatting-options-methodquotes"></a>
111+
### <code>methodQuotes</code>
112+
113+
The style of quotation mark for surrounding method names when quoted. Defaults to `double`
66114

67115
<a name="user-content-type-formatting-options-objectfieldindent"></a>
68116
<a name="type-formatting-options-objectfieldindent"></a>
@@ -113,7 +161,19 @@ Defaults to `false`.
113161
<a name="type-formatting-options-parameterdefaultvaluespacing"></a>
114162
### <code>parameterDefaultValueSpacing</code>
115163

116-
The space character (if any) to use between the equal signs of a default value
164+
The space character (if any) to use between the equal signs of a default value. Defaults to " ".
165+
166+
<a name="user-content-type-formatting-options-postmethodnamespacing"></a>
167+
<a name="type-formatting-options-postmethodnamespacing"></a>
168+
### <code>postMethodNameSpacing</code>
169+
170+
The space character (if any) to add after a method name. Defaults to "".
171+
172+
<a name="user-content-type-formatting-options-postnewspacing"></a>
173+
<a name="type-formatting-options-postnewspacing"></a>
174+
### <code>postNewSpacing</code>
175+
176+
The space character (if any) to add after "new" in a constructor. Defaults to " ".
117177

118178
<a name="user-content-type-formatting-options-separatorforsingleobjectfield"></a>
119179
<a name="type-formatting-options-separatorforsingleobjectfield"></a>
@@ -150,7 +210,7 @@ Determines the spacing to add to unions (`|`). Defaults to a single space (`" "`
150210
|Tags|`param`, `property`, `returns`, `this`, `throws`, `type`, `typedef`, `yields`|
151211
|Recommended|false|
152212
|Settings|`mode`|
153-
|Options|`arrayBrackets`, `enableFixer`, `genericAndTupleElementSpacing`, `genericDot`, `keyValuePostColonSpacing`, `keyValuePostKeySpacing`, `keyValuePostOptionalSpacing`, `keyValuePostVariadicSpacing`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `parameterDefaultValueSpacing`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|
213+
|Options|`arrayBrackets`, `arrowFunctionPostReturnMarkerSpacing`, `arrowFunctionPreReturnMarkerSpacing`, `enableFixer`, `functionOrClassParameterSpacing`, `functionOrClassPostGenericSpacing`, `functionOrClassPostReturnMarkerSpacing`, `functionOrClassPreReturnMarkerSpacing`, `functionOrClassTypeParameterSpacing`, `genericAndTupleElementSpacing`, `genericDot`, `keyValuePostColonSpacing`, `keyValuePostKeySpacing`, `keyValuePostOptionalSpacing`, `keyValuePostVariadicSpacing`, `methodQuotes`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `parameterDefaultValueSpacing`, `postMethodNameSpacing`, `postNewSpacing`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|
154214

155215
<a name="user-content-type-formatting-failing-examples"></a>
156216
<a name="type-formatting-failing-examples"></a>
@@ -378,6 +438,72 @@ The following patterns are considered problems:
378438
*/
379439
// "jsdoc/type-formatting": ["error"|"warn", {"keyValuePostOptionalSpacing":" "}]
380440
// Message: Post optional (`?`) spacing should be " "
441+
442+
/**
443+
* @param {() => void} cfg
444+
*/
445+
// "jsdoc/type-formatting": ["error"|"warn", {"arrowFunctionPostReturnMarkerSpacing":""}]
446+
// Message: Post-return-marker spacing should be ""
447+
448+
/**
449+
* @param {() => void} cfg
450+
*/
451+
// "jsdoc/type-formatting": ["error"|"warn", {"arrowFunctionPreReturnMarkerSpacing":""}]
452+
// Message: Pre-return-marker spacing should be ""
453+
454+
/**
455+
* @param {{hello(): void}} cfg
456+
*/
457+
// "jsdoc/type-formatting": ["error"|"warn", {"postMethodNameSpacing":" "}]
458+
// Message: Post-method-name spacing should be " "
459+
460+
/**
461+
* @param {{new (): void}} cfg
462+
*/
463+
// "jsdoc/type-formatting": ["error"|"warn", {"postNewSpacing":""}]
464+
// Message: Post-`new` spacing should be ""
465+
466+
/**
467+
* @param {function(): void} cfg
468+
*/
469+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassPreReturnMarkerSpacing":" "}]
470+
// Message: Pre-return-marker spacing should be " "
471+
472+
/**
473+
* @param {{new (): void}} cfg
474+
*/
475+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassPostReturnMarkerSpacing":""}]
476+
// Message: Post-return-marker spacing should be ""
477+
478+
/**
479+
* @param {{method(a: string, b: number): void}} cfg
480+
*/
481+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassParameterSpacing":""}]
482+
// Message: Parameter spacing should be ""
483+
484+
/**
485+
* @param {{method<T>(a: T, b: number): void}} cfg
486+
*/
487+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassPostGenericSpacing":" "}]
488+
// Message: Post-generic spacing should be " "
489+
490+
/**
491+
* @param {{method<T, U>(a: T, b: U): void}} cfg
492+
*/
493+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassTypeParameterSpacing":""}]
494+
// Message: Type parameter spacing should be ""
495+
496+
/**
497+
* @param {{'some-method'(a: string, b: number): void}} cfg
498+
*/
499+
// "jsdoc/type-formatting": ["error"|"warn", {"methodQuotes":"double"}]
500+
// Message: Method quoting style should be "double"
501+
502+
/**
503+
* @param {[a: string, ...b: number]} cfg
504+
*/
505+
// "jsdoc/type-formatting": ["error"|"warn", {"keyValuePostVariadicSpacing":" "}]
506+
// Message: Post variadic (`...`) spacing should be " "
381507
````
382508

383509

@@ -463,6 +589,11 @@ The following patterns are not considered problems:
463589
*/
464590
// "jsdoc/type-formatting": ["error"|"warn", {"genericAndTupleElementSpacing":""}]
465591

592+
/**
593+
* @param {SomeType<T, U>} cfg
594+
*/
595+
// "jsdoc/type-formatting": ["error"|"warn", {"genericAndTupleElementSpacing":" "}]
596+
466597
/**
467598
* @param {[string,number]} cfg
468599
*/
@@ -502,5 +633,60 @@ The following patterns are not considered problems:
502633
* @param {[a? : 3]} cfg
503634
*/
504635
// "jsdoc/type-formatting": ["error"|"warn", {"keyValuePostOptionalSpacing":" "}]
636+
637+
/**
638+
* @param {() =>void} cfg
639+
*/
640+
// "jsdoc/type-formatting": ["error"|"warn", {"arrowFunctionPostReturnMarkerSpacing":""}]
641+
642+
/**
643+
* @param {()=> void} cfg
644+
*/
645+
// "jsdoc/type-formatting": ["error"|"warn", {"arrowFunctionPreReturnMarkerSpacing":""}]
646+
647+
/**
648+
* @param {{hello (): void}} cfg
649+
*/
650+
// "jsdoc/type-formatting": ["error"|"warn", {"postMethodNameSpacing":" "}]
651+
652+
/**
653+
* @param {{new(): void}} cfg
654+
*/
655+
// "jsdoc/type-formatting": ["error"|"warn", {"postNewSpacing":""}]
656+
657+
/**
658+
* @param {{new (): void}} cfg
659+
*/
660+
// "jsdoc/type-formatting": ["error"|"warn", {"postNewSpacing":" "}]
661+
662+
/**
663+
* @param {function() : void} cfg
664+
*/
665+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassPreReturnMarkerSpacing":" "}]
666+
667+
/**
668+
* @param {{new ():void}} cfg
669+
*/
670+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassPostReturnMarkerSpacing":""}]
671+
672+
/**
673+
* @param {{method(a: string,b: number): void}} cfg
674+
*/
675+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassParameterSpacing":""}]
676+
677+
/**
678+
* @param {{method<T> (a: T, b: number): void}} cfg
679+
*/
680+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassPostGenericSpacing":" "}]
681+
682+
/**
683+
* @param {{method<T,U>(a: T, b: U): void}} cfg
684+
*/
685+
// "jsdoc/type-formatting": ["error"|"warn", {"functionOrClassTypeParameterSpacing":""}]
686+
687+
/**
688+
* @param {{"some-method"(a: string, b: number): void}} cfg
689+
*/
690+
// "jsdoc/type-formatting": ["error"|"warn", {"methodQuotes":"double"}]
505691
````
506692

src/rules.d.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,34 +2947,66 @@ export interface Rules {
29472947
* Determines how array generics are represented. Set to `angle` for the style `Array<type>` or `square` for the style `type[]`. Defaults to "square".
29482948
*/
29492949
arrayBrackets?: "angle" | "square";
2950+
/**
2951+
* The space character (if any) to use after return markers (`=>`). Defaults to " ".
2952+
*/
2953+
arrowFunctionPostReturnMarkerSpacing?: string;
2954+
/**
2955+
* The space character (if any) to use before return markers (`=>`). Defaults to " ".
2956+
*/
2957+
arrowFunctionPreReturnMarkerSpacing?: string;
29502958
/**
29512959
* Whether to enable the fixer. Defaults to `true`.
29522960
*/
29532961
enableFixer?: boolean;
29542962
/**
2955-
* The space character (if any) to use between elements in generics and tuples
2963+
* The space character (if any) to use between function or class parameters. Defaults to " ".
2964+
*/
2965+
functionOrClassParameterSpacing?: string;
2966+
/**
2967+
* The space character (if any) to use after a generic expression in a function or class. Defaults to "".
2968+
*/
2969+
functionOrClassPostGenericSpacing?: string;
2970+
/**
2971+
* The space character (if any) to use after return markers (`:`). Defaults to "".
2972+
*/
2973+
functionOrClassPostReturnMarkerSpacing?: string;
2974+
/**
2975+
* The space character (if any) to use before return markers (`:`). Defaults to "".
2976+
*/
2977+
functionOrClassPreReturnMarkerSpacing?: string;
2978+
/**
2979+
* The space character (if any) to use between type parameters in a function or class. Defaults to " ".
2980+
*/
2981+
functionOrClassTypeParameterSpacing?: string;
2982+
/**
2983+
* The space character (if any) to use between elements in generics and tuples. Defaults to " ".
29562984
*/
29572985
genericAndTupleElementSpacing?: string;
29582986
/**
29592987
* Boolean value of whether to use a dot before the angled brackets of a generic (e.g., `SomeType.<AnotherType>`). Defaults to `false`.
29602988
*/
29612989
genericDot?: boolean;
29622990
/**
2963-
* The amount of spacing (if any) after the colon of a key-value or object-field pair
2991+
* The amount of spacing (if any) after the colon of a key-value or object-field pair. Defaults to " ".
29642992
*/
29652993
keyValuePostColonSpacing?: string;
29662994
/**
2967-
* The amount of spacing (if any) immediately after keys in a key-value or object-field pair
2995+
* The amount of spacing (if any) immediately after keys in a key-value or object-field pair. Defaults to "".
29682996
*/
29692997
keyValuePostKeySpacing?: string;
29702998
/**
2971-
* The amount of spacing (if any) after the optional operator (`?`) in a key-value or object-field pair
2999+
* The amount of spacing (if any) after the optional operator (`?`) in a key-value or object-field pair. Defaults to "".
29723000
*/
29733001
keyValuePostOptionalSpacing?: string;
29743002
/**
2975-
* The amount of spacing (if any) after a variadic operator (`...`) in a key-value pair
3003+
* The amount of spacing (if any) after a variadic operator (`...`) in a key-value pair. Defaults to "".
29763004
*/
29773005
keyValuePostVariadicSpacing?: string;
3006+
/**
3007+
* The style of quotation mark for surrounding method names when quoted. Defaults to `double`
3008+
*/
3009+
methodQuotes?: "double" | "single";
29783010
/**
29793011
* A string indicating the whitespace to be added on each line preceding an
29803012
* object property-value field. Defaults to the empty string.
@@ -3011,9 +3043,17 @@ export interface Rules {
30113043
*/
30123044
objectFieldSeparatorTrailingPunctuation?: boolean;
30133045
/**
3014-
* The space character (if any) to use between the equal signs of a default value
3046+
* The space character (if any) to use between the equal signs of a default value. Defaults to " ".
30153047
*/
30163048
parameterDefaultValueSpacing?: string;
3049+
/**
3050+
* The space character (if any) to add after a method name. Defaults to "".
3051+
*/
3052+
postMethodNameSpacing?: string;
3053+
/**
3054+
* The space character (if any) to add after "new" in a constructor. Defaults to " ".
3055+
*/
3056+
postNewSpacing?: string;
30173057
/**
30183058
* Whether to apply the `objectFieldSeparator` (e.g., a semicolon) when there
30193059
* is only one property-value object field present. Defaults to `false`.

0 commit comments

Comments
 (0)