Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .README/rules/type-formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Determines the spacing to add to unions (`|`). Defaults to a single space (`" "`
|Tags|`param`, `property`, `returns`, `this`, `throws`, `type`, `typedef`, `yields`|
|Recommended|false|
|Settings|`mode`|
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `propertyQuotes`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|

## Failing examples

Expand Down
24 changes: 1 addition & 23 deletions docs/rules/type-formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Determines the spacing to add to unions (`|`). Defaults to a single space (`" "`
|Tags|`param`, `property`, `returns`, `this`, `throws`, `type`, `typedef`, `yields`|
|Recommended|false|
|Settings|`mode`|
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `propertyQuotes`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|
|Options|`arrayBrackets`, `enableFixer`, `genericDot`, `objectFieldIndent`, `objectFieldQuote`, `objectFieldSeparator`, `objectFieldSeparatorOptionalLinebreak`, `objectFieldSeparatorTrailingPunctuation`, `separatorForSingleObjectField`, `stringQuotes`, `typeBracketSpacing`, `unionSpacing`|

<a name="user-content-type-formatting-failing-examples"></a>
<a name="type-formatting-failing-examples"></a>
Expand Down Expand Up @@ -204,12 +204,6 @@ The following patterns are considered problems:
*/
// Message: Inconsistent object field quotes null

/**
* @param {ab.cd.ef} cfg
*/
// "jsdoc/type-formatting": ["error"|"warn", {"propertyQuotes":"double"}]
// Message: Inconsistent double property quotes usage

/**
* @param {{a: string}} cfg A long
* description
Expand Down Expand Up @@ -285,12 +279,6 @@ The following patterns are considered problems:
// "jsdoc/type-formatting": ["error"|"warn", {"typeBracketSpacing":""}]
// Message: Must have no initial spacing

/**
* @param {ab."cd".ef} cfg
*/
// "jsdoc/type-formatting": ["error"|"warn", {"propertyQuotes":null}]
// Message: Inconsistent null property quotes usage

/**
* @param {{a: string, b: number}} cfg
*/
Expand Down Expand Up @@ -358,16 +346,6 @@ The following patterns are not considered problems:
*/
// "jsdoc/type-formatting": ["error"|"warn", {"objectFieldQuote":"double"}]

/**
* @param {ab.cd.ef} cfg
*/
// "jsdoc/type-formatting": ["error"|"warn", {"propertyQuotes":null}]

/**
* @param {ab."cd ef".gh} cfg
*/
// "jsdoc/type-formatting": ["error"|"warn", {"propertyQuotes":null}]

/**
* @param {ab | cd} cfg
*/
Expand Down
39 changes: 20 additions & 19 deletions src/rules/typeFormatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default iterateJsdoc(({
objectFieldSeparator = 'comma',
objectFieldSeparatorOptionalLinebreak = true,
objectFieldSeparatorTrailingPunctuation = false,
propertyQuotes = null,
// propertyQuotes = null,
separatorForSingleObjectField = false,
stringQuotes = 'single',
typeBracketSpacing = '',
Expand Down Expand Up @@ -277,19 +277,20 @@ export default iterateJsdoc(({
break;
}

case 'JsdocTypeProperty': {
const typeNode = /** @type {import('jsdoc-type-pratt-parser').PropertyResult} */ (nde);
// Only suitable for namepaths (and would need changes); see https://github.com/gajus/eslint-plugin-jsdoc/issues/1524
// case 'JsdocTypeProperty': {
// const typeNode = /** @type {import('jsdoc-type-pratt-parser').PropertyResult} */ (nde);

if ((propertyQuotes ||
(typeof typeNode.value === 'string' && !(/\s/v).test(typeNode.value))) &&
typeNode.meta.quote !== (propertyQuotes ?? undefined)
) {
typeNode.meta.quote = propertyQuotes ?? undefined;
errorMessage = `Inconsistent ${propertyQuotes} property quotes usage`;
}
// if ((propertyQuotes ||
// (typeof typeNode.value === 'string' && !(/\s/v).test(typeNode.value))) &&
// typeNode.meta.quote !== (propertyQuotes ?? undefined)
// ) {
// typeNode.meta.quote = propertyQuotes ?? undefined;
// errorMessage = `Inconsistent ${propertyQuotes} property quotes usage`;
// }

break;
}
// break;
// }

case 'JsdocTypeStringValue': {
const typeNode = /** @type {import('jsdoc-type-pratt-parser').StringValueResult} */ (nde);
Expand Down Expand Up @@ -405,13 +406,13 @@ export default iterateJsdoc(({
objectFieldSeparatorTrailingPunctuation: {
type: 'boolean',
},
propertyQuotes: {
enum: [
'double',
'single',
null,
],
},
// propertyQuotes: {
// enum: [
// 'double',
// 'single',
// null,
// ],
// },
separatorForSingleObjectField: {
type: 'boolean',
},
Expand Down
148 changes: 74 additions & 74 deletions test/rules/assertions/typeFormatting.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,33 +287,33 @@ export default {
*/
`,
},
{
code: `
/**
* @param {ab.cd.ef} cfg
*/
`,
errors: [
{
line: 3,
message: 'Inconsistent double property quotes usage',
},
{
line: 3,
message: 'Inconsistent double property quotes usage',
},
],
options: [
{
propertyQuotes: 'double',
},
],
output: `
/**
* @param {ab."cd"."ef"} cfg
*/
`,
},
// {
// code: `
// /**
// * @param {ab.cd.ef} cfg
// */
// `,
// errors: [
// {
// line: 3,
// message: 'Inconsistent double property quotes usage',
// },
// {
// line: 3,
// message: 'Inconsistent double property quotes usage',
// },
// ],
// options: [
// {
// propertyQuotes: 'double',
// },
// ],
// output: `
// /**
// * @param {ab."cd"."ef"} cfg
// */
// `,
// },
{
code: `
/**
Expand Down Expand Up @@ -627,29 +627,29 @@ export default {
*/
`,
},
{
code: `
/**
* @param {ab."cd".ef} cfg
*/
`,
errors: [
{
line: 3,
message: 'Inconsistent null property quotes usage',
},
],
options: [
{
propertyQuotes: null,
},
],
output: `
/**
* @param {ab.cd.ef} cfg
*/
`,
},
// {
// code: `
// /**
// * @param {ab."cd".ef} cfg
// */
// `,
// errors: [
// {
// line: 3,
// message: 'Inconsistent null property quotes usage',
// },
// ],
// options: [
// {
// propertyQuotes: null,
// },
// ],
// output: `
// /**
// * @param {ab.cd.ef} cfg
// */
// `,
// },
{
code: `
/**
Expand Down Expand Up @@ -801,30 +801,30 @@ export default {
},
],
},
{
code: `
/**
* @param {ab.cd.ef} cfg
*/
`,
options: [
{
propertyQuotes: null,
},
],
},
{
code: `
/**
* @param {ab."cd ef".gh} cfg
*/
`,
options: [
{
propertyQuotes: null,
},
],
},
// {
// code: `
// /**
// * @param {ab.cd.ef} cfg
// */
// `,
// options: [
// {
// propertyQuotes: null,
// },
// ],
// },
// {
// code: `
// /**
// * @param {ab."cd ef".gh} cfg
// */
// `,
// options: [
// {
// propertyQuotes: null,
// },
// ],
// },
{
code: `
/**
Expand Down
Loading