diff --git a/README.md b/README.md index c528fdb13..52d79f4a3 100644 --- a/README.md +++ b/README.md @@ -2011,6 +2011,19 @@ const config = { // Options: ["always"] // Message: Expected JSDoc block lines to be aligned. +/** + * My object. + * + * @typedef {Object} MyObject + * + * @property {{a: number, b: string, c}} lorem Description. + * @property {Object.} sit Description multi words. + * @property {Object.} amet Description} weird {multi} {{words}}. + * @property {Object.} dolor + */ +// Options: ["always"] +// Message: Expected JSDoc block lines to be aligned. + /** * Not implemented yet. * @@ -2128,6 +2141,22 @@ const config = { */ // Options: ["always"] +/** + * My object. + * + * @typedef {Object} MyObject + * + * @property {{a: number, b: string, c}} lorem Description. + * @property {Object.} sit Description multi words. + * @property {Object.} amet Description} weird {multi} {{words}}. + * @property {Object.} dolor + */ +// Options: ["always"] + +/** @param {number} lorem */ +const fn = ( lorem ) => {} +// Options: ["always"] + /** * Not validating without option. * diff --git a/src/rules/checkLineAlignment.js b/src/rules/checkLineAlignment.js index 0d451bc23..318b1a168 100644 --- a/src/rules/checkLineAlignment.js +++ b/src/rules/checkLineAlignment.js @@ -31,7 +31,7 @@ const matchAll = (string, regexp, callback, limit) => { * @returns {string} The full description. */ const getFullDescription = (lineString) => { - return /(?:\S+\s+){4}(.*)/.exec(lineString)[1]; + return /\S+\s+(?:{{.*?}}|{.*?})\s+\S+\s+(.*)/.exec(lineString)[1]; }; /** @@ -139,7 +139,7 @@ const checkCommentPerTag = (comment, tag, tagIndentation, report) => { // All line parts until the first word of the description (if description exists). matchAll( lineString, - /\S+/g, + /{{.*?}}|{.*?}|\S+/g, ({0: match, index: position}, partIndex) => { set(partsMatrix, [lineIndex, partIndex], { position, @@ -187,6 +187,11 @@ export default iterateJsdoc(({ return; } + // Skip if it contains only a single line. + if (!jsdocNode.value.includes('\n')) { + return; + } + // `indent` is whitespace from line 1 (`/**`), so slice and account for "/". const tagIndentation = indent + ' '; diff --git a/test/rules/assertions/checkLineAlignment.js b/test/rules/assertions/checkLineAlignment.js index b58917690..ea8f391de 100644 --- a/test/rules/assertions/checkLineAlignment.js +++ b/test/rules/assertions/checkLineAlignment.js @@ -364,6 +364,41 @@ export default { */ `, }, + { + code: ` + /** + * My object. + * + * @typedef {Object} MyObject + * + * @property {{a: number, b: string, c}} lorem Description. + * @property {Object.} sit Description multi words. + * @property {Object.} amet Description} weird {multi} {{words}}. + * @property {Object.} dolor + */ + `, + errors: [ + { + message: 'Expected JSDoc block lines to be aligned.', + type: 'Block', + }, + ], + options: [ + 'always', + ], + output: ` + /** + * My object. + * + * @typedef {Object} MyObject + * + * @property {{a: number, b: string, c}} lorem Description. + * @property {Object.} sit Description multi words. + * @property {Object.} amet Description} weird {multi} {{words}}. + * @property {Object.} dolor + */ + `, + }, { code: ` /** @@ -549,6 +584,32 @@ export default { 'always', ], }, + { + code: ` + /** + * My object. + * + * @typedef {Object} MyObject + * + * @property {{a: number, b: string, c}} lorem Description. + * @property {Object.} sit Description multi words. + * @property {Object.} amet Description} weird {multi} {{words}}. + * @property {Object.} dolor + */ + `, + options: [ + 'always', + ], + }, + { + code: ` + /** @param {number} lorem */ + const fn = ( lorem ) => {} + `, + options: [ + 'always', + ], + }, { code: ` /**