首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

require-jsdoc

JSDoc 是一个 JavaScript API 文档生成器。它在代码中使用特殊格式的注释来自动生成 API 文档。例如,这是一个 JSDoc 注释对于函数的外观:

/**
 * Adds two numbers together.
 * @param {int} num1 The first number.
 * @param {int} num2 The second number.
 * @returns {int} The sum of the two numbers.
 */
function sum(num1, num2) {
    return num1 + num2;
}

一些风格的指南要求所有函数都使用 JSDoc 注释来解释函数行为。

规则细节

此规则需要指定节点的 JSDoc 注释。支持的节点:

  • "FunctionDeclaration"
  • "ClassDeclaration"
  • "MethodDefinition"
  • "ArrowFunctionExpression"
  • "FunctionExpression"

选项

该规则具有单个对象选项:

  • "require" 需要对于特殊指定的代码JSDoc的解释默认的选项设置:{ "require-jsdoc": ["error", { "require": { "FunctionDeclaration": true, "MethodDefinition": false, "ClassDeclaration": false, "ArrowFunctionExpression": false, "FunctionExpression": false } }] }requireExamples 不正确的代码与此规则的 { "require": { "FunctionDeclaration": true, "MethodDefinition": true, "ClassDeclaration": true, "ArrowFunctionExpression": true, "FunctionExpression": true } } option:/*eslint "require-jsdoc": ["error", { "require": { "FunctionDeclaration": true, "MethodDefinition": true, "ClassDeclaration": true, "ArrowFunctionExpression": true, "FunctionExpression": true } }]*/ function foo() { return 10; } var foo = () => { return 10; }; class Foo { bar() { return 10; } } var foo = function() { return 10; }; var foo = { bar: function() { return 10; }, baz() { return 10; } };这个规则的正确代码的示例{ "require": { "FunctionDeclaration": true, "MethodDefinition": true, "ClassDeclaration": true, "ArrowFunctionExpression": true, "FunctionExpression": true } } option:/*eslint "require-jsdoc": ["error", { "require": { "FunctionDeclaration": true, "MethodDefinition": true, "ClassDeclaration": true, "ArrowFunctionExpression": true, "FunctionExpression": true } }]*/ /** * It returns 10 */ function foo() { return 10; } /** * It returns test + 10 * @params {int} test - some number * @returns {int} sum of test and 10 */ var foo = (test) => { return test + 10; } /** * It returns 10 */ var foo = () => { return 10; } /** * It returns 10 */ var foo = function() { return 10; } var array = [1,2,3]; array.filter(function(item) { return item > 2; }); /** * A class that can return the number 10 */ class Foo { /** * It returns 10 */ bar() { return 10; } } /** * It returns 10 */ var foo = function() { return 10; }; var foo = { /** * It returns 10 */ bar: function() { return 10; }, /** * It returns 10 */ baz() { return 10; } }; setTimeout(() => {}, 10); // 因为它是一个匿名箭头 functionWhen 不使用它如果你不需要为你的函数使用 JSDoc,那么你可以关闭这个规则。相关规则 {},10); //因为它是一个匿名箭头 functionWhen 不使用它如果你不需要为你的函数使用 JSDoc,那么你可以关闭这个规则。相关规则
  • valid-jsdoc

版本

该规则在 ESLint 1.4.0中引入。

资源

扫码关注腾讯云开发者

领取腾讯云代金券