File tree Expand file tree Collapse file tree 4 files changed +58
-4
lines changed Expand file tree Collapse file tree 4 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,8 @@ Boolean value of whether to use a dot before the angled brackets of a generic (e
2626
2727Whether and how object field properties should be quoted (e.g., ` {"a": string} ` ).
2828Set to ` single ` , ` double ` , or ` null ` . Defaults to ` null ` (no quotes unless
29- required due to whitespace within the field).
29+ required due to special characters within the field). Digits will be kept as is,
30+ regardless of setting (they can either represent a digit or a string digit).
3031
3132### ` propertyQuotes `
3233
Original file line number Diff line number Diff line change @@ -38,7 +38,8 @@ Boolean value of whether to use a dot before the angled brackets of a generic (e
3838
3939Whether and how object field properties should be quoted (e.g., ` {"a": string} ` ).
4040Set to ` single ` , ` double ` , or ` null ` . Defaults to ` null ` (no quotes unless
41- required due to whitespace within the field).
41+ required due to special characters within the field). Digits will be kept as is,
42+ regardless of setting (they can either represent a digit or a string digit).
4243
4344<a name =" user-content-type-formatting-options-propertyquotes " ></a >
4445<a name =" type-formatting-options-propertyquotes " ></a >
@@ -319,6 +320,20 @@ The following patterns are not considered problems:
319320 * @param {{"a bc": string}} quotedKeyParam
320321 */
321322
323+ /**
324+ * @param {{55: string}} quotedKeyParam
325+ */
326+
327+ /**
328+ * @param {{"a-b-c": string}} quotedKeyParam
329+ */
330+ // "jsdoc/type-formatting": ["error"|"warn", {"objectFieldQuote":null}]
331+
332+ /**
333+ * @param {{55: string}} quotedKeyParam
334+ */
335+ // "jsdoc/type-formatting": ["error"|"warn", {"objectFieldQuote":"double"}]
336+
322337/**
323338 * @param {ab.cd.ef} cfg
324339 */
Original file line number Diff line number Diff line change @@ -250,8 +250,15 @@ export default iterateJsdoc(({
250250 case 'JsdocTypeObjectField' : {
251251 const typeNode = /** @type {import('jsdoc-type-pratt-parser').ObjectFieldResult } */ ( nde ) ;
252252 if ( ( objectFieldQuote ||
253- ( typeof typeNode . key === 'string' && ! ( / \s / v) . test ( typeNode . key ) ) ) &&
254- typeNode . meta . quote !== ( objectFieldQuote ?? undefined )
253+ ( typeof typeNode . key === 'string' &&
254+ (
255+ ( / ^ \p{ ID_Start} \p{ ID_Continue} * $ / v) . test ( typeNode . key ) ||
256+ ( / ^ ( \d + ( \. \d * ) ? | \. \d + ) ( [ e E ] [ \- + ] ? \d + ) ? $ / v) . test ( typeNode . key )
257+ )
258+ ) ) &&
259+ typeNode . meta . quote !== ( objectFieldQuote ?? undefined ) &&
260+ ( typeof typeNode . key !== 'string' ||
261+ ! ( / ^ ( \d + ( \. \d * ) ? | \. \d + ) ( [ e E ] [ \- + ] ? \d + ) ? $ / v) . test ( typeNode . key ) )
255262 ) {
256263 typeNode . meta . quote = objectFieldQuote ?? undefined ;
257264 errorMessage = `Inconsistent object field quotes ${ objectFieldQuote } ` ;
Original file line number Diff line number Diff line change @@ -714,6 +714,37 @@ export default {
714714 */
715715 ` ,
716716 } ,
717+ {
718+ code : `
719+ /**
720+ * @param {{55: string}} quotedKeyParam
721+ */
722+ ` ,
723+ } ,
724+ {
725+ code : `
726+ /**
727+ * @param {{"a-b-c": string}} quotedKeyParam
728+ */
729+ ` ,
730+ options : [
731+ {
732+ objectFieldQuote : null ,
733+ } ,
734+ ] ,
735+ } ,
736+ {
737+ code : `
738+ /**
739+ * @param {{55: string}} quotedKeyParam
740+ */
741+ ` ,
742+ options : [
743+ {
744+ objectFieldQuote : 'double' ,
745+ } ,
746+ ] ,
747+ } ,
717748 {
718749 code : `
719750 /**
You can’t perform that action at this time.
0 commit comments