【问题标题】:What is the proper/canonical formatting of long JSDoc lines?长 JSDoc 行的正确/规范格式是什么?
【发布时间】:2015-08-20 23:31:06
【问题描述】:

所有官方 JSDoc 示例都有非常简单的文档字符串,如下所示:

/**
 * @param {string} author - The author of the book.
 */

问题是,在现实生活中的文档中,您通常有更长的文档字符串:

/**
 * @param {string} author - The author of the book, presumably some person who writes well
 */

但由于大多数公司(出于合法的可读性原因)都有行长限制,因此上述内容通常是不可接受的。但是,我想不通的是打破这些线条的“正确”方式应该是什么。

我能做到:

/**
 * @param {string} author - The author of the book, presumably some
 * person who writes well
 */

但这很难阅读。我可以这样做:

/**
 * @param {string} author - The author of the book, presumably some
 *                          person who writes well
 */

这看起来更好,但它会导致大量的行,特别是如果参数名称很长:

/**
 * @param {string} personWhoIsTheAuthorOfTheBook - The author of the
 *                                                 book, presumably
 *                                                 some person who
 *                                                 writes well
 */

所以我的问题是,格式化长 @param 行(在代码中,而不是在生成的 JSDoc 中)的正确/官方/规范方式是什么……或者实际上任何长注释行。

【问题讨论】:

    标签: jsdoc


    【解决方案1】:

    在 JSDoc 中有两种处理换行符的正确方法。第一个,显然是 Google 使用的,是在第一行之后缩进:

    /**
     * @param {string} author - The author of the book, presumably some
     *     person who writes well and does so for a living. This is
     *     especially important for obvious reasons.
     */
    

    这是来自 Google Javascript 样式指南: http://google.github.io/styleguide/javascriptguide.xml?showone=Comments#Comments

    第二个是基于 JSDoc 从 JavaDoc 派生的事实,这与您的第二个示例类似。有关 JavaDoc 示例,请参见以下链接: http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#styleguide

    我会推荐使用缩进方法 - 我认为它是可读性和没有非常短的行之间的一个很好的交叉。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-27
      • 1970-01-01
      • 1970-01-01
      • 2015-08-12
      • 2011-06-22
      • 1970-01-01
      相关资源
      最近更新 更多